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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
from tojauth import TOJAuth
from asyncdb import AsyncDB
import mod
import com
import imc.async
from imc.proxy import Proxy
import config
class TestdataMg:
_accessid = 7
def __init__(self, mod_idendesc, get_link_fn):
TestdataMg.db = AsyncDB(config.CORE_DBNAME, config.CORE_DBUSER,
config.CORE_DBPASSWORD)
TestdataMg._idendesc = mod_idendesc
self.get_link = get_link_fn
Proxy.instance.register_call(
'core/testdata/', 'add_testdata', self.add_testdata)
Proxy.instance.register_call(
'core/testdata/', 'update_testdata', self.update_testdata)
Proxy.instance.register_call(
'core/testdata/', 'get_testdata', self.get_testdata)
Proxy.instance.register_call(
'core/testdata/', 'del_testdata', self.del_testdata)
def unload(self):
Proxy.instance.unregister_call(
'core/testdata/', 'add_testdata')
Proxy.instance.unregister_call(
'core/testdata/', 'update_testdata')
Proxy.instance.unregister_call(
'core/testdata/', 'get_testdata')
Proxy.instance.unregister_call(
'core/testdata/', 'del_testdata')
@imc.async.caller
def add_testdata(self, blobname, expire, proid, info):
if expire != None:
expire = com.isoptime(expire)
if expire == None:
return 'Eparameter'
if(
type(blobname) != str or
(proid != None and type(proid) != int) or
type(info) != str
):
return 'Eparameter'
testid = self._add_testdata(blobname, expire, proid, info)
return testid
@TOJAuth.check_access(_accessid, TOJAuth.ACCESS_EXECUTE)
def _add_testdata(self, blobname, expire, proid, info):
cur = self.db.cursor()
sqlstr = ('INSERT INTO "TESTDATA" ("blobname", "expire", "proid", '
'"info") VALUES (%s, %s, %s, %s) RETURNING "testid";')
sqlarr = (blobname, expire, proid, info)
cur.execute(sqlstr, sqlarr)
testid = None
for data in cur:
testid = data[0]
return testid
@imc.async.caller
def update_testdata(self, testid, blobname, expire, proid, info):
if expire != None:
expire = com.isoptime(expire)
if expire == None:
return 'Eparameter'
if(
type(testid) != int or
type(blobname) != str or
(proid != None and type(proid) != int) or
type(info) != str
):
return 'Eparameter'
if not self.does_testid_exist(testid):
return 'Etestid'
self._update_testdata(testid, blobname, expire, proid, info)
return 'Success'
@TOJAuth.check_access(_accessid, TOJAuth.ACCESS_EXECUTE)
def _update_testdata(self, testid, blobname, expire, proid, info):
cur = self.db.cursor()
sqlstr = ('UPDATE "TESTDATA" SET "blobname" = %s, "expire" = %s, '
'"proid" = %s, "info" = %s WHERE "testid" = %s;')
sqlarr = (blobname, expire, proid, info, testid)
cur.execute(sqlstr, sqlarr)
@imc.async.caller
def get_testdata(self, testid):
if(
type(testid) != int
):
return 'Eparameter'
testdata = self._get_testdata(self, testid)
if testdata == None:
return 'Etestid'
return testdata
@TOJAuth.check_access(_accessid, TOJAuth.ACCESS_EXECUTE)
def _get_testdata(self, testid):
cur = self.db.cursor()
sqlstr = ('SELECT "testid", "blobname", "expire", "proid", "info" '
'FROM "TESTDATA" WHERE "testid" = %s;')
sqlarr = (testid, )
cur.execute(sqlstr, sqlarr)
testdata = None
for data in cur:
testdata = {}
testdata['testid'] = data[0]
testdata['blobname'] = data[1]
testdata['expire'] = data[2]
testdata['proid'] = data[3]
testdata['info'] = data[4]
return testdata
@imc.async.caller
def del_testdata(self, testid):
if(
type(testid) != int
):
return 'Eparameter'
if not self.does_testid_exist(testid):
return 'Etestid'
self._del_testdata(testid)
return 'Success'
@TOJAuth.check_access(_accessid, TOJAuth.ACCESS_EXECUTE)
def _del_testdata(self, testid):
cur = self.db.cursor()
sqlstr = ('DELETE FROM "TESTDATA" WHERE "testid" = %s;')
sqlarr = (testid, )
cur.execute(sqlstr, sqlarr)
@imc.async.caller
def list_testdata(self, proid = None):
if(
(proid != None and type(proid) != int)
):
return 'Eparameter'
testdata_list = self._list_testdata(self, proid)
return testdata_list
@TOJAuth.check_access(_accessid, TOJAuth.ACCESS_EXECUTE)
def _list_testdata(self, proid):
cur = self.db.cursor()
sqlstr = ('SELECT "testid", "proid", "info", "expire" FROM '
'"TESTDATA"')
sqlarr = []
if proid != None:
sqlstr = sqlstr + ' WHERE "proid" = %s'
sqlarr.append(proid)
sqlstr = sqlstr + ' ORDER BY "testid" ASC;'
cur.execute(sqlstr, sqlarr)
testdata_list = []
for data in cur:
obj = {}
obj['testid'] = data[0]
obj['proid'] = data[1]
obj['info'] = data[2]
obj['expire'] = data[3]
testdata_list.append(obj)
return testdata_list
def does_testid_exist(self, testid):
testdata = self._get_testdata(self, testid)
return testdata != None
|