diff options
-rw-r--r-- | NEWS | 3 | ||||
-rwxr-xr-x | deheader | 34 | ||||
-rw-r--r-- | deheader.xml | 2 | ||||
-rw-r--r-- | test/regress.chk | 1 |
4 files changed, 37 insertions, 3 deletions
@@ -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. @@ -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 |