-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
48 lines (43 loc) · 1.1 KB
/
db.py
File metadata and controls
48 lines (43 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from ZEO.ClientStorage import ClientStorage
from ZODB.FileStorage import FileStorage
from ZODB import DB
from persistent.mapping import PersistentMapping
from persistent.list import PersistentList
import transaction
import socket
import os
import cluster
conn = None
def connect(server=None, zodb=None):
global conn
close() # close any existing connection
if zodb:
conn = DB(FileStorage(os.path.expanduser(zodb))).open()
else:
if not server:
server = cluster.ZEOSERVER
s = server
p = 12345
if ':' in server:
s, p = server.split(':')
p = int(p)
MB = 1024**2
storage = ClientStorage((s,p), cache_size=16*MB)
db = DB(storage)
conn = db.open()
root = conn.root()
return root
def reconnect():
# I dont think this actually works... errors about re-using a connection
transaction.abort()
conn.close()
connect()
def sync():
conn.sync()
def close():
global conn
if conn:
transaction.abort()
conn.close()
conn.db().close()
conn = None