KERNEL: add win32 compile

bzr revid: ced-5040a2a33469b094dd0fa2a7ca9a3e60d3547708
This commit is contained in:
ced 2007-06-11 11:10:47 +00:00
parent 6232b2e8ab
commit 10efe308d5
6 changed files with 138 additions and 1 deletions

View File

@ -125,7 +125,7 @@ class configmanager(object):
# if the server is run by an unprivileged user, he has to specify location of a config file where he has the rights to write,
# else he won't be able to save the configurations, or even to start the server...
if os.name == 'nt':
rcfilepath = os.path.join(os.path.split(os.path.split(os.path.abspath(sys.argv[0]))[0])[0], 'etc', 'tinyerp-server.conf')
rcfilepath = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'tinyerp-server.conf')
else:
rcfilepath = os.path.expanduser('~/.terp_serverrc')

View File

@ -52,6 +52,10 @@
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_CHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Start TinyERP Server"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME $INSTDIR\README.txt
!insertmacro MUI_PAGE_FINISH
@ -71,26 +75,42 @@
Section "TinyERP Server" SecTinyERPServer
nsExec::Exec "net stop tinyerp-service"
sleep 2
SetOutPath "$INSTDIR"
;ADD YOUR OWN FILES HERE...
File /r "dist\\*"
SetOutPath "$INSTDIR\service"
File /r "win32\\dist\\*"
File "win32\\start.bat"
File "win32\\stop.bat"
;Store installation folder
WriteRegStr HKCU "Software\TinyERP Server" "" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
;Create shortcuts
CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\TinyERP Server.lnk" "$INSTDIR\tinyerp-server.exe"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Start service.lnk" "$INSTDIR\service\start.bat"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Stop service.lnk" "$INSTDIR\service\stop.bat"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Edit config.lnk" "notepad.exe" "$INSTDIR\tinyerp-server.conf"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Edit log.lnk" "notepad.exe" "$INSTDIR\tinyerp-server.log"
!insertmacro MUI_STARTMENU_WRITE_END
nsExec::Exec '"$INSTDIR\\tinyerp-server.exe" --stop-after-init --logfile "$INSTDIR\\tinyerp-server.log" -s'
nsExec::Exec '"$INSTDIR\\service\\TinyERPServerService.exe" -auto -install'
SectionEnd
;Descriptions
@ -108,11 +128,17 @@ SectionEnd
Section "Uninstall"
nsExec::Exec "net stop tinyerp-service"
sleep 2
nsExec::Exec '"$INSTDIR\\service\\TinyERPServerService.exe" -remove'
sleep 2
;ADD YOUR OWN FILES HERE...
Delete "$INSTDIR\Uninstall.exe"
Push "$INSTDIR\addons"
Push ""
Call un.RmFilesButOne
Delete "$INSTDIR\service\*"
Delete "$INSTDIR\*"
Delete "$INSTDIR\Uninstall.exe"
@ -120,12 +146,15 @@ Section "Uninstall"
Push ""
Call un.RmDirsButOne
RMDir "$INSTDIR\addons"
RMDir "$INSTDIR\service"
RMDir "$INSTDIR"
!insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
Delete "$SMPROGRAMS\$MUI_TEMP\TinyERP Server.lnk"
Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
Delete "$SMPROGRAMS\$MUI_TEMP\Start service.lnk"
Delete "$SMPROGRAMS\$MUI_TEMP\Stop service.lnk"
;Delete empty start menu parent diretories
StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
@ -144,6 +173,10 @@ Section "Uninstall"
SectionEnd
Function LaunchLink
nsExec::Exec "net start tinyerp-service"
FunctionEnd
Function un.RmDirsButOne
Exch $R0 ; exclude dir
Exch

View File

@ -0,0 +1,80 @@
#
# TinyERPServerService.py
#
# Script installing Tiny ERP as Windows service
# Win32 python extensions modules
import win32serviceutil
import win32service
import win32event
import win32api
import win32process
import servicemanager
import sys
import subprocess
import os
import thread
class TinyERPServerService(win32serviceutil.ServiceFramework):
# required info
_svc_name_ = "tinyerp-service"
_svc_display_name_ = "Tiny ERP Server"
# optionnal info
_svc_description_ = "Tiny ERP Server service"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
# a reference to the server's process
self.terpprocess = None
# info if the service terminates correctly or if the server crashed
self.stopping = False
def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop process.
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
# stop the running TERP Server: say it's a normal exit
win32api.TerminateProcess(int(self.terpprocess._handle), 0)
servicemanager.LogInfoMsg("Tiny ERP Server stopped correctly")
# And set my event.
win32event.SetEvent(self.hWaitStop)
def StartTERP(self):
# The server finds now its configuration automatically on Windows
# We start the ERP Server as an independent process, but we keep its handle
# The server's binary must be one directory above the service's binary (when py2exe'd the python libraries shouldn' mix)
service_dir = os.path.dirname(sys.argv[0])
server_dir = os.path.split(service_dir)[0]
server_path = os.path.join(server_dir, 'tinyerp-server.exe')
self.terpprocess = subprocess.Popen([server_path], \
cwd=server_dir,
creationflags=win32process.CREATE_NO_WINDOW)
def StartControl(self,ws):
# this listens to the Service Manager's events
win32event.WaitForSingleObject(ws, win32event.INFINITE)
self.stopping = True
def SvcDoRun(self):
# Start Tiny ERP Server itself
self.StartTERP()
# start the loop waiting for the Service Manager's stop signal
thread.start_new_thread(self.StartControl, (self.hWaitStop,))
# Log a info message that the server is running
servicemanager.LogInfoMsg("Tiny ERP Server up and running")
# verification if the server is really running, else quit with an error
self.terpprocess.wait()
if not self.stopping:
sys.exit("Tiny ERP Server check: server not running, check the logfile for more info")
if __name__=='__main__':
# Do with the service whatever option is passed in the command line
win32serviceutil.HandleCommandLine(TinyERPServerService)

12
win32/setup.py Normal file
View File

@ -0,0 +1,12 @@
# setup.py
from distutils.core import setup
import py2exe
setup(service=["TinyERPServerService"],
options={"py2exe":{"excludes":["Tkconstants","Tkinter","tcl",
"_imagingtk","PIL._imagingtk",
"ImageTk", "PIL.ImageTk",
"FixTk"],
"compressed": 1}}
)

7
win32/start.bat Normal file
View File

@ -0,0 +1,7 @@
@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.
@net stop tinyerp-service
@net start tinyerp-service
cls

5
win32/stop.bat Normal file
View File

@ -0,0 +1,5 @@
@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.
@net stop tinyerp-service
cls