fixed winservice problem

This commit is contained in:
mdipierro
2012-12-10 21:32:36 -06:00
parent c02b79f0c3
commit a98f45f875
3 changed files with 13 additions and 12 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.3.0 (2012-12-09 14:28:45) rc1 Version 2.3.0 (2012-12-10 21:31:49) rc1
+5 -3
View File
@@ -34,7 +34,7 @@ try:
import Tkinter import Tkinter
import tkMessageBox import tkMessageBox
import contrib.taskbar_widget import contrib.taskbar_widget
from winservice import web2py_windows_service_handler from winservice import register_service_handler, Web2pyService
have_winservice = True have_winservice = True
except: except:
have_winservice = False have_winservice = False
@@ -1116,8 +1116,10 @@ def start(cron=True):
if options.winservice: if options.winservice:
if os.name == 'nt': if os.name == 'nt':
if have_winservice: if have_winservice:
web2py_windows_service_handler(['', options.winservice], register_service_handler(
options.config) argv=['', options.winservice],
opt_file=options.config,
cls=Web2pyService)
else: else:
print 'Error: Missing python module winservice' print 'Error: Missing python module winservice'
sys.exit(1) sys.exit(1)
+7 -8
View File
@@ -191,22 +191,21 @@ class Web2pyCronService(Web2pyService):
if self.extcron: if self.extcron:
self.extcron.join() self.extcron.join()
def register_service_handler( def register_service_handler(argv=None, opt_file='options', cls=Web2pyService):
name=Web2pyService, argv=None, opt_file='options'):
path = os.path.dirname(__file__) path = os.path.dirname(__file__)
web2py_path = up(path) web2py_path = up(path)
if web2py_path.endswith('.zip'): # in case bianry distro 'library.zip' if web2py_path.endswith('.zip'): # in case bianry distro 'library.zip'
web2py_path = os.path.dirname(web2py_path) web2py_path = os.path.dirname(web2py_path)
os.chdir(web2py_path) os.chdir(web2py_path)
classstring = os.path.normpath( classstring = os.path.normpath(
os.path.join(web2py_path, 'gluon.winservice.'+name.__name__)) os.path.join(web2py_path, 'gluon.winservice.'+cls.__name__))
if opt_file: if opt_file:
name._exe_args_ = opt_file cls._exe_args_ = opt_file
win32serviceutil.HandleCommandLine( win32serviceutil.HandleCommandLine(
name, serviceClassString=classstring, argv=['', 'install']) cls, serviceClassString=classstring, argv=['', 'install'])
win32serviceutil.HandleCommandLine( win32serviceutil.HandleCommandLine(
name, serviceClassString=classstring, argv=argv) cls, serviceClassString=classstring, argv=argv)
if __name__ == '__main__': if __name__ == '__main__':
register_service_handler(Web2pyService) register_service_handler(cls=Web2pyService)
register_service_handler(Web2pyCronService) register_service_handler(cls=Web2pyCronService)