/
debug_dboperations.py
executable file
·87 lines (69 loc) · 1.82 KB
/
debug_dboperations.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python
import boto.dynamodb2
from boto.dynamodb2.table import Table
from boto.dynamodb2.fields import HashKey
from dboperations import create, retrieve_id, retrieve_name, add, delete_id, delete_name
# Test driver for dboperations.py
# [DEBUG] Create Table
def debug_create_table():
users = Table.create('users',
schema=[
HashKey('id'),
],
throughput={
'read': 5,
'write': 15,
},
connection=boto.dynamodb2.connect_to_region('us-west-2')
)
print "Table created!"
return
# [DEBUG] Populate Table
def debug_populate_table():
create("12", "John", "swimming,sleeping")
create("13", "SolidSnake", "espionage,cqc")
create("14", "RevolverOcelot", "six,bullets,more,than,enough")
create("15", "SniperWolf", "sniping,dying,hankerchieves")
create("16", "Otacon", "anime")
create("17", "GrayFox", "pain,snake,anime")
return
def debug_retrieve_users():
res = retrieve_id("12")
print res
res = retrieve_name("SolidSnake")
print res
return
def debug_add_activities():
res = add("16", "hacking,hiding")
print res
res = add("15", "waiting")
print res
def debug_delete_users():
res = delete_id("12")
print res
res = delete_name("RevolverOcelot")
print res
# [DEBUG] Delete Table
def debug_delete_table():
try:
users = Table('users', connection=boto.dynamodb2.connect_to_region('us-west-2'))
Table.delete(users)
print "Deleting users!"
except Exception, c:
print c
return
# [DEBUG] Test driver to connect and populate the database
# Comment and uncomment sections as necessary
def debug_test():
# debug_create_table()
try:
users = Table('users', connection=boto.dynamodb2.connect_to_region('us-west-2'))
except Exception, e:
print e
# debug_populate_table()
# debug_retrieve_users()
# debug_add_activities()
# debug_delete_users()
# debug_delete_table()
return
debug_test()