[REF] netsvc: LocalService() can be a function.
[odoo/odoo.git] / setup.py
index 9ab2284..e36662b 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -1,9 +1,9 @@
 #!/usr/bin/env python
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
 ##############################################################################
-#    
+#
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
+#    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
@@ -16,7 +16,7 @@
 #    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/>.
 #
 ##############################################################################
 
 #   taken from gnomolicious http://www.nongnu.org/gnomolicious/
 #   adapted by Nicolas Évrard <nicoe@altern.org>
 #
+# doc/migrate is not included since about 6.1-dev
+# doc/tests is not included
+# python25-compat/*py should be in the openerp (and imported appropriately)
 
-import imp
 import sys
 import os
+from os.path import join, isfile
 import glob
 
-from distutils.core import setup, Command
-from distutils.command.install import install
-
-has_py2exe = False
+from setuptools import setup, find_packages
+
+# Backports os.walk with followlinks from python 2.6.
+# Needed to add all addons files to data_files for Windows packaging.
+def walk_followlinks(top, topdown=True, onerror=None, followlinks=False):
+    from os.path import join, isdir, islink
+    from os import listdir, error
+
+    try:
+        names = listdir(top)
+    except error, err:
+        if onerror is not None:
+            onerror(err)
+        return
+
+    dirs, nondirs = [], []
+    for name in names:
+        if isdir(join(top, name)):
+            dirs.append(name)
+        else:
+            nondirs.append(name)
+
+    if topdown:
+        yield top, dirs, nondirs
+    for name in dirs:
+        path = join(top, name)
+        if followlinks or not islink(path):
+            for x in walk_followlinks(path, topdown, onerror, followlinks):
+                yield x
+    if not topdown:
+        yield top, dirs, nondirs
+
+if sys.version_info < (2, 6):
+    os.walk = walk_followlinks
+
+py2exe_keywords = {}
+py2exe_data_files = []
 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
-
-execfile(opj('bin', 'release.py'))
-
-if sys.argv[1] == 'bdist_rpm':
-    version = version.split('-')[0]
-
-# get python short version
-py_short_version = '%s.%s' % sys.version_info[:2]
-
-required_modules = [
-    ('psycopg2', 'PostgreSQL module'),
-    ('xml', 'XML Tools for python'),
-    ('libxml2', 'libxml2 python bindings'),
-    ('libxslt', 'libxslt python bindings'),
-    ('reportlab', 'reportlab module'),
-    ('pychart', 'pychart module'),
-    ('pydot', 'pydot module'),
-]
-
-def check_modules():
-    ok = True
-    for modname, desc in required_modules:
-        try:
-            exec('import %s' % modname)
-        except ImportError:
-            ok = False
-            print 'Error: python module %s (%s) is required' % (modname, desc)
-
-    if not ok:
-        sys.exit(1)
-
-def find_addons():
-    for (dp, dn, names) in os.walk(opj('bin', 'addons')):
-        if '__terp__.py' in names:
-            modname = dp.replace(os.path.sep, '.').replace('bin', 'openerp-server', 1)
-            yield modname
-
-def data_files():
-    '''Build list of data files to be installed'''
-    files = []
-    if os.name == 'nt':
-        os.chdir('bin')
-        for (dp,dn,names) in os.walk('addons'):
-            files.append((dp, map(lambda x: opj('bin', dp, x), names)))
+    py2exe_keywords['console'] = [
+        { "script": "openerp-server",
+          "icon_resources": [(1, join("pixmaps","openerp-icon.ico"))],
+        }]
+    py2exe_keywords['options'] = {
+        "py2exe": {
+            "skip_archive": 1,
+            "optimize": 2,
+            "dist_dir": 'dist',
+            "packages": [
+                "lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
+                "lxml.objectify", "decimal", "xml", "xml", "xml.dom", "xml.xpath",
+                "encodings", "dateutil", "pychart", "PIL", "pyparsing",
+                "pydot", "asyncore","asynchat", "reportlab", "vobject",
+                "HTMLParser", "select", "mako", "poplib",
+                "imaplib", "smtplib", "email", "yaml", "DAV",
+                "uuid", "commands", "openerp",
+            ],
+            "excludes" : ["Tkconstants","Tkinter","tcl"],
+        }
+    }
+    # TODO is it still necessary now that we don't use the library.zip file?
+    def data_files():
+        '''For Windows, we consider all the addons as data files.
+           It seems also that package_data below isn't honored by py2exe.'''
+        files = []
+        os.chdir('openerp')
+        for (dp, dn, names) in os.walk('addons'):
+            files.append((join('openerp',dp), map(lambda x: join('openerp', dp, x), names)))
         os.chdir('..')
-        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'),
-                            opj('bin', 'server.cert')]))
-    else:
-        man_directory = opj('share', 'man')
-        files.append((opj(man_directory, 'man1'), ['man/openerp-server.1']))
-        files.append((opj(man_directory, 'man5'), ['man/openerp_serverrc.5']))
-
-        doc_directory = opj('share', 'doc', 'openerp-server-%s' % version)
-        files.append((doc_directory, [f for f in glob.glob('doc/*') if os.path.isfile(f)]))
-        files.append((opj(doc_directory, 'migrate', '3.3.0-3.4.0'), [f for f in glob.glob('doc/migrate/3.3.0-3.4.0/*') if os.path.isfile(f)]))
-        files.append((opj(doc_directory, 'migrate', '3.4.0-4.0.0'), [f for f in glob.glob('doc/migrate/3.4.0-4.0.0/*') if os.path.isfile(f)]))
-
-        openerp_site_packages = opj('lib', 'python%s' % py_short_version, 'site-packages', 'openerp-server')
+        files.append(('openerp', [join('openerp', 'import_xml.rng'),]))
 
-        files.append((openerp_site_packages, [opj('bin', 'import_xml.rng'),
-                                              opj('bin', 'server.pkey'),
-                                              opj('bin', 'server.cert')]))
+        # copy pytz/timzeone
+        # TODO check if we have to also copy dateutil's timezone data.
+        import pytz
+        # Make sure the layout of pytz hasn't changed
+        assert (pytz.__file__.endswith('__init__.pyc') or
+                pytz.__file__.endswith('__init__.py')), pytz.__file__
+        pytz_dir = os.path.dirname(pytz.__file__)
 
-        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))
-            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), '.')))
-                    pathfiles.extend(((res, map(lambda file: opj(root, file), innerfiles)),))
-            files.extend(pathfiles)
+        saved_dir = os.getcwd()
+        os.chdir(pytz_dir)
+        for dp, dn, names in os.walk('zoneinfo'):
+            files.append((join('pytz',dp), map(lambda x: join(pytz_dir, dp, x), names)))
+        os.chdir(saved_dir)
 
-    return files
+        return files
+    py2exe_data_files = data_files()
 
-check_modules()
-
-f = file('openerp-server','w')
-start_script = """#!/bin/sh\necho "OpenERP Setup - The content of this file is generated at the install stage\n" """
-f.write(start_script)
-f.close()
-
-class openerp_server_install(install):
-    def run(self):
-        # create startup script
-        start_script = "#!/bin/sh\ncd %s\nexec %s ./openerp-server.py $@\n" % (opj(self.install_libbase, "openerp-server"), sys.executable)
-        # write script
-        f = open('openerp-server', 'w')
-        f.write(start_script)
-        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"],
-        "excludes" : ["Tkconstants","Tkinter","tcl"],
-    }
-}
+execfile(join('openerp', 'release.py'))
 
 setup(name             = name,
       version          = version,
@@ -162,57 +133,42 @@ setup(name             = name,
       author_email     = author_email,
       classifiers      = filter(None, classifiers.split("\n")),
       license          = license,
-      data_files       = data_files(),
-      cmdclass         = {
-            'install' : openerp_server_install,
-      },
+      data_files       = [
+        (join('man', 'man1'), ['man/openerp-server.1']),
+        (join('man', 'man5'), ['man/openerp_serverrc.5']),
+        ('doc', filter(isfile, glob.glob('doc/*'))),
+      ] + py2exe_data_files,
       scripts          = ['openerp-server'],
-      packages         = ['openerp-server',
-                          'openerp-server.addons',
-                          'openerp-server.ir',
-                          'openerp-server.osv',
-                          'openerp-server.service',
-                          'openerp-server.tools',
-                          'openerp-server.report',
-                          'openerp-server.report.printscreen',
-                          'openerp-server.report.pyPdf',
-                          'openerp-server.report.render',
-                          'openerp-server.report.render.rml2pdf',
-                          'openerp-server.report.render.rml2html',
-                          'openerp-server.wizard',
-                          'openerp-server.report.render.odt2odt',
-                          'openerp-server.report.render.html2html',
-                          '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,
-      )
-
-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()
+      packages = find_packages(),
+      include_package_data = True,
+      package_data = {
+          '': ['*.yml', '*.xml', '*.po', '*.pot', '*.csv'],
+      },
+      dependency_links = ['http://download.gna.org/pychart/'],
+      install_requires = [
+       # We require the same version as caldav for lxml.
+          'lxml==2.1.5',
+          'mako',
+          'python-dateutil',
+          'psycopg2',
+        # TODO the pychart package we include in openerp corresponds to PyChart 1.37.
+        # It seems there is a single difference, which is a spurious print in generate_docs.py.
+        # It is probably safe to move to PyChart 1.39 (the latest one).
+        # (Let setup.py choose the latest one, and we should check we can remove pychart from
+        # our tree.)
+          'pychart',
+          'pydot',
+          'pytz',
+          'reportlab',
+          'caldav',
+          'pyyaml',
+          'pywebdav',
+          'feedparser',
+          'simplejson >= 2.0',
+      ],
+      extras_require = {
+          'SSL' : ['pyopenssl'],
+      },
+      **py2exe_keywords
+)