Fix compiler warning due to missing function prototype.
[svn.git] / tools / bdb / erase-all-text-data.py
blobfb08ddc7e879d9ffcab03ef832d23bd3a2787588
1 #!/usr/bin/env python
3 # Erases the text of every file in a BDB repository
6 import sys, os
7 import skel, svnfs
9 def main():
10 if len(sys.argv) == 2:
11 dbhome = os.path.join(sys.argv[1], 'db')
12 for i in ('', 'uuids', 'revisions', 'transactions', 'representations',
13 'strings', 'changes', 'copies', 'nodes'):
14 if not os.path.exists(os.path.join(dbhome, i)):
15 sys.stderr.write("%s: '%s' is not a valid bdb svn repository\n" %
16 (sys.argv[0], sys.argv[1]))
17 sys.exit(1)
18 else:
19 sys.stderr.write("Usage: %s <bdb-svn-repository>\n" % sys.argv[0])
20 sys.exit(1)
22 print "WARNING!: This program will destroy all text data in the subversion"
23 print "repository '%s'" % sys.argv[1]
24 print "Do not proceed unless this is a *COPY* of your real repository"
25 print "If this is really what you want to do, " \
26 "type 'YESERASE' and press Return"
27 confirmation = raw_input("Confirmation string> ")
28 if confirmation != "YESERASE":
29 print "Cancelled - confirmation string not matched"
30 sys.exit(0)
31 print "Opening database environment..."
32 cur = None
33 ctx = svnfs.Ctx(dbhome)
34 try:
35 cur = ctx.nodes_db.cursor()
36 nodecount = 0
37 newrep = skel.Rep()
38 newrep.str = "empty"
39 empty_fulltext_rep_skel = newrep.unparse()
40 del newrep
41 ctx.strings_db['empty'] = ""
42 rec = cur.first()
43 while rec:
44 if rec[0] != "next-key":
45 if (nodecount % 10000 == 0) and nodecount != 0:
46 print "Processed %d nodes..." % nodecount
47 nodecount += 1
48 node = skel.Node(rec[1])
49 if node.kind == "file":
50 rep = skel.Rep(ctx.reps_db[node.datarep])
51 if rep.kind == "fulltext":
52 if ctx.strings_db.has_key(rep.str):
53 del ctx.strings_db[rep.str]
54 ctx.reps_db[node.datarep] = empty_fulltext_rep_skel
55 else:
56 for w in rep.windows:
57 if ctx.strings_db.has_key(w.str):
58 del ctx.strings_db[w.str]
59 ctx.reps_db[node.datarep] = empty_fulltext_rep_skel
60 rec = cur.next()
61 print "Processed %d nodes" % nodecount
62 finally:
63 if cur:
64 cur.close()
65 ctx.close()
66 print "Done"
68 if __name__ == '__main__':
69 main()