[IMP] rewrite win32/setup.py to generate dynamic files
authorChristophe Simonis <chs@openerp.com>
Wed, 28 Nov 2012 12:09:50 +0000 (13:09 +0100)
committerChristophe Simonis <chs@openerp.com>
Wed, 28 Nov 2012 12:09:50 +0000 (13:09 +0100)
bzr revid: chs@openerp.com-20121128120950-bi6uv3bn73gotmwi

.bzrignore
openerp/release.py
openerp/tools/osutil.py
win32/OpenERPServerService.py
win32/setup.py
win32/start.bat [deleted file]
win32/stop.bat [deleted file]

index 8531ad4..e7618c7 100644 (file)
@@ -17,3 +17,5 @@ include/
 lib/
 share/
 doc/_build/*
+win32/*.bat
+win32/meta.py
index 50d9b8a..e66d924 100644 (file)
@@ -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:
index 949ba2a..2f72e09 100644 (file)
@@ -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()
 
index efd9243..c529b58 100644 (file)
@@ -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)
index 9c064c1..5366b63 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
-#    
+#
 #    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 #
 #    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 <http://www.gnu.org/licenses/>.     
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
 from distutils.core import setup
+import os
 import py2exe
 
+meta = {}
+execfile(os.path.join(os.path.dirname(__file__), '..', 'openerp', 'release.py'), meta)
+
+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],))
 
-setup(service=["OpenERPServerService"],
-      options={"py2exe":{"excludes":["Tkconstants","Tkinter","tcl",
-                                     "_imagingtk","PIL._imagingtk",
-                                     "ImageTk", "PIL.ImageTk",
-                                     "FixTk"],
-                         "skip_archive": 1,
-                         "optimize": 2,}}
+    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 (file)
index ff3c49b..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.\r
-\r
-@net stop openerp-server-6.1\r
-\r
-@net start openerp-server-6.1\r
-\r
-cls\r
diff --git a/win32/stop.bat b/win32/stop.bat
deleted file mode 100644 (file)
index 76a35b7..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.\r
-\r
-@net stop openerp-server-6.1\r
-\r
-cls\r