From a55a26c777a0e6d9e8c49f35e6154734d3933171 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 28 Nov 2012 13:09:50 +0100 Subject: [PATCH] [IMP] rewrite win32/setup.py to generate dynamic files bzr revid: chs@openerp.com-20121128120950-bi6uv3bn73gotmwi --- .bzrignore | 2 ++ openerp/release.py | 2 ++ openerp/tools/osutil.py | 26 +++++++++--------- win32/OpenERPServerService.py | 15 +++++++---- win32/setup.py | 51 ++++++++++++++++++++++++++++------- win32/start.bat | 7 ----- win32/stop.bat | 5 ---- 7 files changed, 67 insertions(+), 41 deletions(-) delete mode 100644 win32/start.bat delete mode 100644 win32/stop.bat diff --git a/.bzrignore b/.bzrignore index 8531ad42bbb..e7618c7b0ce 100644 --- a/.bzrignore +++ b/.bzrignore @@ -17,3 +17,5 @@ include/ lib/ share/ doc/_build/* +win32/*.bat +win32/meta.py diff --git a/openerp/release.py b/openerp/release.py index 50d9b8ac760..e66d924906b 100644 --- a/openerp/release.py +++ b/openerp/release.py @@ -50,4 +50,6 @@ author = 'OpenERP S.A.' author_email = 'info@openerp.com' license = 'AGPL-3' +nt_service_name = "openerp-server-" + serie + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/tools/osutil.py b/openerp/tools/osutil.py index 949ba2a8422..2f72e099f7f 100644 --- a/openerp/tools/osutil.py +++ b/openerp/tools/osutil.py @@ -68,16 +68,16 @@ else: # based on http://mail.python.org/pipermail/python-win32/2007-June/006174.html _TH32CS_SNAPPROCESS = 0x00000002 class _PROCESSENTRY32(ctypes.Structure): - _fields_ = [("dwSize", ctypes.c_ulong), - ("cntUsage", ctypes.c_ulong), - ("th32ProcessID", ctypes.c_ulong), - ("th32DefaultHeapID", ctypes.c_ulong), - ("th32ModuleID", ctypes.c_ulong), - ("cntThreads", ctypes.c_ulong), - ("th32ParentProcessID", ctypes.c_ulong), - ("pcPriClassBase", ctypes.c_ulong), - ("dwFlags", ctypes.c_ulong), - ("szExeFile", ctypes.c_char * 260)] + _fields_ = [("dwSize", ctypes.c_ulong), + ("cntUsage", ctypes.c_ulong), + ("th32ProcessID", ctypes.c_ulong), + ("th32DefaultHeapID", ctypes.c_ulong), + ("th32ModuleID", ctypes.c_ulong), + ("cntThreads", ctypes.c_ulong), + ("th32ParentProcessID", ctypes.c_ulong), + ("pcPriClassBase", ctypes.c_ulong), + ("dwFlags", ctypes.c_ulong), + ("szExeFile", ctypes.c_char * 260)] def getppid(): CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot @@ -100,7 +100,7 @@ else: CloseHandle(hProcessSnap) from contextlib import contextmanager - from openerp.release import serie + from openerp.release import nt_service_name def is_running_as_nt_service(): @contextmanager @@ -110,10 +110,8 @@ else: finally: ws.CloseServiceHandle(srv) - service_name = 'openerp-server-' + serie - with close_srv(ws.OpenSCManager(None, None, ws.SC_MANAGER_ALL_ACCESS)) as hscm: - with close_srv(ws.SmartOpenService(hscm, service_name, ws.SERVICE_ALL_ACCESS)) as hs: + with close_srv(ws.SmartOpenService(hscm, nt_service_name, ws.SERVICE_ALL_ACCESS)) as hs: info = ws.QueryServiceStatusEx(hs) return info.ProcessId == getppid() diff --git a/win32/OpenERPServerService.py b/win32/OpenERPServerService.py index efd9243fc31..c529b582ba4 100644 --- a/win32/OpenERPServerService.py +++ b/win32/OpenERPServerService.py @@ -29,14 +29,19 @@ import sys import subprocess import os -from ..openerp.release import serie +try: + import meta +except ImportError: + if hasattr(sys, 'frozen'): + raise + from setup import generate_files + generate_files() + import meta class OpenERPServerService(win32serviceutil.ServiceFramework): # required info - _svc_name_ = "openerp-server-" + serie - _svc_display_name_ = "OpenERP Server " + serie - # optionnal info - _svc_description_ = "OpenERP Server %s service" % (serie,) + _svc_name_ = meta.nt_service_name + _svc_display_name_ = "%s %s" % (meta.description, meta.serie) def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) diff --git a/win32/setup.py b/win32/setup.py index 9c064c1f6d8..5366b63ab4d 100644 --- a/win32/setup.py +++ b/win32/setup.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # @@ -15,22 +15,53 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## from distutils.core import setup +import os import py2exe +meta = {} +execfile(os.path.join(os.path.dirname(__file__), '..', 'openerp', 'release.py'), meta) -setup(service=["OpenERPServerService"], - options={"py2exe":{"excludes":["Tkconstants","Tkinter","tcl", - "_imagingtk","PIL._imagingtk", - "ImageTk", "PIL.ImageTk", - "FixTk"], - "skip_archive": 1, - "optimize": 2,}} +def generate_files(): + actions = { + 'start': ['stop', 'start'], + 'stop': ['stop'], + } + + files = [] + for action, steps in actions.items(): + fname = action + '.bat' + files.append(fname) + with open(fname, 'w') as fp: + fp.write('@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.') + for step in steps: + fp.write('@net %s %s' % (step, meta['nt_service_name'])) + + files.append('meta.py') + with open('meta.py', 'w') as fp: + for m in 'description serie nt_service_name'.split(): + fp.write("%s = %r" % (m, meta[m],)) + + return files + +excludes = "Tkconstants Tkinter tcl _imagingtk PIL._imagingtk ImageTk PIL.ImageTk FixTk".split() + +setup(service = ["OpenERPServerService"], + version = meta['version'], + licence = meta['licence'], + url = meta['url'], + author = meta['author'], + author_email = meta['author_email'], + data_files = generate_files(), + options = {"py2exe": { + "excludes": excludes, + "skip_archive": 1, + "optimize": 2, + }} ) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/win32/start.bat b/win32/start.bat deleted file mode 100644 index ff3c49b1397..00000000000 --- a/win32/start.bat +++ /dev/null @@ -1,7 +0,0 @@ -@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;. - -@net stop openerp-server-6.1 - -@net start openerp-server-6.1 - -cls diff --git a/win32/stop.bat b/win32/stop.bat deleted file mode 100644 index 76a35b7e91f..00000000000 --- a/win32/stop.bat +++ /dev/null @@ -1,5 +0,0 @@ -@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;. - -@net stop openerp-server-6.1 - -cls