From 41c41d2d3f20b41ec8ce0882e0e8eec0d7e295d9 Mon Sep 17 00:00:00 2001 From: Marc Jones Date: Wed, 5 Feb 2014 12:53:21 -0500 Subject: removed summary.py after folding in to main.py --- main.py | 18 ++++++++++++------ main.py~ | 17 ++++++++++++----- summary.py | 32 -------------------------------- summary.py~ | 32 -------------------------------- 4 files changed, 24 insertions(+), 75 deletions(-) delete mode 100755 summary.py delete mode 100755 summary.py~ diff --git a/main.py b/main.py index b157ab5..6211dcb 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,4 @@ #!/usr/bin/python -#example command from optparse import OptionParser import os @@ -121,6 +120,7 @@ parser.add_option("-p", "--display_progress", dest="display_progress", default=F parser.add_option("-l", "--max-wholeword-length", dest="maxwholewordlength", type="int", default=-1, help="maximun length of a word allowed to only find matches on whole word") parser.add_option("-o", "--summary-file", dest="summaryfile", help="name of the file to store the summary in") parser.add_option("-x", "--display-summary", dest="displaysummary", default=False, help="Display a summary from the summary file", action="store_true") +parser.add_option("-X", "--dont-display-summary", dest="dontdisplaysummary", default=False, help="Dont Display a summary after running a scan", action="store_true") (options, args) = parser.parse_args() @@ -213,7 +213,7 @@ for file in filelist: if options.display_progress: print '\r' + " " * len(progresstext) + '\r', -if options.printreport: +if options.printreport and not options.dontdisplaysummary: if options.printreport == "f": printscore(sortscore(scorefile(report))) elif options.printreport == "wf" or options.printreport == "fw": @@ -230,13 +230,19 @@ if options.display_counts: if options.summaryfile and len(filelist) > 0 and not options.displaysummary: summaryfilename = options.summaryfile - counter = None + counter = 0 while os.path.isfile(summaryfilename): counter +=1 summaryfilename = options.summaryfile + '.' + str(counter) - summaryfile = open(summaryfilename, 'w+') - summaryfile.write(summary(report)) - summaryfile.close() + try: + if counter > 1: print "saving as " + summaryfilename + "...." + summaryfile = open(summaryfilename, 'w+') + summaryfile.write(summary(report)) + summaryfile.close() + except: + print report + print "error saving summary as " + summaryfilename + def test(): print wholeword("22", "port22") diff --git a/main.py~ b/main.py~ index 2f9fdf3..9dc8af5 100755 --- a/main.py~ +++ b/main.py~ @@ -121,6 +121,7 @@ parser.add_option("-p", "--display_progress", dest="display_progress", default=F parser.add_option("-l", "--max-wholeword-length", dest="maxwholewordlength", type="int", default=-1, help="maximun length of a word allowed to only find matches on whole word") parser.add_option("-o", "--summary-file", dest="summaryfile", help="name of the file to store the summary in") parser.add_option("-x", "--display-summary", dest="displaysummary", default=False, help="Display a summary from the summary file", action="store_true") +parser.add_option("-X", "--dont-display-summary", dest="dontdisplaysummary", default=False, help="Dont Display a summary after running a scan", action="store_true") (options, args) = parser.parse_args() @@ -213,7 +214,7 @@ for file in filelist: if options.display_progress: print '\r' + " " * len(progresstext) + '\r', -if options.printreport: +if options.printreport and not options.dontdisplaysummary: if options.printreport == "f": printscore(sortscore(scorefile(report))) elif options.printreport == "wf" or options.printreport == "fw": @@ -230,13 +231,19 @@ if options.display_counts: if options.summaryfile and len(filelist) > 0 and not options.displaysummary: summaryfilename = options.summaryfile - counter = None + counter = 0 while os.path.isfile(summaryfilename): counter +=1 summaryfilename = options.summaryfile + '.' + str(counter) - summaryfile = open(summaryfile, 'w+') - summaryfile.write(summary(report)) - summaryfile.close() + try: + if counter > 1: print "saving as " + summaryfilename + "...." + summaryfile = open(summaryfilename, 'w+') + summaryfile.write(summary(report)) + summaryfile.close() + except: + print report + print "error saving summary as " + summaryfilename + def test(): print wholeword("22", "port22") diff --git a/summary.py b/summary.py deleted file mode 100755 index 098af74..0000000 --- a/summary.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/python -i -from optparse import OptionParser -import os -import re -import sys -import datetime - -parser = OptionParser() - -(options, args) = parser.parse_args() - -report = dict() -file -for a in args: - summaryfile = open(a) - - #sample input - #../bzr.lf/lsb/devel/build_env/headers/x86-64/4.1/glib-2.0/gio/gmenuexporter.h.defs(1): export(1); - for line in summaryfile: - #find the file name which is before the matching parathsis before the last colon on the line - filename = line[:line[:line.rfind(':')].rfind('(')] - #find the total number of words found by locating the end of the filename and taking the number in parathesis right before the : - totalfilecount = line[line[:line.rfind(':')].rfind('(')+1:line[:line.rfind(':')].rfind(')')] - #find the list of words following the :, and split them by the ;, and then drop the last item on the list which is always a \n - foundwords = line[line.rfind(':')+1:].split(';')[:-1] - report[filename] = dict() - for w in foundwords: - w = w.strip() - word = w[:w.find('(')] - wcount = w[w.find('(')+1:w.find(')')] - report[filename][word] = wcount - diff --git a/summary.py~ b/summary.py~ deleted file mode 100755 index 4298109..0000000 --- a/summary.py~ +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/python -i -from optparse import OptionParser -import os -import re -import sys -import datetime - -parser = OptionParser() - -(options, args) = parser.parse_args() - -report = dict() -file -for a in args: - summaryfile = open(a) - - #sample input - #../bzr.lf/lsb/devel/build_env/headers/x86-64/4.1/glib-2.0/gio/gmenuexporter.h.defs(1): export(1); - for line in summaryfile: - #find the file name which is before the matching parathsis before the last colon on the line - filename = line[:line[:line.rfind(':')].rfind('(')] - #find the total number of words found by locating the end of the filename and taking the number in parathesis right before the : - totalfilecount = line[line[:line.rfind(':')].rfind('(')+1:line[:line.rfind(':')].rfind(')')] - #find the list of words following the :, and split them by the ;, and then drop the last item on the list which is always a \n - foundwords = line[line.rfind(':')+1:].split(';')[:-1] - report[filename] = dict() - for w in foundwords: - w = w.trim() - word = w[:w.find('(')] - wcount = w[w.find('(')+1:w.find(')')] - report[filename][word] = wcount - -- cgit v1.2.1