[IMP] rewrite win32/setup.py to generate dynamic files
bzr revid: chs@openerp.com-20121128120950-bi6uv3bn73gotmwi
This commit is contained in:
parent
9432574fec
commit
a55a26c777
|
@ -17,3 +17,5 @@ include/
|
||||||
lib/
|
lib/
|
||||||
share/
|
share/
|
||||||
doc/_build/*
|
doc/_build/*
|
||||||
|
win32/*.bat
|
||||||
|
win32/meta.py
|
||||||
|
|
|
@ -50,4 +50,6 @@ author = 'OpenERP S.A.'
|
||||||
author_email = 'info@openerp.com'
|
author_email = 'info@openerp.com'
|
||||||
license = 'AGPL-3'
|
license = 'AGPL-3'
|
||||||
|
|
||||||
|
nt_service_name = "openerp-server-" + serie
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -68,16 +68,16 @@ else:
|
||||||
# based on http://mail.python.org/pipermail/python-win32/2007-June/006174.html
|
# based on http://mail.python.org/pipermail/python-win32/2007-June/006174.html
|
||||||
_TH32CS_SNAPPROCESS = 0x00000002
|
_TH32CS_SNAPPROCESS = 0x00000002
|
||||||
class _PROCESSENTRY32(ctypes.Structure):
|
class _PROCESSENTRY32(ctypes.Structure):
|
||||||
_fields_ = [("dwSize", ctypes.c_ulong),
|
_fields_ = [("dwSize", ctypes.c_ulong),
|
||||||
("cntUsage", ctypes.c_ulong),
|
("cntUsage", ctypes.c_ulong),
|
||||||
("th32ProcessID", ctypes.c_ulong),
|
("th32ProcessID", ctypes.c_ulong),
|
||||||
("th32DefaultHeapID", ctypes.c_ulong),
|
("th32DefaultHeapID", ctypes.c_ulong),
|
||||||
("th32ModuleID", ctypes.c_ulong),
|
("th32ModuleID", ctypes.c_ulong),
|
||||||
("cntThreads", ctypes.c_ulong),
|
("cntThreads", ctypes.c_ulong),
|
||||||
("th32ParentProcessID", ctypes.c_ulong),
|
("th32ParentProcessID", ctypes.c_ulong),
|
||||||
("pcPriClassBase", ctypes.c_ulong),
|
("pcPriClassBase", ctypes.c_ulong),
|
||||||
("dwFlags", ctypes.c_ulong),
|
("dwFlags", ctypes.c_ulong),
|
||||||
("szExeFile", ctypes.c_char * 260)]
|
("szExeFile", ctypes.c_char * 260)]
|
||||||
|
|
||||||
def getppid():
|
def getppid():
|
||||||
CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot
|
CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot
|
||||||
|
@ -100,7 +100,7 @@ else:
|
||||||
CloseHandle(hProcessSnap)
|
CloseHandle(hProcessSnap)
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from openerp.release import serie
|
from openerp.release import nt_service_name
|
||||||
|
|
||||||
def is_running_as_nt_service():
|
def is_running_as_nt_service():
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
@ -110,10 +110,8 @@ else:
|
||||||
finally:
|
finally:
|
||||||
ws.CloseServiceHandle(srv)
|
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.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)
|
info = ws.QueryServiceStatusEx(hs)
|
||||||
return info.ProcessId == getppid()
|
return info.ProcessId == getppid()
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,19 @@ import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
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):
|
class OpenERPServerService(win32serviceutil.ServiceFramework):
|
||||||
# required info
|
# required info
|
||||||
_svc_name_ = "openerp-server-" + serie
|
_svc_name_ = meta.nt_service_name
|
||||||
_svc_display_name_ = "OpenERP Server " + serie
|
_svc_display_name_ = "%s %s" % (meta.description, meta.serie)
|
||||||
# optionnal info
|
|
||||||
_svc_description_ = "OpenERP Server %s service" % (serie,)
|
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
win32serviceutil.ServiceFramework.__init__(self, args)
|
win32serviceutil.ServiceFramework.__init__(self, args)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# OpenERP, Open Source Management Solution
|
# OpenERP, Open Source Management Solution
|
||||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||||
#
|
#
|
||||||
|
@ -15,22 +15,53 @@
|
||||||
# GNU Affero General Public License for more details.
|
# GNU Affero General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
import os
|
||||||
import py2exe
|
import py2exe
|
||||||
|
|
||||||
|
meta = {}
|
||||||
|
execfile(os.path.join(os.path.dirname(__file__), '..', 'openerp', 'release.py'), meta)
|
||||||
|
|
||||||
setup(service=["OpenERPServerService"],
|
def generate_files():
|
||||||
options={"py2exe":{"excludes":["Tkconstants","Tkinter","tcl",
|
actions = {
|
||||||
"_imagingtk","PIL._imagingtk",
|
'start': ['stop', 'start'],
|
||||||
"ImageTk", "PIL.ImageTk",
|
'stop': ['stop'],
|
||||||
"FixTk"],
|
}
|
||||||
"skip_archive": 1,
|
|
||||||
"optimize": 2,}}
|
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:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.
|
|
||||||
|
|
||||||
@net stop openerp-server-6.1
|
|
||||||
|
|
||||||
@net start openerp-server-6.1
|
|
||||||
|
|
||||||
cls
|
|
|
@ -1,5 +0,0 @@
|
||||||
@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.
|
|
||||||
|
|
||||||
@net stop openerp-server-6.1
|
|
||||||
|
|
||||||
cls
|
|
Loading…
Reference in New Issue