[FIX] MRP : Corrected picking creation from procurement
[odoo/odoo.git] / setup.py
index 200d57a..f98c4b3 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -1,65 +1,58 @@
 #!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# setup from TinERP
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
+#    $Id$
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU 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 General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+# 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>
-#
-# $Id$
 
-import imp
 import sys
 import os
 import glob
 
-from distutils.core import setup, Command
-from distutils.command.install_scripts import install_scripts
-from distutils.file_util import copy_file
+from distutils.core import setup
+from distutils.command.install import install
+from distutils.sysconfig import get_python_lib
 
-from stat import ST_MODE
+sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), "bin"))
 
 opj = os.path.join
 
-name = 'tinyerp-server'
-version = '4.0.0'
+execfile(opj('bin', 'release.py'))
+
+if 'bdist_rpm' in sys.argv:
+    version = version.split('-')[0]
 
 # get python short version
 py_short_version = '%s.%s' % sys.version_info[:2]
 
-included_addons = [
-    'account', 'account_followup', 'account_tax_include', 'airport', 'audittrail',
-    'base','base_partner_relation', 'base_setup', 'crm', 'custom', 'delivery',
-    'edi', 'esale_ez', 'esale_joomla', 'esale_osc',
-    'hr', 'hr_evaluation', 'hr_expense', 'hr_skill', 'hr_timesheet',
-    'hr_timesheet_ical', 'hr_timesheet_invoice', 'hr_timesheet_project',
-    'letter', 'marketing', 'mrp', 'network', 'partner_ldap',
-    'product','product_electronic', 'product_expiry', 'product_extended',
-    'productivity_analysis', 'product_variant', 'profile_accounting',
-    'profile_manufacturing', 'profile_service', 'project', 'purchase',
-    'purchase_tax_include', 'report_analytic_line', 'report_crm',
-    'report_project', 'report_purchase', 'report_sale', 'sale', 'sale_crm',
-    'sale_journal', 'sale_rebate', 'sale_tax_include', 'sandwich', 'scrum',
-    'stock', 'subscription', 'travel',
-    'l10n_be', 'l10n_ca-qc', 'l10n_ch', 'l10n_ch_pcpbl_association',
-    'l10n_ch_pcpbl_independant', 'l10n_ch_pcpbl_menage',
-    'l10n_ch_pcpbl_plangen', 'l10n_ch_pcpbl_plangensimpl', 'l10n_ch_vat_brut',
-    'l10n_ch_vat_forfait', 'l10n_ch_vat_net', 'l10n_fr', 'l10n_se',
-    'l10n_simple', 'l10n_chart_at', 'l10n_chart_au', 'l10n_chart_be_frnl',
-    'l10n_chart_br', 'l10n_chart_ca_en', 'l10n_chart_ca_fr',
-    'l10n_chart_ch_german', 'l10n_chart_cn', 'l10n_chart_cn_traditional',
-    'l10n_chart_co', 'l10n_chart_cz', 'l10n_chart_da', 'l10n_chart_de_skr03',
-    'l10n_chart_hu', 'l10n_chart_id', 'l10n_chart_it', 'l10n_chart_it_cc2424',
-    'l10n_chart_la', 'l10n_chart_nl', 'l10n_chart_nl_standard', 'l10n_chart_no',
-    'l10n_chart_pa', 'l10n_chart_pl', 'l10n_chart_sp', 'l10n_chart_sw',
-    'l10n_chart_sw_church', 'l10n_chart_sw_food', 'l10n_chart_uk',
-    'l10n_chart_us_general', 'l10n_chart_us_manufacturing',
-    'l10n_chart_us_service', 'l10n_chart_us_ucoa', 'l10n_chart_us_ucoa_ez',
-    'l10n_chart_ve',]
-
-required_modules = [('psycopg', 'PostgreSQL module'),
-                    ('xml', 'XML Tools for python'),
-                    ('libxml2', 'libxml2 python bindings'),
-                    ('libxslt', 'libxslt python bindings')]
+required_modules = [
+    ('psycopg2', 'PostgreSQL module'),
+    ('reportlab', 'reportlab module'),
+    ('pychart', 'pychart module'),
+    ('pydot', 'pydot module'),
+    ('lxml', 'lxml module: pythonic libxml2 and libxslt bindings'),
+]
 
 def check_modules():
     ok = True
@@ -74,97 +67,169 @@ def check_modules():
         sys.exit(1)
 
 def find_addons():
-    for addon in included_addons:
-        path = opj('bin', 'addons', addon)
-        for dirpath, dirnames, filenames in os.walk(path):
-            if '__init__.py' in filenames:
-                modname = dirpath.replace(os.path.sep, '.')
-                yield modname.replace('bin', 'tinyerp-server', 1)
+    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 = [(opj('share', 'man', 'man1'),
-              ['man/tinyerp-server.1']),
-             (opj('share', 'man', 'man5'),
-              ['man/terp_serverrc.5']),
-             (opj('share','doc', 'tinyerp-server-%s' % version), 
-              [f for f in glob.glob('doc/*') if os.path.isfile(f)]),
-             (opj('lib','python%s' % py_short_version, 'site-package', 'tinyerp-server', 'i18n'), 
-              glob.glob('bin/i18n/*')),
-             (opj('lib', 'python%s' % py_short_version, 'site-packages', 'tinyerp-server', 'addons', 'custom'),
-              glob.glob('bin/addons/custom/*xml') + 
-              glob.glob('bin/addons/custom/*rml') +
-              glob.glob('bin/addons/custom/*xsl'))]
-    for addon in find_addons():
-        add_path = addon.replace('.', os.path.sep).replace('tinyerp-server', 'bin',
-                                                           1)
-        pathfiles = [(opj('lib', 'python%s' % py_short_version, 'site-packages', 
-                          add_path.replace('bin', 'tinyerp-server', 1)),
-                      glob.glob(opj(add_path, '*xml')) +
-                      glob.glob(opj(add_path, '*csv')) +
-                      glob.glob(opj(add_path, '*sql'))),
-                     (opj('lib', 'python%s' % py_short_version, 'site-packages',
-                          add_path.replace('bin', 'tinyerp-server', 1), 'data'),
-                      glob.glob(opj(add_path, 'data', '*xml'))), 
-                     (opj('lib', 'python%s' % py_short_version, 'site-packages',
-                          add_path.replace('bin', 'tinyerp-server', 1), 'report'),
-                      glob.glob(opj(add_path, 'report', '*xml')) +
-                      glob.glob(opj(add_path, 'report', '*rml')) +
-                      glob.glob(opj(add_path, 'report', '*xsl')))]
-        files.extend(pathfiles)
-    return files
-
-long_desc = '''\
-Tiny ERP is a complete ERP and CRM. The main features are accounting (analytic
-and financial), stock management, sales and purchases management, tasks
-automation, marketing campaigns, help desk, POS, etc. Technical features include
-a distributed server, flexible workflows, an object database, a dynamic GUI,
-customizable reports, and SOAP and XML-RPC interfaces.
-'''
+    files = []
+    if sys.platform == 'win32':
+        os.chdir('bin')
+        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'):
+            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(get_python_lib(prefix=''), 'openerp-server')
+
+        files.append((openerp_site_packages, [opj('bin', 'import_xml.rng'),
+                                              opj('bin', 'server.pkey'),
+                                              opj('bin', 'server.cert')]))
+
+        for addon in find_addons():
+            addonname = addon.split('.')[-1]
+            add_path = addon.replace('.', os.path.sep).replace('openerp-server', 'bin', 1)
+            addon_path = opj(get_python_lib(prefix=''),
+                             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)
 
-classifiers = """\
-Development Status :: 5 - Production/Stable
-License :: OSI Approved :: GNU General Public License (GPL)
-Programming Language :: Python
-"""
+    return files
 
 check_modules()
 
-# create startup script
-start_script = \
-"#!/bin/sh\n\
-cd %s/lib/python%s/site-packages/tinyerp-server\n\
-exec %s ./tinyerp-server.py $@" % (sys.prefix, py_short_version, sys.executable)
-# write script
-f = open('tinyerp-server', 'w')
+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)
+
+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,
-      description      = "Tiny's Enterprise Resource Planning",
+      description      = description,
       long_description = long_desc,
-      url              = 'http://tinyerp.com',
-      author           = 'Tiny.be',
-      author_email     = 'info@tiny.be',
+      url              = url,
+      author           = author,
+      author_email     = author_email,
       classifiers      = filter(None, classifiers.split("\n")),
-      license          = 'GPL',
+      license          = license,
       data_files       = data_files(),
-      packages         = ['tinyerp-server', 'tinyerp-server.addons',
-                          'tinyerp-server.ir',
-                          'tinyerp-server.osv',
-                          'tinyerp-server.ssl',
-                          'tinyerp-server.service', 'tinyerp-server.tools',
-                          'tinyerp-server.pychart', 'tinyerp-server.pychart.afm',
-                          'tinyerp-server.report',
-                          'tinyerp-server.report.printscreen',
-                          'tinyerp-server.report.render',
-                          'tinyerp-server.report.render.rml2pdf',
-                          'tinyerp-server.report.render.rml2html',
-                          'tinyerp-server.wizard', 'tinyerp-server.workflow'] + \
+      cmdclass         = {
+          'install' : openerp_server_install,
+      },
+      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      = {'tinyerp-server': 'bin'},
-      scripts          = ['tinyerp-server']
-      )
+      package_dir      = {'openerp-server': 'bin'},
+      **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(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()
 
-# vim:expandtab:tw=80