-
Notifications
You must be signed in to change notification settings - Fork 0
/
sondeHTTP.py
55 lines (43 loc) · 1.84 KB
/
sondeHTTP.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
from BaseHTTPServer import HTTPServer,BaseHTTPRequestHandler
import urllib2
import subprocess
from os import path
from urlparse import urlparse
from urlparse import parse_qs
class SondeHandler(BaseHTTPRequestHandler):
def do_GET(self):
try:
self.send_response(200)
url=urlparse(self.path)
script=url.path
arg=["./script/"+script]
for key,value in parse_qs(url.query).items():
arg.append("-"+str(key))
arg.append(str(value[0]))
rep=self.execScript(arg)
self.send_header('Content-Type','text/html')
except Exception, e:
self.send_response(500)
self.send_header('Content-Type','text/html')
rep="ERROR : "+str(e)
self.end_headers()
self.wfile.write(rep)
def execScript(self,arg):
print arg
value=str(subprocess.check_output(arg).strip())
return value
class myHTTPServer(HTTPServer):
def __init__(self, *args, **kw):
self.port=args[0][1]
HTTPServer.__init__(self, *args, **kw)
self.stopHTTP=False
def serve_forever(self):
while ( self.stopHTTP == False):
self.handle_request()
class SondeHTTP():
def __init__(self):
self.port=8080
print 'Start HTTP server on '+str(self.port)
self.server = myHTTPServer(('',self.port),SondeHandler)
self.server.serve_forever()
print 'Stop HTTP server on '+str(self.port)