-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdb.py
More file actions
28 lines (22 loc) · 659 Bytes
/
Copy pathdb.py
File metadata and controls
28 lines (22 loc) · 659 Bytes
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
import shelve
import os
def open_db(name):
db = None
try:
filename = '{}.db'.format(name)
folder = 'db'
if not os.path.isdir(folder):
if os.path.exists(folder):
print ('File "{}" already exists as a file'.format(folder))
return None
os.mkdir(folder)
path = os.path.join(folder, filename)
print ('Opening DB "{}"'.format(path))
db = shelve.open(path, writeback=True)
except:
import traceback
traceback.print_exc()
print ('ERROR Cannot open database "{}"'.format(path))
db = None
pass
return db