Move definitions of generate_ignores() higher in the file.
[cvs2svn.git] / cvs2svn_rcsparse / parse_rcs_file.py
blob05ff5b07b5efa2b076cbc35dbfd069f6eb46ac18
1 #! /usr/bin/python
3 # (Be in -*- python -*- mode.)
5 # ====================================================================
6 # Copyright (c) 2006-2007 CollabNet. All rights reserved.
8 # This software is licensed as described in the file COPYING, which
9 # you should have received as part of this distribution. The terms
10 # are also available at http://subversion.tigris.org/license-1.html.
11 # If newer versions of this license are posted there, you may use a
12 # newer version instead, at your option.
14 # This software consists of voluntary contributions made by many
15 # individuals. For exact contribution history, see the revision
16 # history and logs, available at http://cvs2svn.tigris.org/.
17 # ====================================================================
19 """Parse an RCS file, showing the rcsparse callbacks that are called.
21 This program is useful to see whether an RCS file has a problem (in
22 the sense of not being parseable by rcsparse) and also to illuminate
23 the correspondence between RCS file contents and rcsparse callbacks.
25 The output of this program can also be considered to be a kind of
26 'canonical' format for RCS files, at least in so far as rcsparse
27 returns all relevant information in the file and provided that the
28 order of callbacks is always the same."""
31 import sys
32 import os
35 class Logger:
36 def __init__(self, f, name):
37 self.f = f
38 self.name = name
40 def __call__(self, *args):
41 self.f.write(
42 '%s(%s)\n' % (self.name, ', '.join(['%r' % arg for arg in args]),)
46 class LoggingSink:
47 def __init__(self, f):
48 self.f = f
50 def __getattr__(self, name):
51 return Logger(self.f, name)
54 if __name__ == '__main__':
55 # Since there is nontrivial logic in __init__.py, we have to import
56 # parse() via that file. First make sure that the directory
57 # containing this script is in the path:
58 sys.path.insert(0, os.path.dirname(sys.argv[0]))
60 from __init__ import parse
62 if sys.argv[1:]:
63 for path in sys.argv[1:]:
64 if os.path.isfile(path) and path.endswith(',v'):
65 parse(
66 open(path, 'rb'), LoggingSink(sys.stdout)
68 else:
69 sys.stderr.write('%r is being ignored.\n' % path)
70 else:
71 parse(sys.stdin, LoggingSink(sys.stdout))