[IMP] setup.py: Rewrite some parts of the setup.py
authorStephane Wirtel <stephane@openerp.com>
Wed, 5 May 2010 15:14:24 +0000 (17:14 +0200)
committerStephane Wirtel <stephane@openerp.com>
Wed, 5 May 2010 15:14:24 +0000 (17:14 +0200)
bzr revid: stephane@openerp.com-20100505151424-wb65zpiez7uwi0a1

setup.py

index 9a2a63e..6a9ea60 100755 (executable)
--- a/setup.py
+++ b/setup.py
 #
 ##############################################################################
 
-# setup from TinERP
+# setup for OpenERP Server
 #   taken from straw http://www.nongnu.org/straw/index.html
 #   taken from gnomolicious http://www.nongnu.org/gnomolicious/
 #   adapted by Nicolas Évrard <nicoe@altern.org>
-#
 
-import imp
 import sys
 import os
 import glob
 
-from distutils.core import setup, Command
+from distutils.core import setup
 from distutils.command.install import install
 
-has_py2exe = False
-if os.name == 'nt':
-    import py2exe
-    has_py2exe = True
-
 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), "bin"))
 
 opj = os.path.join
@@ -81,12 +74,12 @@ def find_addons():
 def data_files():
     '''Build list of data files to be installed'''
     files = []
-    if os.name == 'nt':
+    if sys.platform == 'win32':
         os.chdir('bin')
-        for (dp,dn,names) in os.walk('addons'):
+        for (dp, dn, names) in os.walk('addons'):
             files.append((dp, map(lambda x: opj('bin', dp, x), names)))
         os.chdir('..')
-        for (dp,dn,names) in os.walk('doc'):
+        for (dp, dn, names) in os.walk('doc'):
             files.append((dp, map(lambda x: opj(dp, x), names)))
         files.append(('.', [opj('bin', 'import_xml.rng'),
                             opj('bin', 'server.pkey'),
@@ -110,12 +103,16 @@ def data_files():
         for addon in find_addons():
             addonname = addon.split('.')[-1]
             add_path = addon.replace('.', os.path.sep).replace('openerp-server', 'bin', 1)
-            addon_path = opj('lib', 'python%s' % py_short_version, 'site-packages', add_path.replace('bin', 'openerp-server', 1))
+            addon_path = opj('lib', 'python%s' % py_short_version,
+                             'site-packages',
+                             add_path.replace('bin', 'openerp-server', 1))
             pathfiles = []
             for root, dirs, innerfiles in os.walk(add_path):
                 innerfiles = filter(lambda file: os.path.splitext(file)[1] not in ('.pyc', '.pyd', '.pyo'), innerfiles)
                 if innerfiles:
-                    res = os.path.normpath(opj(addon_path, root.replace(opj('bin','addons', addonname), '.')))
+                    res = os.path.normpath(
+                        opj(addon_path, root.replace(opj('bin', 'addons', addonname), '.'))
+                    )
                     pathfiles.extend(((res, map(lambda file: opj(root, file), innerfiles)),))
             files.extend(pathfiles)
 
@@ -138,22 +135,39 @@ class openerp_server_install(install):
         f.close()
         install.run(self)
 
-options = {
-    "py2exe": {
-        "compressed": 1,
-        "optimize": 2,
-        "dist_dir": 'dist',
-        "packages": [
-            "lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
-            "lxml.objectify", "decimal", "xml", "xml.dom", "xml.xpath",
-            "encodings", "mx.DateTime","wizard","pychart","PIL", "pyparsing",
-            "pydot", "asyncore", "asynchat", "reportlab", "vobject",
-            "HTMLParser", "select", "mako", "poplib",
-            "imaplib", "smtplib", "email",
-        ],
-        "excludes" : ["Tkconstants","Tkinter","tcl"],
+complementary_arguments = dict()
+
+has_py2exe = False
+
+if sys.platform == 'win32':
+    complementary_arguments['windows'] = [
+        {
+            "script" : os.path.join('bin', 'openerp-server.py'),
+            "icon_resources" : [ (1, os.path.join('pixmaps', 'openerp-icon.ico')) ]
+        }
+    ]
+
+    import py2exe
+
+    has_py2exe = True
+
+    complementary_arguments['options'] = {
+        'py2exe' : {
+            "compressed": 1,
+            "optimize": 2,
+            "dist_dir": 'dist',
+            "packages": [
+                "lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
+                "lxml.objectify", "decimal", "xml", "xml.dom", "xml.xpath",
+                "encodings", "mx.DateTime","wizard","pychart","PIL", "pyparsing",
+                "pydot", "asyncore", "asynchat", "reportlab", "vobject",
+                "HTMLParser", "select", "mako", "poplib",
+                "imaplib", "smtplib", "email",
+            ],
+            "excludes" : ["Tkconstants","Tkinter","tcl"],
+        }
     }
-}
+
 
 setup(name             = name,
       version          = version,
@@ -166,7 +180,7 @@ setup(name             = name,
       license          = license,
       data_files       = data_files(),
       cmdclass         = {
-            'install' : openerp_server_install,
+          'install' : openerp_server_install,
       },
       scripts          = ['openerp-server'],
       packages         = ['openerp-server',
@@ -187,34 +201,35 @@ setup(name             = name,
                           'openerp-server.workflow'] + \
                          list(find_addons()),
       package_dir      = {'openerp-server': 'bin'},
-      console = [ { "script" : "bin\\openerp-server.py", "icon_resources" : [ (1,"pixmaps\\openerp-icon.ico") ] } ],
-      options = options,
-      )
+      **complementary_arguments
+     )
 
 if has_py2exe:
-  # Sometime between pytz-2008a and pytz-2008i common_timezones started to
-  # include only names of zones with a corresponding data file in zoneinfo.
-  # pytz installs the zoneinfo directory tree in the same directory
-  # as the pytz/__init__.py file. These data files are loaded using
-  # pkg_resources.resource_stream. py2exe does not copy this to library.zip so
-  # resource_stream can't find the files and common_timezones is empty when
-  # read in the py2exe executable.
-  # This manually copies zoneinfo into the zip. See also
-  # http://code.google.com/p/googletransitdatafeed/issues/detail?id=121
-  import pytz
-  import zipfile
-  # Make sure the layout of pytz hasn't changed
-  assert (pytz.__file__.endswith('__init__.pyc') or
-          pytz.__file__.endswith('__init__.py')), pytz.__file__
-  zoneinfo_dir = os.path.join(os.path.dirname(pytz.__file__), 'zoneinfo')
-  # '..\\Lib\\pytz\\__init__.py' -> '..\\Lib'
-  disk_basedir = os.path.dirname(os.path.dirname(pytz.__file__))
-  zipfile_path = os.path.join(options['py2exe']['dist_dir'], 'library.zip')
-  z = zipfile.ZipFile(zipfile_path, 'a')
-  for absdir, directories, filenames in os.walk(zoneinfo_dir):
-    assert absdir.startswith(disk_basedir), (absdir, disk_basedir)
-    zip_dir = absdir[len(disk_basedir):]
-    for f in filenames:
-      z.write(os.path.join(absdir, f), os.path.join(zip_dir, f))
-  z.close()
+    # Sometime between pytz-2008a and pytz-2008i common_timezones started to
+    # include only names of zones with a corresponding data file in zoneinfo.
+    # pytz installs the zoneinfo directory tree in the same directory
+    # as the pytz/__init__.py file. These data files are loaded using
+    # pkg_resources.resource_stream. py2exe does not copy this to library.zip so
+    # resource_stream can't find the files and common_timezones is empty when
+    # read in the py2exe executable.
+    # This manually copies zoneinfo into the zip. See also
+    # http://code.google.com/p/googletransitdatafeed/issues/detail?id=121
+    import pytz
+    import zipfile
+    # Make sure the layout of pytz hasn't changed
+    assert (pytz.__file__.endswith('__init__.pyc') or
+            pytz.__file__.endswith('__init__.py')), pytz.__file__
+    zoneinfo_dir = os.path.join(os.path.dirname(pytz.__file__), 'zoneinfo')
+    # '..\\Lib\\pytz\\__init__.py' -> '..\\Lib'
+    disk_basedir = os.path.dirname(os.path.dirname(pytz.__file__))
+    zipfile_path = os.path.join(complementary_arguments['options']['py2exe']['dist_dir'], 'library.zip')
+    z = zipfile.ZipFile(zipfile_path, 'a')
+
+    for absdir, directories, filenames in os.walk(zoneinfo_dir):
+        assert absdir.startswith(disk_basedir), (absdir, disk_basedir)
+        zip_dir = absdir[len(disk_basedir):]
+        for f in filenames:
+            z.write(os.path.join(absdir, f), os.path.join(zip_dir, f))
+
+    z.close()