forked from manishmohanlal/Fuse---KVFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbsddb_wrapper.py
52 lines (40 loc) · 956 Bytes
/
bsddb_wrapper.py
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
49
50
51
52
import bsddb3
import logging
LOG_FILENAME = 'log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
class bsddbWrapper:
def __init__(self, loc):
self.db = bsddb3.db.DB()
self.db.open(loc,flags=bsddb3.db.DB_CREATE,dbtype=bsddb3.db.DB_HASH)
def addFile(self,key,value):
if self.db.has_key(key):
return -1
else:
self.db[key]=value
return key
def updateFile(self,key,value):
logging.info("update")
self.db[key]=value
return key
def deleteFile(self,key):
if self.db.has_key(key):
del self.db[key]
return key
else:
return -1
def hasKey(self,key):
if self.db.has_key(key):
return True
else:
return False
def get(self,key, **kwargs):
if 'dlen' in kwargs and 'doff' in kwargs:
dlen = kwargs['dlen']
doff = kwargs['doff']
return self.db.get(key,dlen=dlen,doff=doff)
else:
return self.db.get(key)
def commit(self):
self.db.sync()
def close(self):
self.db.close()