forked from informationextraction/test-av
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_service.py
69 lines (55 loc) · 1.97 KB
/
web_service.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
import subprocess
import traceback
import os
import sys
import win32serviceutil
import win32service
import win32event
class testLauncher(win32serviceutil.ServiceFramework):
_svc_name_ = 'AVTESTER-WEB'
_svc_display_name_ = 'AV TESTER WEB'
_svc_description_ = "NA"
def __init__(self, *args):
win32serviceutil.ServiceFramework.__init__(self, *args)
self.log('init')
self.runflag = True
self.stop_event = win32event.CreateEvent(None, 0, 0, None)
def log(self, msg):
import servicemanager
servicemanager.LogInfoMsg(str(msg))
def sleep(self, sec):
win32api.Sleep(sec*1000, True)
def SvcDoRun(self):
self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
try:
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
self.log('start')
sys.stdout.write("starting")
self.start()
while self.runflag == True:
pass
self.log('wait')
win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE)
self.log('done')
except Exception, x:
self.log('Exception : %s' % x)
self.SvcStop()
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
self.log('stopping')
self.stop()
self.log('stopped')
win32event.SetEvent(self.stop_event)
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
def start(self):
sys.stdout.write("opening")
pyPath = "c:/Python27/python.exe"
webPath = "c:/test-av/utils/web_analysis.py"
os.chdir("c:/test-av/")
proc = subprocess.call([pyPath,webPath],
stdin = subprocess.PIPE,
stdout = subprocess.PIPE)
def stop(self):
self.runflag = False
if __name__ == "__main__":
win32serviceutil.HandleCommandLine(testLauncher)