* test-data/main-cvsrepos/single-files/twoquick,v: Lock (in the CVS sense)
[cvs2svn.git] / show-db.py
blobf29b8154aa49d2a2ef240f6f6aac67939cbf87a3
1 #!/usr/bin/env python
3 import anydbm
4 import marshal
5 import sys
6 import os
7 import getopt
10 def usage():
11 cmd = sys.argv[0]
12 sys.stderr.write('Usage: %s OPTION [DIRECTORY]\n\n' % os.path.basename(cmd))
13 sys.stderr.write(
14 'Show the contents of the temporary database files created by cvs2svn\n'
15 'in a structured human-readable way.\n'
16 '\n'
17 'OPTION is one of:\n'
18 ' -s SymbolicNameTracker state database\n'
19 ' -R RepositoryMirror revisions table\n'
20 ' -N RepositoryMirror nodes table\n'
21 ' -y RepositoryMirror symroots table\n'
22 ' -r rev RepositoryMirror node tree for specific revision\n'
23 '\n'
24 'DIRECTORY is the directory containing the temporary database files.\n'
25 'If omitted, the current directory is assumed.\n')
26 sys.exit(1)
29 def print_node_tree(db, key="0", name="<rootnode>", prefix=""):
30 print "%s%s (%s)" % (prefix, name, key)
31 if name[:1] != "/":
32 dict = marshal.loads(db[key])
33 items = dict.items()
34 items.sort()
35 for entry in items:
36 print_node_tree(db, entry[1], entry[0], prefix + " ")
39 def main():
40 try:
41 opts, args = getopt.getopt(sys.argv[1:], "sRNyr:")
42 except getopt.GetoptError:
43 usage()
45 if len(args) > 1 or len(opts) != 1:
46 usage()
48 if len(args) == 1:
49 os.chdir(args[0])
51 db = None
53 for o, a in opts:
54 if o == "-s":
55 db = anydbm.open("cvs2svn-sym-names.db", 'r')
56 print "SymbolicNameTracker state database"
57 print_node_tree(db)
58 elif o == "-R":
59 db = anydbm.open("cvs2svn-revisions.db", 'r')
60 print "RepositoryMirror revisions table"
61 k = map(lambda x: int(x), db.keys())
62 k.sort()
63 for i in k:
64 print "%6d: %s" % (i, db[str(i)])
65 elif o == "-N":
66 db = anydbm.open("cvs2svn-nodes.db", 'r')
67 print "RepositoryMirror nodes table"
68 k = db.keys()
69 k.sort()
70 for i in k:
71 print "%6s: %s" % (i, marshal.loads(db[i]))
72 elif o == "-y":
73 db = anydbm.open("cvs2svn-symroots.db", 'r')
74 print "RepositoryMirror symroots table"
75 k = db.keys()
76 k.sort()
77 for i in k:
78 print "%s: %s" % (i, marshal.loads(db[i]))
79 elif o == "-r":
80 try:
81 revnum = int(a)
82 except ValueError:
83 sys.stderr.write('Option -r requires a valid revision number\n')
84 sys.exit(1)
85 db = anydbm.open("cvs2svn-revisions.db", 'r')
86 key = marshal.loads(db[str(revnum)])
87 db.close()
88 db = anydbm.open("cvs2svn-nodes.db", 'r')
89 print_node_tree(db, key, "Revision %d" % revnum)
90 else:
91 usage()
92 sys.exit(2)
94 db.close()
97 if __name__ == '__main__':
98 main()