[REF][FIX]: Windows packaging: lint, cleanup and make it work
authorSimon Lejeune <sle@openerp.com>
Tue, 2 Sep 2014 12:02:37 +0000 (14:02 +0200)
committerSimon Lejeune <sle@openerp.com>
Tue, 2 Sep 2014 12:13:01 +0000 (14:13 +0200)
setup.nsi: make it build and use postgresql 9.3
win32_se*: lint and simplified
Makefile: only one mode

setup/win32/Makefile
setup/win32/Makefile.python [new file with mode: 0644]
setup/win32/Makefile.version [new file with mode: 0644]
setup/win32/setup.nsi
setup/win32/win32_service.py
setup/win32/win32_setup.py

index 6378e17..ab8bc88 100644 (file)
@@ -1,9 +1,11 @@
 include Makefile.version
+include Makefile.python
 
-SERVER_DIRECTORY=../server
-FILES_DIRECTORY=files
+SERVER_DIRECTORY=../..
+FILES_DIRECTORY=release
 
-LAUNCH_PY2EXE=/cygdrive/c/python26/python.exe setup.py py2exe
+LAUNCH_PY2EXE_SERVICE=/cygdrive/c/python${PYTHON_VERSION}/python.exe win32_setup.py py2exe
+LAUNCH_PY2EXE=/cygdrive/c/python${PYTHON_VERSION}/python.exe setup.py py2exe
 
 MAKENSIS_ARGUMENTS=/DVERSION=$(VERSION)
 
@@ -23,14 +25,9 @@ server_clean:
        rm -rf $(SERVER_DIRECTORY)/*.exe
        rm -rf $(SERVER_DIRECTORY)/.cyg*
 
-server: server_clean
-       (cd $(SERVER_DIRECTORY)/win32 && $(LAUNCH_PY2EXE))
+allinone: server_clean
+       (cd $(SERVER_DIRECTORY)/setup/win32 && $(LAUNCH_PY2EXE_SERVICE))
        (cd $(SERVER_DIRECTORY) && $(LAUNCH_PY2EXE))
-#      rm -rf `/usr/bin/find ${SERVER_DIRECTORY}/dist/openerp/addons -maxdepth 1 -mindepth 1 -not -name "web*" -and -not -name "base" -type d | xargs rm -rf`
-       (cd $(SERVER_DIRECTORY) && $(LAUNCH_MAKENSIS))
-       cp $(SERVER_DIRECTORY)/openerp-*.exe $(FILES_DIRECTORY)/openerp-server-setup-$(VERSION).exe
-
-allinone: server
-       $(LAUNCH_MAKENSIS)
-       cp ./openerp-*.exe $(FILES_DIRECTORY)/openerp-allinone-setup-$(VERSION).exe
-
+       (cd $(SERVER_DIRECTORY)/setup/win32 && $(LAUNCH_MAKENSIS))
+       (cd $(SERVER_DIRECTORY)/setup/win32 && mkdir -p $(FILES_DIRECTORY))
+       (cd $(SERVER_DIRECTORY)/setup/win32 && cp openerp-*.exe $(FILES_DIRECTORY)/openerp-server-setup-$(VERSION).exe)
diff --git a/setup/win32/Makefile.python b/setup/win32/Makefile.python
new file mode 100644 (file)
index 0000000..84e766c
--- /dev/null
@@ -0,0 +1 @@
+PYTHON_VERSION=27
diff --git a/setup/win32/Makefile.version b/setup/win32/Makefile.version
new file mode 100644 (file)
index 0000000..e278258
--- /dev/null
@@ -0,0 +1 @@
+VERSION=
index b212958..3a02e4f 100755 (executable)
@@ -26,6 +26,7 @@
 \r
 # TODO: Avoid to uninstall the database\r
 # TODO: We can update the server or the clients without to uninstall the all-in-one\r
+# TODO: Add startmenu handling (link to localhost + uninstall)\r
 \r
 !include 'MUI2.nsh'\r
 !include 'FileFunc.nsh'\r
@@ -139,9 +140,8 @@ Var HWNDPostgreSQLPassword
 \r
 !define STATIC_PATH "static"\r
 !define PIXMAPS_PATH "${STATIC_PATH}\pixmaps"\r
-!define POSTGRESQL_EXE "${STATIC_PATH}\postgresql-8.3-int.msi"\r
-\r
-!define OPENERP_SERVER_SETUP 'openerp-server-setup-${VERSION}.exe'\r
+!define POSTGRESQL_EXE_FILENAME "postgresql-9.3.5-1-windows.exe"\r
+!define POSTGRESQL_EXE "${STATIC_PATH}\${POSTGRESQL_EXE_FILENAME}"\r
 \r
 !define MUI_ABORTWARNING\r
 !define MUI_ICON "${PIXMAPS_PATH}\openerp-icon.ico"\r
@@ -220,33 +220,46 @@ LangString Profile_AllInOne ${LANG_FRENCH} "All In One"
 LangString Profile_Server ${LANG_FRENCH} "Seulement le serveur"\r
 LangString TITLE_OpenERP_Server ${LANG_FRENCH} "Serveur OpenERP"\r
 LangString TITLE_PostgreSQL ${LANG_FRENCH} "Installation du serveur de base de donn?es PostgreSQL"\r
-LangString DESC_FinishPageText ${LANG_FRENCH} "Lancer OpenERP"\r
+LangString DESC_FinishPageText ${LANG_FRENCH} "Démarrer OpenERP"\r
 \r
 InstType $(Profile_AllInOne)\r
 InstType $(Profile_Server)\r
 \r
 Section $(TITLE_OpenERP_Server) SectionOpenERP_Server\r
     SectionIn 1 2\r
-    SetOutPath "$TEMP"\r
-    File "files\${OPENERP_SERVER_SETUP}"\r
-    ExecWait '"$TEMP\${OPENERP_SERVER_SETUP}" /S /D=$INSTDIR\Server'\r
 \r
-# If there is a previous install of the OpenERP Server, keep the login/password from the config file\r
-    WriteIniStr "$INSTDIR\Server\server\openerp-server.conf" "options" "db_host" $TextPostgreSQLHostname\r
-    WriteIniStr "$INSTDIR\Server\server\openerp-server.conf" "options" "db_user" $TextPostgreSQLUsername\r
-    WriteIniStr "$INSTDIR\Server\server\openerp-server.conf" "options" "db_password" $TextPostgreSQLPassword\r
-    WriteIniStr "$INSTDIR\Server\server\openerp-server.conf" "options" "db_port" $TextPostgreSQLPort\r
+    # TODO: install in a temp dir before\r
+\r
+    SetOutPath "$INSTDIR\server"\r
+    File /r "..\..\dist\*"\r
+\r
+    SetOutPath "$INSTDIR\service"\r
+    File /r "dist\*"\r
+    File "start.bat"\r
+    File "stop.bat"\r
 \r
-    # if we've going to install postgresql force it's path,\r
+# If there is a previous install of the OpenERP Server, keep the login/password from the config file\r
+    WriteIniStr "$INSTDIR\server\openerp-server.conf" "options" "db_host" $TextPostgreSQLHostname\r
+    WriteIniStr "$INSTDIR\server\openerp-server.conf" "options" "db_user" $TextPostgreSQLUsername\r
+    WriteIniStr "$INSTDIR\server\openerp-server.conf" "options" "db_password" $TextPostgreSQLPassword\r
+    WriteIniStr "$INSTDIR\server\openerp-server.conf" "options" "db_port" $TextPostgreSQLPort\r
+    # Fix the addons path\r
+    WriteIniStr "$INSTDIR\server\openerp-server.conf" "options" "addons_path" "$INSTDIR\server\openerp\addons"\r
+\r
+    # if we're going to install postgresql force it's path,\r
     # otherwise we consider it's always done and/or correctly tune by users\r
     ${If} $HasPostgreSQL == 0\r
-        WriteIniStr "$INSTDIR\Server\server\openerp-server.conf" "options" "pg_path" "$INSTDIR\PostgreSQL\bin"\r
+        WriteIniStr "$INSTDIR\server\openerp-server.conf" "options" "pg_path" "$INSTDIR\PostgreSQL\bin"\r
     ${EndIf}\r
 \r
-    nsExec::Exec "net stop openerp-server-7.0"\r
+    nsExec::Exec '"$INSTDIR\server\openerp-server.exe" --stop-after-init --logfile "$INSTDIR\server\openerp-server.log" -s'\r
+    nsExec::Exec '"$INSTDIR\service\win32_service.exe" -auto -install'\r
+\r
+    # TODO: don't hardcode the service name\r
+    nsExec::Exec "net stop openerp-server-8.0"\r
     sleep 2\r
 \r
-    nsExec::Exec "net start openerp-server-7.0"\r
+    nsExec::Exec "net start openerp-server-8.0"\r
     sleep 2\r
 \r
 SectionEnd\r
@@ -256,7 +269,7 @@ Section $(TITLE_PostgreSQL) SectionPostgreSQL
     SetOutPath '$TEMP'\r
     nsExec::Exec 'net user openpgsvc /delete'\r
 \r
-    File "postgresql-9.2.2-1-windows.exe"\r
+    File ${POSTGRESQL_EXE}\r
 \r
     ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName"\r
     StrCmp $0 "" win9x\r
@@ -265,7 +278,7 @@ Section $(TITLE_PostgreSQL) SectionPostgreSQL
         ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName"\r
     done:\r
     Rmdir /r "$INSTDIR\PostgreSQL"\r
-    ExecWait '"$TEMP\postgresql-9.2.2-1-windows.exe" \\r
+    ExecWait '"$TEMP\${POSTGRESQL_EXE_FILENAME}" \\r
         --mode unattended \\r
         --prefix "$INSTDIR\PostgreSQL" \\r
         --datadir "$INSTDIR\PostgreSQL\data" \\r
@@ -305,6 +318,10 @@ Section "Uninstall"
     ReadRegStr $0 HKLM "${UNINSTALL_REGISTRY_KEY_SERVER}" "UninstallString"\r
     ExecWait '"$0" /S'\r
 \r
+    nsExec::Exec "net stop openerp-server-8.0"\r
+    nsExec::Exec "sc delete openerp-server-8.0"\r
+    sleep 2\r
+\r
     Rmdir /r "$INSTDIR\server"\r
     Rmdir /r "$INSTDIR\service"\r
 \r
index 8b3c117..fcc6b89 100644 (file)
@@ -1,82 +1,53 @@
 # -*- coding: utf-8 -*-
-##############################################################################
-#
-#    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
-#
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU Affero General Public License as
-#    published by the Free Software Foundation, either version 3 of the
-#    License, or (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    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/>.
-#
-##############################################################################
 
-import win32serviceutil
-import win32service
+import servicemanager
 import win32api
 import win32process
-import servicemanager
+import win32service
+import win32serviceutil
 
-import sys
 import subprocess
-import os
+import sys
+from os.path import dirname, join, split
+
+
+execfile(join(dirname(__file__), '..', 'server', 'openerp', 'release.py'))
 
-try:
-    import meta
-except ImportError:
-    if hasattr(sys, 'frozen'):
-        raise
-    from setup import generate_files
-    generate_files()
-    import meta     # noqa
 
-class OpenERPServerService(win32serviceutil.ServiceFramework):
-    # required info
-    _svc_name_ = meta.nt_service_name
-    _svc_display_name_ = "%s %s" % (meta.description, meta.serie)
+class OdooService(win32serviceutil.ServiceFramework):
+    _svc_name_ = nt_service_name
+    _svc_display_name_ = "%s %s" % (nt_service_name, serie)
 
     def __init__(self, args):
         win32serviceutil.ServiceFramework.__init__(self, args)
-        # a reference to the server's process
-        self.terpprocess = None
+        self.odooprocess = None  # Reference to the server's process
 
     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 OpenERP Server: say it's a normal exit
-        win32api.TerminateProcess(int(self.terpprocess._handle), 0)
-        servicemanager.LogInfoMsg("OpenERP Server stopped correctly")
-
-    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, 'server', 'openerp-server.exe')
-        self.terpprocess = subprocess.Popen([server_path], cwd=server_dir, creationflags=win32process.CREATE_NO_WINDOW)
+        # Stop the running Odoo: say it's a normal exit
+        win32api.TerminateProcess(int(self.odooprocess._handle), 0)
+        servicemanager.LogInfoMsg("Odoo stopped correctly")
 
     def SvcDoRun(self):
-        self.StartTERP()
-        servicemanager.LogInfoMsg("OpenERP Server up and running")
-        # exit with same exit code as OpenERP process
-        sys.exit(self.terpprocess.wait())
+        # We start Odoo as an independent process, but we keep its handle
+        service_dir = dirname(sys.argv[0])
+        server_dir = split(service_dir)[0]
+        server_path = join(server_dir, 'server', 'openerp-server.exe')
+        self.odooprocess = subprocess.Popen(
+            [server_path], cwd=server_dir, creationflags=win32process.CREATE_NO_WINDOW
+        )
+        servicemanager.LogInfoMsg('Odoo up and running')
+        # exit with same exit code as Odoo process
+        sys.exit(self.odooprocess.wait())
 
 
 def option_handler(opts):
     # configure the service to auto restart on failures...
-    subprocess.call(['sc', 'failure', meta.nt_service_name, 'reset=', '0', 'actions=', 'restart/0/restart/0/restart/0'])
+    subprocess.call([
+        'sc', 'failure', nt_service_name, 'reset=', '0', 'actions=', 'restart/0/restart/0/restart/0'
+    ])
 
-if __name__ == '__main__':
-    # Do with the service whatever option is passed in the command line
-    win32serviceutil.HandleCommandLine(OpenERPServerService, customOptionHandler=option_handler)
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+if __name__ == '__main__':
+    win32serviceutil.HandleCommandLine(OdooService, customOptionHandler=option_handler)
index b0b36b5..dcebaf3 100644 (file)
@@ -1,32 +1,13 @@
 # -*- coding: utf-8 -*-
-##############################################################################
-#
-#    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
-#
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU Affero General Public License as
-#    published by the Free Software Foundation, either version 3 of the
-#    License, or (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    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/>.
-#
-##############################################################################
 
 import os
 import glob
-from distutils.core import setup
 import py2exe
+from distutils.core import setup
 
 
-meta = {}
-execfile(os.path.join(os.path.dirname(__file__), '..', 'openerp', 'release.py'), meta)
+execfile(os.path.join(os.path.dirname(__file__), '..', '..', 'openerp', 'release.py'))
+
 
 def generate_files():
     actions = {
@@ -43,29 +24,31 @@ def generate_files():
         with open(fname, 'w') as fp:
             fp.write('@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.\n')
             for step in steps:
-                fp.write('@net %s %s\n' % (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\n" % (m, meta[m],))
-
+                fp.write('@net %s %s\n' % (step, nt_service_name))
     return files
 
-excludes = "Tkconstants Tkinter tcl _imagingtk PIL._imagingtk ImageTk PIL.ImageTk FixTk".split()
-
-setup(service      = ["OpenERPServerService"],
-      version      = meta['version'],
-      license      = meta['license'],
-      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:
+setup(
+    service=["win32_service"],
+    version=version,
+    license=license,
+    url=url,
+    author=author,
+    author_email=author_email,
+    data_files=generate_files(),
+    options={
+        "py2exe": {
+            "excludes": [
+                'Tkconstants',
+                'Tkinter',
+                'tcl',
+                '_imagingtk',
+                'PIL._imagingtk',
+                'ImageTk',
+                'PIL.ImageTk',
+                'FixTk'
+            ],
+            "skip_archive": 1,
+            "optimize": 2,
+        }
+    },
+)