[Zope-CVS] CVS: Products/ZCTextIndex/tests - hs-tool.py:1.1.2.2
Jeremy Hylton
jeremy@zope.com
Mon, 13 May 2002 18:32:16 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv11165
Modified Files:
Tag: TextIndexDS9-branch
hs-tool.py
Log Message:
Add -A option to produce annotated dump of each file instead of normal
output.
=== Products/ZCTextIndex/tests/hs-tool.py 1.1.2.1 => 1.1.2.2 ===
print '%8d %8d' % info, basename(filename), line
+def annotate_results(results):
+ files = {}
+ for stats, place in results:
+ if not place:
+ continue
+ hits, time = stats
+ file, line, func = place
+ l = files.get(file)
+ if l is None:
+ l = files[file] = []
+ l.append((line, hits, time))
+ for k, v in files.items():
+ if os.path.exists(k):
+ v.sort()
+ annotate(k, v)
+
+def annotate(file, lines):
+ f = open(file)
+ i = 1
+ match = lines[0][0]
+ for line in f:
+ if match == i:
+ print "%5d %5d " % lines[0][1:], line,
+ del lines[0]
+ if lines:
+ match = lines[0][0]
+ else:
+ match = None
+ else:
+ print " " * 12, line,
+ i += 1
+
def get_cache_name(filename):
d, fn = os.path.split(filename)
cache_dir = os.path.join(d, '.hs-tool')
@@ -48,10 +80,7 @@
finally:
fp.close()
-def main():
- filename = 'profile.dat'
- if sys.argv[1:]:
- filename = sys.argv[1]
+def main(filename, annotate):
cache_dir, cache_file = get_cache_name(filename)
if ( os.path.isfile(cache_file)
@@ -68,8 +97,24 @@
results.sort()
cache_results(filename, results)
- print_results(results)
+ if annotate:
+ annotate_results(results)
+ else:
+ print_results(results)
if __name__ == "__main__":
- main()
+ import sys
+ import getopt
+
+ annotate_p = 0
+ opts, args = getopt.getopt(sys.argv[1:], 'A')
+ for o, v in opts:
+ if o == '-A':
+ annotate_p = 1
+ if args:
+ filename, = args
+ else:
+ filename = "profile.dat"
+
+ main(filename, annotate_p)