summaryrefslogtreecommitdiff
path: root/suspicious
diff options
context:
space:
mode:
authorDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2017-09-29 12:32:12 -0400
committerDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2017-09-29 12:32:12 -0400
commit7c83421ce723aa211168b6fb46d5f8ec7d187a88 (patch)
tree4436da5acc2bf46f6f83fe7bc62cc3ea23fb7efe /suspicious
parent2def3ad7e644e0367536d15fe70adbf85b212de0 (diff)
suspicious: use YAML for summary files
Diffstat (limited to 'suspicious')
-rwxr-xr-xsuspicious31
1 files changed, 12 insertions, 19 deletions
diff --git a/suspicious b/suspicious
index 2ab782b..8140254 100755
--- a/suspicious
+++ b/suspicious
@@ -17,9 +17,9 @@
# Authors: Marc Jones <mjones@softwarefreedom.org>,
# Daniel Gnoutcheff <gnoutchd@softwarefreedom.org>
-# Date: June 2016
-# Version 0.3.0
-# Added AVFS support
+# Date: October 2017
+# Version 0.4.0
+# Use YAML for summary files
##TODO
#need to verify that word score counts each instance, not just 0 or 1
@@ -35,6 +35,12 @@ import string
import subprocess
import chardet
+from yaml import load, dump
+try:
+ from yaml import CLoader as Loader, CDumper as Dumper
+except ImportError:
+ from yaml import Loader, Dumper
+
import avfs
report = {}
@@ -287,21 +293,7 @@ if options.displaysummary and options.summaryfile:
except:
print("no summary file: " + options.summaryfile)
exit()
- #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] = int(wcount)
+ report = load(summaryfile, Loader=Loader)
if options.commonwordfilename and not(options.dontweightreport):
report, weightedfiles = weightreport(report, commonwords)
@@ -379,7 +371,8 @@ if options.summaryfile and len(filelist) > 0 and not options.displaysummary:
try:
if counter > 1: print("saving as " + summaryfilename + "....")
summaryfile = open(summaryfilename, 'w+')
- summaryfile.write(summary(report))
+
+ summaryfile.write(dump(report, Dumper=Dumper))
summaryfile.close()
except:
print(report)