[FIX] Update the MANIFEST.in to include the rng files and the po files
[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
40 if os.name == 'nt':
41     import py2exe
42
43 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), "bin"))
44
45 opj = os.path.join
46
47 execfile(opj('bin', 'release.py'))
48
49 # get python short version
50 py_short_version = '%s.%s' % sys.version_info[:2]
51
52 required_modules = [
53     ('psycopg2', 'PostgreSQL module'),
54     ('xml', 'XML Tools for python'),
55     ('libxml2', 'libxml2 python bindings'),
56     ('libxslt', 'libxslt python bindings'),
57     ('reportlab', 'reportlab module'),
58     ('pychart', 'pychart module'),
59     ('pydot', 'pydot module'),
60 ]
61
62 def check_modules():
63     ok = True
64     for modname, desc in required_modules:
65         try:
66             exec('import %s' % modname)
67         except ImportError:
68             ok = False
69             print 'Error: python module %s (%s) is required' % (modname, desc)
70
71     if not ok:
72         sys.exit(1)
73
74 def find_addons():
75     for (dp, dn, names) in os.walk(opj('bin', 'addons')):
76         if '__init__.py' in names:
77             modname = dp.replace(os.path.sep, '.').replace('bin', 'openerp-server', 1)
78             yield modname
79
80 def data_files():
81     '''Build list of data files to be installed'''
82     files = []
83     if os.name == 'nt':
84         os.chdir('bin')
85         for (dp,dn,names) in os.walk('addons'):
86             files.append((dp, map(lambda x: opj('bin', dp, x), names)))
87         os.chdir('..')
88         for (dp,dn,names) in os.walk('doc'):
89             files.append((dp, map(lambda x: opj(dp, x), names)))
90     else:
91         man_directory = opj('share', 'man')
92         files.append((opj(man_directory, 'man1'), ['man/openerp-server.1']))
93         files.append((opj(man_directory, 'man5'), ['man/openerp_serverrc.5']))
94
95         doc_directory = opj('share', 'doc', 'openerp-server-%s' % version)
96         files.append((doc_directory, [f for f in glob.glob('doc/*') if os.path.isfile(f)]))
97         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)]))
98         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)]))
99
100         openerp_site_packages = opj('lib', 'python%s' % py_short_version, 'site-packages', 'openerp-server')
101
102         for addon in find_addons():
103             add_path = addon.replace('.', os.path.sep).replace('openerp-server', 'bin', 1)
104             addon_path = opj('lib', 'python%s' % py_short_version, 'site-packages', add_path.replace('bin', 'openerp-server', 1))
105             pathfiles = []
106             for root, dirs, innerfiles in os.walk(add_path):
107                 innerfiles = filter(lambda file: os.path.splitext(file)[1] not in ('.pyc', '.py', '.pyd', '.pyo'), innerfiles)
108                 if innerfiles:
109                     pathfiles.extend(((opj(addon_path, root.replace('bin/addons/', '')), map(lambda file: opj(root, file), innerfiles)),))
110             files.extend(pathfiles)
111     return files
112
113 check_modules()
114
115 f = file('openerp-server','w')
116 start_script = """#!/bin/sh\necho "OpenERP Setup - The content of this file is generated at the install stage\n" """
117 f.write(start_script)
118 f.close()
119
120 class openerp_server_install(install):
121     def run(self):
122         # create startup script
123         start_script = "#!/bin/sh\ncd %s\nexec %s ./openerp-server.py $@\n" % (opj(self.install_libbase, "openerp-server"), sys.executable)
124         # write script
125         f = open('openerp-server', 'w')
126         f.write(start_script)
127         f.close()
128         install.run(self)
129
130 options = {
131     "py2exe": {
132         "compressed": 1,
133         "optimize": 2, 
134         "packages": ["lxml", "lxml.builder", "lxml._elementpath", "lxml.etree", 
135                      "lxml.objectify", "decimal", "xml", "xml.dom", "xml.xpath", 
136                      "encodings","mx.DateTime","wizard","pychart","PIL", "pyparsing", 
137                      "pydot","asyncore","asynchat", "reportlab", "vobject", "HTMLParser"],
138         "excludes" : ["Tkconstants","Tkinter","tcl"],
139     }
140 }
141
142 setup(name             = name,
143       version          = version,
144       description      = description,
145       long_description = long_desc,
146       url              = url,
147       author           = author,
148       author_email     = author_email,
149       classifiers      = filter(None, classifiers.split("\n")),
150       license          = license,
151       data_files       = data_files(),
152       cmdclass         = { 
153             'install' : openerp_server_install,
154       },
155       scripts          = ['openerp-server'],
156       packages         = ['openerp-server', 
157                           'openerp-server.addons',
158                           'openerp-server.ir',
159                           'openerp-server.osv',
160                           'openerp-server.ssl',
161                           'openerp-server.service', 
162                           'openerp-server.tools',
163                           'openerp-server.report',
164                           'openerp-server.report.printscreen',
165                           'openerp-server.report.render',
166                           'openerp-server.report.render.rml2pdf',
167                           'openerp-server.report.render.rml2html',
168                           'openerp-server.wizard', 
169                           'openerp-server.workflow'] + \
170                          list(find_addons()),
171       package_dir      = {'openerp-server': 'bin'},
172       console = [ { "script" : "bin\\openerp-server.py", "icon_resources" : [ (1,"pixmaps\\openerp-icon.ico") ] } ],
173       options = options,
174       )
175
176
177 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
178