Update to rcsparse r2495.
[cvs2svn.git] / cvs2svn_rcsparse / debug.py
blobcfeaf2b6330bc5596f21c0167e4e1bd68144c9d3
1 # -*-python-*-
3 # Copyright (C) 1999-2006 The ViewCVS Group. All Rights Reserved.
5 # By using this file, you agree to the terms and conditions set forth in
6 # the LICENSE.html file which can be found at the top level of the ViewVC
7 # distribution or at http://viewvc.org/license-1.html.
9 # For more information, visit http://viewvc.org/
11 # -----------------------------------------------------------------------
13 """debug.py: various debugging tools for the rcsparse package."""
15 import time
17 from __init__ import parse
18 import common
21 class DebugSink(common.Sink):
22 def set_head_revision(self, revision):
23 print 'head:', revision
25 def set_principal_branch(self, branch_name):
26 print 'branch:', branch_name
28 def define_tag(self, name, revision):
29 print 'tag:', name, '=', revision
31 def set_comment(self, comment):
32 print 'comment:', comment
34 def set_description(self, description):
35 print 'description:', description
37 def define_revision(self, revision, timestamp, author, state,
38 branches, next):
39 print 'revision:', revision
40 print ' timestamp:', timestamp
41 print ' author:', author
42 print ' state:', state
43 print ' branches:', branches
44 print ' next:', next
46 def set_revision_info(self, revision, log, text):
47 print 'revision:', revision
48 print ' log:', log
49 print ' text:', text[:100], '...'
52 class DumpSink(common.Sink):
53 """Dump all the parse information directly to stdout.
55 The output is relatively unformatted and untagged. It is intended as a
56 raw dump of the data in the RCS file. A copy can be saved, then changes
57 made to the parsing engine, then a comparison of the new output against
58 the old output.
59 """
60 def __init__(self):
61 global sha
62 import sha
64 def set_head_revision(self, revision):
65 print revision
67 def set_principal_branch(self, branch_name):
68 print branch_name
70 def define_tag(self, name, revision):
71 print name, revision
73 def set_comment(self, comment):
74 print comment
76 def set_description(self, description):
77 print description
79 def define_revision(self, revision, timestamp, author, state,
80 branches, next):
81 print revision, timestamp, author, state, branches, next
83 def set_revision_info(self, revision, log, text):
84 print revision, sha.new(log).hexdigest(), sha.new(text).hexdigest()
86 def tree_completed(self):
87 print 'tree_completed'
89 def parse_completed(self):
90 print 'parse_completed'
93 def dump_file(fname):
94 parse(open(fname, 'rb'), DumpSink())
96 def time_file(fname):
97 f = open(fname, 'rb')
98 s = common.Sink()
99 t = time.time()
100 parse(f, s)
101 t = time.time() - t
102 print t
104 def _usage():
105 print 'This is normally a module for importing, but it has a couple'
106 print 'features for testing as an executable script.'
107 print 'USAGE: %s COMMAND filename,v' % sys.argv[0]
108 print ' where COMMAND is one of:'
109 print ' dump: filename is "dumped" to stdout'
110 print ' time: filename is parsed with the time written to stdout'
111 sys.exit(1)
113 if __name__ == '__main__':
114 import sys
115 if len(sys.argv) != 3:
116 _usage()
117 if sys.argv[1] == 'dump':
118 dump_file(sys.argv[2])
119 elif sys.argv[1] == 'time':
120 time_file(sys.argv[2])
121 else:
122 _usage()