[FIX] Load all directories in the addons by the setup
[odoo/odoo.git] / setup.py
1 #!/usr/bin/env python
2 # -*- encoding: utf-8 -*-
3 ##############################################################################
4 #
5 #    OpenERP, Open Source Management Solution   
6 #    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
7 #    $Id$
8 #
9 #    This program is free software: you can redistribute it and/or modify
10 #    it under the terms of the GNU General Public License as published by
11 #    the Free Software Foundation, either version 3 of the License, or
12 #    (at your option) any later version.
13 #
14 #    This program is distributed in the hope that it will be useful,
15 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #    GNU General Public License for more details.
18 #
19 #    You should have received a copy of the GNU General Public License
20 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22 ##############################################################################
23
24 # setup from TinERP
25 #   taken from straw http://www.nongnu.org/straw/index.html
26 #   taken from gnomolicious http://www.nongnu.org/gnomolicious/
27 #   adapted by Nicolas Évrard <nicoe@altern.org>
28 #
29
30 import imp
31 import sys
32 import os
33 import glob
34
35 from stat import ST_MODE
36
37 from distutils.core import setup, Command
38 from distutils.command.install import install
39 from distutils.command.build import build
40 from distutils.command.build_scripts import build_scripts
41 from distutils.command.install_scripts import install_scripts
42 from distutils.file_util import copy_file
43
44 if os.name == 'nt':
45     import py2exe
46
47 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), "bin"))
48
49 opj = os.path.join
50
51 execfile(opj('bin', 'release.py'))
52
53 # get python short version
54 py_short_version = '%s.%s' % sys.version_info[:2]
55
56 required_modules = [
57     ('psycopg', 'PostgreSQL module'),
58     ('xml', 'XML Tools for python'),
59     ('libxml2', 'libxml2 python bindings'),
60     ('libxslt', 'libxslt python bindings'),
61     ('reportlab', 'reportlab module'),
62     ('pychart', 'pychart module'),
63     ('pydot', 'pydot module'),
64 ]
65
66 def check_modules():
67     ok = True
68     for modname, desc in required_modules:
69         try:
70             exec('import %s' % modname)
71         except ImportError:
72             ok = False
73             print 'Error: python module %s (%s) is required' % (modname, desc)
74
75     if not ok:
76         sys.exit(1)
77
78 def find_addons():
79     for (dp, dn, names) in os.walk(opj('bin', 'addons')):
80         if '__init__.py' in names:
81             modname = dp.replace(os.path.sep, '.').replace('bin', 'openerp-server', 1)
82             yield modname
83
84 def data_files():
85     '''Build list of data files to be installed'''
86     files = []
87     if os.name == 'nt':
88         os.chdir('bin')
89         for (dp,dn,names) in os.walk('addons'):
90             files.append((dp, map(lambda x: opj('bin', dp, x), names)))
91         os.chdir('..')
92         for (dp,dn,names) in os.walk('doc'):
93             files.append((dp, map(lambda x: opj(dp, x), names)))
94         files.append(('.', [(opj('bin', 'import_xml.rng'))]))
95     else:
96         man_directory = opj('share', 'man')
97         files.append((opj(man_directory, 'man1'), ['man/openerp-server.1']))
98         files.append((opj(man_directory, 'man5'), ['man/openerp_serverrc.5']))
99
100         doc_directory = opj('share', 'doc', 'openerp-server-%s' % version)
101         files.append((doc_directory, [f for f in glob.glob('doc/*') if os.path.isfile(f)]))
102         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)]))
103         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)]))
104
105         openerp_site_packages = opj('lib', 'python%s' % py_short_version, 'site-packages', 'openerp-server')
106
107         files.append((openerp_site_packages, [('bin/import_xml.rng')]))
108
109         for addon in find_addons():
110             add_path = addon.replace('.', os.path.sep).replace('openerp-server', 'bin', 1)
111             addon_path = opj('lib', 'python%s' % py_short_version, 'site-packages', add_path.replace('bin', 'openerp-server', 1))
112
113             pathfiles = []
114             for root, dirs, innerfiles in os.walk(add_path):
115                 innerfiles = filter(lambda file: os.path.splitext(file)[1] not in ('.pyc', '.py', '.pyd', '.pyo'), innerfiles)
116                 if innerfiles:
117                     pathfiles.extend(((opj(addon_path, root.replace('bin/addons/', '')), map(lambda file: opj(root, file), innerfiles)),))
118             files.extend(pathfiles)
119     return files
120
121 check_modules()
122
123 f = file('openerp-server','w')
124 start_script = """#!/bin/sh\necho "OpenERP Setup - The content of this file is generated at the install stage" """
125 f.write(start_script)
126 f.close()
127
128 class openerp_server_install(install):
129     def run(self):
130         # create startup script
131         start_script = "#!/bin/sh\ncd %s\nexec %s ./openerp-server.py $@\n" % (opj(self.install_libbase, "openerp-server"), sys.executable)
132         # write script
133         f = open('openerp-server', 'w')
134         f.write(start_script)
135         f.close()
136         install.run(self)
137
138 options = {
139     "py2exe": {
140         "compressed": 1,
141         "optimize": 2, 
142         "packages": ["lxml", "lxml.builder", "lxml._elementpath", "lxml.etree", 
143                      "lxml.objectify", "decimal", "xml", "xml.dom", "xml.xpath", 
144                      "encodings","mx.DateTime","wizard","pychart","PIL", "pyparsing", 
145                      "pydot","asyncore","asynchat", "reportlab", "vobject", "HTMLParser"],
146         "excludes" : ["Tkconstants","Tkinter","tcl"],
147     }
148 }
149
150 setup(name             = name,
151       version          = version,
152       description      = description,
153       long_description = long_desc,
154       url              = url,
155       author           = author,
156       author_email     = author_email,
157       classifiers      = filter(None, classifiers.split("\n")),
158       license          = license,
159       data_files       = data_files(),
160       cmdclass         = { 
161             'install' : openerp_server_install,
162       },
163       scripts          = ['openerp-server'],
164       packages         = ['openerp-server', 
165                           'openerp-server.addons',
166                           'openerp-server.ir',
167                           'openerp-server.osv',
168                           'openerp-server.ssl',
169                           'openerp-server.service', 
170                           'openerp-server.tools',
171                           'openerp-server.report',
172                           'openerp-server.report.printscreen',
173                           'openerp-server.report.render',
174                           'openerp-server.report.render.rml2pdf',
175                           'openerp-server.report.render.rml2html',
176                           'openerp-server.wizard', 
177                           'openerp-server.workflow'] + \
178                          list(find_addons()),
179       package_dir      = {'openerp-server': 'bin'},
180       console = [ 
181           { "script" : "bin\\openerp-server.py", 
182             "icon_resources" : [
183                 (1,"pixmaps\\openerp-icon.ico")
184             ]
185           }
186       ],
187       options = options,
188       )
189
190
191 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
192