forked from C291F14/C291A2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.py~
69 lines (56 loc) · 1.69 KB
/
menu.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Berkeley DB
# Cody Ingram
import bsddb3 as db3
import sys
import random
import time
import subprocess
import btreeCreatePopDB
DA_FILE = "/tmp/my_db/291_db.db"
def main():
arg = sys.argv[0].lower()
inpList = ['btree', 'hash', 'indexfile']
# check valid program argument
if arg not in inpList:
print("Invalid Program Argument")
sys.exit()
# menu start
while True:
opt = input("Please Select An Option\n 1 - Create and populate a database\n 2 - Retrieve records with a given key\n \
3 - Retrieve records with given data\n 4 - Retrieve records with a range of key values\n 5 - Destroy Database\n 6 - Quit\n")
if opt == '1':
if arg == 'btree':
#btree
subprocess.call(['rm', '-r', '-f', DA_FILE, '/tmp/my_db'])
subprocess.call(['mkdir', '/tmp/my_db'])
try:
db = bsddb.btopen(DA_FILE, "w")
except:
print("DB doesn't exist, creating a new one.")
db = bsddb.btopen(DA_FILE, "c")
btreeCreatePopDB.btreeCreatePop(db, DA_FILE)
elif arg == 'hash':
#hash
subprocess.call(['rm', '-r', '-f', DA_FILE, '/tmp/my_db'])
subprocess.call(['mkdir', '/tmp/my_db'])
try:
db = bsddb.hashopen(DA_FILE, "w")
except:
print("DB doesn't exist, creating a new one.")
db = bsddb.hashopen(DA_FILE, "c")
btreeCreatePopDB.btreeCreatePop(db, DA_FILE)
elif arg == 'indexfile':
#indexfile
elif opt == '2':
print("call something")
elif opt == '3':
print("call something")
elif opt == '4':
print("call something")
elif opt == '5':
print("call something")
elif opt == '6':
print("call something")
else:
print("Invalid Input")
continue