-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadfilessv.py
225 lines (193 loc) · 6.99 KB
/
uploadfilessv.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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env python
from pysimplesoap.server import SoapDispatcher, SOAPHandler
from BaseHTTPServer import HTTPServer
from pysimplesoap.simplexml import SimpleXMLElement
import pickle
import array
import gtk, gobject
import thread, time
#global
g_current_content_def = dict()
g_contenf_def_list = list()
g_last_content_update_time = time.time()
g_current_content_idx = -1
class TestWindow:
# This is a callback function. The data arguments are ignored
# in this example. More on callbacks below.
def hello(self, widget, data=None):
print "Hello World"
def delete_event(self, widget, event, data=None):
# If you return FALSE in the "delete_event" signal handler,
# GTK will emit the "destroy" signal. Returning TRUE means
# you don't want the window to be destroyed.
# This is useful for popping up 'are you sure you want to quit?'
# type dialogs.
print "delete event occurred"
# Change FALSE to TRUE and the main window will not be destroyed
# with a "delete_event".
return False
# Another callback
def destroy(self, widget, data=None):
gtk.main_quit()
def __init__(self):
# create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
# When the window is given the "delete_event" signal (this is given
# by the window manager, usually by the "close" option, or on the
# titlebar), we ask it to call the delete_event () function
# as defined above. The data passed to the callback
# function is NULL and is ignored in the callback function.
self.window.connect("delete_event", self.delete_event)
# Here we connect the "destroy" event to a signal handler.
# This event occurs when we call gtk_widget_destroy() on the window,
# or if we return FALSE in the "delete_event" callback.
self.window.connect("destroy", self.destroy)
# Sets the border width of the window.
self.window.set_border_width(10)
# Creates a labels
self.label_time = gtk.Label("time")
self.label_content = gtk.Label("content")
# This packs the button into the window (a GTK container).
self.pane = gtk.VPaned()
self.pane.add(self.label_time)
self.pane.add(self.label_content)
self.window.add(self.pane)
# The final step is to display this newly created widget.
self.label_time.show()
self.label_content.show()
self.pane.show()
# and the window
self.window.show()
def main(self):
# All PyGTK applications must have a gtk.main(). Control ends here
# and waits for an event to occur (like a key press or mouse event).
print "Entering gtk.main()..."
gtk.main()
def callback(httpd):
print "enter callback"
global g_test_window
g_test_window.label_time.set_text(time.ctime())
#check contents definition
nowtime = time.localtime()
now_h = nowtime.tm_hour
now_m = nowtime.tm_min
h = 0
m = 0
global g_contenf_def_list, g_current_content_def, g_current_content_idx, g_last_content_update_time
for contents_def in g_contenf_def_list:
start_h = contents_def['start_h']
start_m = contents_def['start_m']
if start_h >= h and start_h <= now_h :
if start_m >= m and start_m <= now_m :
h = start_h
m = start_m
interval = contents_def['interval']
contents = contents_def['contents']
g_current_content_def = contents_def
#show current content
if len(g_current_content_def) > 0 :
print 'start time=%(h)02d:%(m)02d' % {"h": g_current_content_def['start_h'], "m": g_current_content_def['start_m']}
print 'interval=%(interval)d' % {"interval": g_current_content_def['interval']}
content_idx = 0
for content in g_current_content_def['contents']:
print ' %(content_idx)d : %(content)s' % {"content_idx": content_idx, "content": content}
content_idx = content_idx + 1
#check interval and change contents
time_diff = time.time() - g_last_content_update_time
print "past from last update: %(time_diff)d" % {"time_diff": time_diff}
if len(g_current_content_def) > 0 :
interval = g_current_content_def['interval']
if interval < time_diff or g_current_content_idx == -1:
contents = g_current_content_def['contents']
i = iter(contents)
index = 0
g_current_content_idx = g_current_content_idx + 1
for content_name in i:
if index == g_current_content_idx:
g_test_window.label_content.set_text(content_name)
g_last_content_update_time = time.time()
break;
else :
index = index + 1
#handle web serice request
httpd.handle_request()
#The function is called repeatedly until it returns FALSE
return True
# Define a function for Web Service
def uploadConfigAndImages(contests_def_list_str, imgs_str):
#print(conf_dic_str)
with open("out\\contents_def.dat", 'wb') as f1:
f1.write(contests_def_list_str)
with open("out\\imgs.dat", 'wb') as f2:
f2.write(imgs_str)
global g_contenf_def_list
g_contenf_def_list = pickle.loads(contests_def_list_str)
for contents_def in g_contenf_def_list:
start_h = contents_def['start_h']
start_m = contents_def['start_h']
print 'start time=%(h)02d:%(m)02d' % {"h": start_h, "m": start_m}
interval = contents_def['interval']
print 'interval=%(interval)d' % {"interval": interval}
contents = contents_def['contents']
content_idx = 0
for content in contents:
print ' %(content_idx)d : %(content)s' % {"content_idx": content_idx, "content": content}
content_idx = content_idx + 1
imgs = pickle.loads(imgs_str)
for image_name in iter(imgs):
print(image_name)
ar = imgs[image_name]
with open("out/" + image_name, 'wb') as f3:
ar.tofile(f3)
return 0
def uploadImages(imgsstr):
#print(imgsstr)
imgs = pickle.loads(imgsstr)
for image_name in iter(imgs):
print(image_name)
ar = imgs[image_name]
with open("out\\" + image_name, 'wb') as f2:
ar.tofile(f2)
return 0
def uploadImage(name, imgstr):
try:
print(name)
print(imgstr)
img = pickle.loads(imgstr)
#xmlElm = SimpleXMLElement("<xmlElm><a>" + imgxmlstr + "</a></xmlElm>")
#print(xmlElm.children())
#img = xmlElm.unmarshall({'img':array.array})
print(img)
with open("out\\" + name, 'wb') as f2:
img.tofile(f2)
except Exception as e:
print e
return 0
# If the program is run directly or passed as an argument to the python
# interpreter then create a server instance and show window
if __name__ == "__main__":
dispatcher = SoapDispatcher(
'my_dispatcher',
location = "http://localhost:8008/",
action = 'http://localhost:8008/', # SOAPAction
namespace = "http://example.com/sample.wsdl", prefix="ns0",
trace = True,
ns = True)
# register the user function
dispatcher.register_function('uploadImages', uploadImages,
returns={'Result': int},
args={'imgs_str': str})
dispatcher.register_function('uploadImage', uploadImage,
returns={'Result': int},
args={'name': str, 'imgstr': str})
dispatcher.register_function('uploadConfigAndImages', uploadConfigAndImages,
returns={'Result': int},
args={'contests_def_list_str': str, 'imgs_str': str})
print "Starting server..."
httpd = HTTPServer(("", 8008), SOAPHandler)
httpd.dispatcher = dispatcher
httpd.timeout = 1
#httpd.serve_forever()
gobject.timeout_add_seconds(2, callback, httpd)
g_test_window = TestWindow()
g_test_window.main()