1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | ''' |
---|
4 | Created on Jan 25, 2011 |
---|
5 | |
---|
6 | @author: Pete |
---|
7 | ########### SVN repository information ################### |
---|
8 | # $Date: 2011-01-27 00:45:24 +0000 (Thu, 27 Jan 2011) $ |
---|
9 | # $Author: jemian $ |
---|
10 | # $Revision: 251 $ |
---|
11 | # $URL: topdoc/src/Utils/TokenExaminer.py $ |
---|
12 | # $Id: TokenExaminer.py 251 2011-01-27 00:45:24Z jemian $ |
---|
13 | ########### SVN repository information ################### |
---|
14 | ''' |
---|
15 | |
---|
16 | import FileTree |
---|
17 | import os |
---|
18 | from FileTokens import TokenLog |
---|
19 | import sys |
---|
20 | from Utils.Validation import isEpicsTopLevelDir |
---|
21 | |
---|
22 | |
---|
23 | def makeTokens(d): |
---|
24 | keys = d.keys() |
---|
25 | keys.sort() |
---|
26 | results = {} |
---|
27 | tokNames = [] |
---|
28 | well_known_binary_exts = ('.gif', '.png', '.jpg', '.pdf', '.ps') |
---|
29 | for k in keys: |
---|
30 | for name in d[k]['files']: # loop over just the files |
---|
31 | for ext in well_known_binary_exts: |
---|
32 | # skip well-known binary files |
---|
33 | if name.lower().endswith(ext): |
---|
34 | name = None |
---|
35 | break |
---|
36 | if name == None: continue |
---|
37 | full = os.path.join(k, name) |
---|
38 | try: |
---|
39 | obj = TokenLog.TokenLog() |
---|
40 | obj.processFile(full) |
---|
41 | except: |
---|
42 | print "\n error while parsing " + full, sys.exc_info()[:2] |
---|
43 | continue |
---|
44 | #print "\n" + full |
---|
45 | print full |
---|
46 | s = obj.summary() |
---|
47 | results[full] = s |
---|
48 | for ky in s.keys(): |
---|
49 | if not ky in tokNames: |
---|
50 | tokNames.append( ky ) |
---|
51 | return results, tokNames |
---|
52 | |
---|
53 | |
---|
54 | def report(results, tokNames): |
---|
55 | ''' |
---|
56 | Print a table suitable for input into Excel |
---|
57 | ''' |
---|
58 | keys = results.keys() |
---|
59 | keys.sort() |
---|
60 | tokNames.sort() |
---|
61 | print "filename\t" + "\t".join( tokNames ) |
---|
62 | for k in keys: |
---|
63 | line = [k] |
---|
64 | for c in tokNames: |
---|
65 | if c in results[k]: |
---|
66 | line.append( "%d" % results[k][c] ) |
---|
67 | else: |
---|
68 | line.append( "0" ) |
---|
69 | print "\t".join(line) |
---|
70 | |
---|
71 | |
---|
72 | if __name__ == '__main__': |
---|
73 | working_dir = 'C:\\Users\\Pete\\Documents\\projects\\bcdaioc\\12id' |
---|
74 | print "\n".join(os.environ['PYTHONPATH'].split(";")) |
---|
75 | if isEpicsTopLevelDir(working_dir): |
---|
76 | os.chdir(working_dir) |
---|
77 | d = FileTree.FileTree().discover(".") |
---|
78 | results, tokNames = makeTokens(d) |
---|
79 | print len(results) |
---|
80 | report(results, tokNames) |
---|
81 | |
---|