summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2010-12-02 04:29:41 -0500
committerEric S. Raymond <esr@thyrsus.com>2010-12-02 04:29:41 -0500
commit914cb86f8b67b8d5a9703faf6f9eb9c2ce42a095 (patch)
treec8cdb8264a13a0a70b4486a8ac1b6906b893771d
parent94952f4135c837fb80ab8fcac89cd9ddb21be326 (diff)
downloaddeheader-914cb86f8b67b8d5a9703faf6f9eb9c2ce42a095.tar.gz
deheader-914cb86f8b67b8d5a9703faf6f9eb9c2ce42a095.tar.bz2
deheader-914cb86f8b67b8d5a9703faf6f9eb9c2ce42a095.tar.xz
deheader-914cb86f8b67b8d5a9703faf6f9eb9c2ce42a095.zip
Add a statistical summary on the last line.
-rw-r--r--NEWS3
-rwxr-xr-xdeheader34
-rw-r--r--deheader.xml2
-rw-r--r--test/regress.chk1
4 files changed, 37 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 449fc5d..2c6aad3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,7 @@
deheader project news
+0.2 @ 2010-12-02
+ Make the last line of output a statistical summary.
+
0.1 @ 2010-12-01
Initial release.
diff --git a/deheader b/deheader
index 213818e..f3733eb 100755
--- a/deheader
+++ b/deheader
@@ -22,9 +22,11 @@ had been passed to it.
The original sourcefile is moved to a name with an .orig suffix and restored
on interrupt or after processing with its original timestamp, unless the
-r option was given and headers removed.
+
+The last line of the output is a statistical summary of operations.
"""
-import sys, os, getopt, time, re
+import sys, os, getopt, time, re, operator
BATON_DEBUG = 1
PROGRESS_DEBUG = 2
@@ -211,7 +213,7 @@ def deheader(sourcefile, maker, includes, remove, verbose):
if st == 0:
# Now do the analysis
if sourcefile.endswith(".c") or sourcefile.endswith(".cpp"):
- unneeded = c_analyze(sourcefile, maker, includes, verbose)
+ unneeded = c_analyze(sourcefile, maker, includes[:], verbose)
if unneeded:
for line in unneeded:
print "deheader: remove %s from %s" % (trim(line), sourcefile)
@@ -220,6 +222,27 @@ def deheader(sourcefile, maker, includes, remove, verbose):
remove_it.remove_headers(unneeded)
remove_it.forget()
del remove_it
+ return Summary([sourcefile], includes, unneeded)
+ else:
+ return Summary([sourcefile], includes, [])
+
+# After-action analysis starts here
+
+class Summary:
+ "Summarize results from a deheading."
+ def __init__(self, filenames=None, includes=None, unneeded=None):
+ self.filenames = filenames or []
+ self.includes = includes or []
+ self.unneeded = unneeded or []
+ def __add__(self, other):
+ result = Summary()
+ result.filenames = self.filenames + other.filenames
+ result.includes = self.includes + other.includes
+ result.unneeded = self.unneeded + other.unneeded
+ return result
+ def __repr__(self):
+ return "%d files, %d includes, %d removed" % \
+ (len(self.filenames), len(self.includes), len(self.unneeded))
if __name__ == "__main__":
(options, arguments) = getopt.getopt(sys.argv[1:], "hi:m:rvV",
@@ -252,8 +275,13 @@ if __name__ == "__main__":
arguments = ["."]
inclusion_map = InclusionMap(arguments, ignore, verbose)
+ summaries = []
for sourcefile in inclusion_map.c_to_h:
- deheader(sourcefile, maker, inclusion_map.c_to_h[sourcefile], remove, verbose)
+ summaries.append(deheader(sourcefile, maker, inclusion_map.c_to_h[sourcefile], remove, verbose))
+ stats = Summary()
+ for summary in summaries:
+ stats = stats + summary
+ print "deheader: saw", stats
raise SystemExit, 0
# End
diff --git a/deheader.xml b/deheader.xml
index 8487238..8db4ed0 100644
--- a/deheader.xml
+++ b/deheader.xml
@@ -78,6 +78,8 @@ indicated with a twirling-baton prompt. At verbosity level 2, you get
vebose progress messages on the analysis. At verbosity level 3, you
see the output from the make and compilation commands.</para>
+<para>The last line of the output will be a statistical summary.</para>
+
<para>Running deheader will leave a lot of binaries in your directory that
were compiled in ways possibly not invoked by your normal build process.
Running "make clean" afterwards is strongly recommended.</para>
diff --git a/test/regress.chk b/test/regress.chk
index ecff26c..4dae4d1 100644
--- a/test/regress.chk
+++ b/test/regress.chk
@@ -1 +1,2 @@
deheader: remove <string.h> from test/string.c
+deheader: saw 2 files, 1 includes, 1 removed