Skip to content
Snippets Groups Projects
setup.py 7.28 KiB
Newer Older
Fabien Pinckaers's avatar
Fabien Pinckaers committed
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
##############################################################################
#
Christophe Simonis's avatar
Christophe Simonis committed
#    OpenERP, Open Source Management Solution	
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
Christophe Simonis's avatar
Christophe Simonis committed
#    $Id$
Christophe Simonis's avatar
Christophe Simonis committed
#    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.
Christophe Simonis's avatar
Christophe Simonis committed
#    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.
Christophe Simonis's avatar
Christophe Simonis committed
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
Christophe Simonis's avatar
Christophe Simonis committed
##############################################################################
Christophe Simonis's avatar
Christophe Simonis committed

Fabien Pinckaers's avatar
Fabien Pinckaers committed
# setup from TinERP
#   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.command.install import install
Fabien Pinckaers's avatar
Fabien Pinckaers committed

Cédric Krier's avatar
Cédric Krier committed
if os.name == 'nt':
    import py2exe

sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), "bin"))
Fabien Pinckaers's avatar
Fabien Pinckaers committed

opj = os.path.join

Cédric Krier's avatar
Cédric Krier committed
execfile(opj('bin', 'release.py'))
Fabien Pinckaers's avatar
Fabien Pinckaers committed

if sys.argv[1] != 'bdist_rpm':
    version = version + '-' + release

Fabien Pinckaers's avatar
Fabien Pinckaers committed
# get python short version
py_short_version = '%s.%s' % sys.version_info[:2]

Stéphane Wirtel's avatar
Stéphane Wirtel committed
required_modules = [
    ('psycopg2', 'PostgreSQL module'),
Stéphane Wirtel's avatar
Stéphane Wirtel committed
    ('xml', 'XML Tools for python'),
    ('libxml2', 'libxml2 python bindings'),
Stéphane Wirtel's avatar
Stéphane Wirtel committed
    ('libxslt', 'libxslt python bindings'),
    ('reportlab', 'reportlab module'),
    ('pychart', 'pychart module'),
    ('pydot', 'pydot module'),
Fabien Pinckaers's avatar
Fabien Pinckaers committed

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():
Cédric Krier's avatar
Cédric Krier committed
    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
Fabien Pinckaers's avatar
Fabien Pinckaers committed

def data_files():
    '''Build list of data files to be installed'''
Cédric Krier's avatar
Cédric Krier committed
    files = []
    if os.name == 'nt':
        os.chdir('bin')
        for (dp,dn,names) in os.walk('addons'):
Stéphane Wirtel's avatar
Stéphane Wirtel committed
            files.append((dp, map(lambda x: opj('bin', dp, x), names)))
Cédric Krier's avatar
Cédric Krier committed
        os.chdir('..')
        for (dp,dn,names) in os.walk('doc'):
Stéphane Wirtel's avatar
Stéphane Wirtel committed
            files.append((dp, map(lambda x: opj(dp, x), names)))
Stéphane Wirtel's avatar
Stéphane Wirtel committed
        files.append(('.', [opj('bin', 'import_xml.rng'),
                            opj('bin', 'server.pkey'), 
                            opj('bin', 'server.cert')]))
Cédric Krier's avatar
Cédric Krier committed
    else:
Stéphane Wirtel's avatar
Stéphane Wirtel committed
        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_site_packages, [opj('bin', 'import_xml.rng'),
                                              opj('bin', 'server.pkey'),
                                              opj('bin', 'server.cert')]))

Cédric Krier's avatar
Cédric Krier committed
        for addon in find_addons():
            addonname = addon.split('.')[-1]
Stéphane Wirtel's avatar
Stéphane Wirtel committed
            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):
Stéphane Wirtel's avatar
Stéphane Wirtel committed
                innerfiles = filter(lambda file: os.path.splitext(file)[1] not in ('.pyc', '.pyd', '.pyo'), innerfiles)
                    res = os.path.normpath(opj(addon_path, root.replace(opj('bin','addons', addonname), '.')))
                    pathfiles.extend(((res, map(lambda file: opj(root, file), innerfiles)),))
Cédric Krier's avatar
Cédric Krier committed
            files.extend(pathfiles)
Fabien Pinckaers's avatar
Fabien Pinckaers committed
    return files

check_modules()

Stéphane Wirtel's avatar
Stéphane Wirtel committed
f = file('openerp-server','w')
start_script = """#!/bin/sh\necho "OpenERP Setup - The content of this file is generated at the install stage\n" """
Stéphane Wirtel's avatar
Stéphane Wirtel committed
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)
Fabien Pinckaers's avatar
Fabien Pinckaers committed

Stéphane Wirtel's avatar
Stéphane Wirtel committed
options = {
    "py2exe": {
Stéphane Wirtel's avatar
Stéphane Wirtel committed
        "optimize": 2, 
        "packages": ["lxml", "lxml.builder", "lxml._elementpath", "lxml.etree", 
                     "lxml.objectify", "decimal", "xml", "xml.dom", "xml.xpath", 
                     "encodings","mx.DateTime","wizard","pychart","PIL", "pyparsing", 
Stéphane Wirtel's avatar
Stéphane Wirtel committed
                     "pydot","asyncore","asynchat", "reportlab", "vobject",
                     "HTMLParser", "select"],
Stéphane Wirtel's avatar
Stéphane Wirtel committed
        "excludes" : ["Tkconstants","Tkinter","tcl"],
    }
}
Fabien Pinckaers's avatar
Fabien Pinckaers committed
setup(name             = name,
      version          = version,
Cédric Krier's avatar
Cédric Krier committed
      description      = description,
Fabien Pinckaers's avatar
Fabien Pinckaers committed
      long_description = long_desc,
Cédric Krier's avatar
Cédric Krier committed
      url              = url,
      author           = author,
      author_email     = author_email,
Fabien Pinckaers's avatar
Fabien Pinckaers committed
      classifiers      = filter(None, classifiers.split("\n")),
Cédric Krier's avatar
Cédric Krier committed
      license          = license,
Fabien Pinckaers's avatar
Fabien Pinckaers committed
      data_files       = data_files(),
Stéphane Wirtel's avatar
Stéphane Wirtel committed
      cmdclass         = { 
            'install' : openerp_server_install,
      },
      scripts          = ['openerp-server'],
Stéphane Wirtel's avatar
Stéphane Wirtel committed
      packages         = ['openerp-server', 
                          'openerp-server.addons',
                          'openerp-server.ir',
                          'openerp-server.osv',
Stéphane Wirtel's avatar
Stéphane Wirtel committed
                          'openerp-server.service', 
                          'openerp-server.tools',
                          'openerp-server.report',
                          'openerp-server.report.printscreen',
                          'openerp-server.report.render',
                          'openerp-server.report.render.rml2pdf',
                          'openerp-server.report.render.rml2html',
Stéphane Wirtel's avatar
Stéphane Wirtel committed
                          'openerp-server.wizard', 
                          'openerp-server.workflow'] + \
Fabien Pinckaers's avatar
Fabien Pinckaers committed
                         list(find_addons()),
      package_dir      = {'openerp-server': 'bin'},
      console = [ { "script" : "bin\\openerp-server.py", "icon_resources" : [ (1,"pixmaps\\openerp-icon.ico") ] } ],
Cédric Krier's avatar
Cédric Krier committed
      options = options,
Fabien Pinckaers's avatar
Fabien Pinckaers committed
      )


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: