3 # Copyright (C) 1999-2014 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."""
17 from __init__
import parse
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
,
39 print 'revision:', revision
40 print ' timestamp:', timestamp
41 print ' author:', author
42 print ' state:', state
43 print ' branches:', branches
46 def set_revision_info(self
, revision
, log
, text
):
47 print 'revision:', revision
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
64 def set_head_revision(self
, revision
):
67 def set_principal_branch(self
, branch_name
):
70 def define_tag(self
, name
, revision
):
73 def set_comment(self
, comment
):
76 def set_description(self
, description
):
79 def define_revision(self
, revision
, timestamp
, author
, state
,
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'
94 parse(open(fname
, 'rb'), DumpSink())
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'
113 if __name__
== '__main__':
115 if len(sys
.argv
) != 3:
117 if sys
.argv
[1] == 'dump':
118 dump_file(sys
.argv
[2])
119 elif sys
.argv
[1] == 'time':
120 time_file(sys
.argv
[2])