Reorganize the output to "svnserve --help".
[svn.git] / tools / bdb / svnfs.py
blobb3be4434824ce9a35ccbc3ff03456d92b36f2257
1 # A handle object for convenience in opening a svn repository
3 import sys
5 # We need a bsddb linked to the same version of Berkeley DB as Subversion is
6 try:
7 import bsddb3 as bsddb
8 except ImportError:
9 import bsddb
11 # Publish the result
12 sys.modules['svnfs_bsddb'] = bsddb
14 from svnfs_bsddb.db import *
16 class Ctx:
17 def __init__(self, dbhome, readonly=None):
18 self.env = self.uuids_db = self.revs_db = self.txns_db = self.changes_db \
19 = self.copies_db = self.nodes_db = self.reps_db = self.strings_db = \
20 None
21 try:
22 self.env = DBEnv()
23 self.env.set_lk_detect(DB_LOCK_RANDOM)
24 self.env.set_get_returns_none(1)
25 self.env.open(dbhome, DB_CREATE | DB_INIT_MPOOL | DB_INIT_TXN \
26 | DB_INIT_LOCK | DB_INIT_LOG)
27 def open_db(dbname):
28 db = DB(self.env)
29 dbflags = 0
30 if readonly:
31 dbflags = DB_RDONLY
32 db.open(dbname, flags=dbflags)
33 return db
34 self.uuids_db = open_db('uuids')
35 self.revs_db = open_db('revisions')
36 self.txns_db = open_db('transactions')
37 self.changes_db = open_db('changes')
38 self.copies_db = open_db('copies')
39 self.nodes_db = open_db('nodes')
40 self.reps_db = open_db('representations')
41 self.strings_db = open_db('strings')
42 except:
43 self.close()
44 raise
46 def close(self):
47 def close_if_not_None(i):
48 if i is not None:
49 i.close()
50 close_if_not_None(self.uuids_db )
51 close_if_not_None(self.revs_db )
52 close_if_not_None(self.txns_db )
53 close_if_not_None(self.changes_db )
54 close_if_not_None(self.copies_db )
55 close_if_not_None(self.nodes_db )
56 close_if_not_None(self.reps_db )
57 close_if_not_None(self.strings_db )
58 close_if_not_None(self.env )
59 self.env = self.uuids_db = self.revs_db = self.txns_db = self.changes_db \
60 = self.copies_db = self.nodes_db = self.reps_db = self.strings_db = \
61 None
63 # And now, some utility functions
64 def get_whole_string(self, key):
65 cur = self.strings_db.cursor()
66 try:
67 rec = cur.set(key)
68 if rec is None:
69 raise DBNotFoundError
70 str = ""
71 while rec:
72 str = str + (rec[1] or "")
73 rec = cur.next_dup()
74 finally:
75 cur.close()
76 return str