[IMP] crm,report_crm: Fix the probelm probability aand add the company_id in all...
[odoo/odoo.git] / setup.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 ##############################################################################
4 #    
5 #    OpenERP, Open Source Management Solution
6 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU Affero General Public License as
10 #    published by the Free Software Foundation, either version 3 of the
11 #    License, or (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU Affero General Public License for more details.
17 #
18 #    You should have received a copy of the GNU Affero General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
20 #
21 ##############################################################################
22
23 # setup from TinERP
24 #   taken from straw http://www.nongnu.org/straw/index.html
25 #   taken from gnomolicious http://www.nongnu.org/gnomolicious/
26 #   adapted by Nicolas Évrard <nicoe@altern.org>
27 #
28
29 import imp
30 import sys
31 import os
32 import glob
33
34 from distutils.core import setup, Command
35 from distutils.command.install import install
36
37 has_py2exe = False
38 if os.name == 'nt':
39     import py2exe
40     has_py2exe = True
41
42 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), "bin"))
43
44 opj = os.path.join
45
46 execfile(opj('bin', 'release.py'))
47
48 if sys.argv[1] == 'bdist_rpm':
49     version = version.split('-')[0]
50
51 # get python short version
52 py_short_version = '%s.%s' % sys.version_info[:2]
53
54 required_modules = [
55     ('psycopg2', 'PostgreSQL module'),
56     ('xml', 'XML Tools for python'),
57     ('libxml2', 'libxml2 python bindings'),
58     ('libxslt', 'libxslt python bindings'),
59     ('reportlab', 'reportlab module'),
60     ('pychart', 'pychart module'),
61     ('pydot', 'pydot module'),
62 ]
63
64 def check_modules():
65     ok = True
66     for modname, desc in required_modules:
67         try:
68             exec('import %s' % modname)
69         except ImportError:
70             ok = False
71             print 'Error: python module %s (%s) is required' % (modname, desc)
72
73     if not ok:
74         sys.exit(1)
75
76 def find_addons():
77     for (dp, dn, names) in os.walk(opj('bin', 'addons')):
78         if '__terp__.py' in names:
79             modname = dp.replace(os.path.sep, '.').replace('bin', 'openerp-server', 1)
80             yield modname
81
82 def data_files():
83     '''Build list of data files to be installed'''
84     files = []
85     if os.name == 'nt':
86         os.chdir('bin')
87         for (dp,dn,names) in os.walk('addons'):
88             files.append((dp, map(lambda x: opj('bin', dp, x), names)))
89         os.chdir('..')
90         for (dp,dn,names) in os.walk('doc'):
91             files.append((dp, map(lambda x: opj(dp, x), names)))
92         files.append(('.', [opj('bin', 'import_xml.rng'),
93                             opj('bin', 'server.pkey'),
94                             opj('bin', 'server.cert')]))
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, [opj('bin', 'import_xml.rng'),
108                                               opj('bin', 'server.pkey'),
109                                               opj('bin', 'server.cert')]))
110
111         for addon in find_addons():
112             addonname = addon.split('.')[-1]
113             add_path = addon.replace('.', os.path.sep).replace('openerp-server', 'bin', 1)
114             addon_path = opj('lib', 'python%s' % py_short_version, 'site-packages', add_path.replace('bin', 'openerp-server', 1))
115             pathfiles = []
116             for root, dirs, innerfiles in os.walk(add_path):
117                 innerfiles = filter(lambda file: os.path.splitext(file)[1] not in ('.pyc', '.pyd', '.pyo'), innerfiles)
118                 if innerfiles:
119                     res = os.path.normpath(opj(addon_path, root.replace(opj('bin','addons', addonname), '.')))
120                     pathfiles.extend(((res, map(lambda file: opj(root, file), innerfiles)),))
121             files.extend(pathfiles)
122
123     return files
124
125 check_modules()
126
127 f = file('openerp-server','w')
128 start_script = """#!/bin/sh\necho "OpenERP Setup - The content of this file is generated at the install stage\n" """
129 f.write(start_script)
130 f.close()
131
132 class openerp_server_install(install):
133     def run(self):
134         # create startup script
135         start_script = "#!/bin/sh\ncd %s\nexec %s ./openerp-server.py $@\n" % (opj(self.install_libbase, "openerp-server"), sys.executable)
136         # write script
137         f = open('openerp-server', 'w')
138         f.write(start_script)
139         f.close()
140         install.run(self)
141
142 options = {
143     "py2exe": {
144         "compressed": 1,
145         "optimize": 2,
146         "dist_dir": 'dist',
147         "packages": ["lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
148                      "lxml.objectify", "decimal", "xml", "xml.dom", "xml.xpath",
149                      "encodings","mx.DateTime","wizard","pychart","PIL", "pyparsing",
150                      "pydot","asyncore","asynchat", "reportlab", "vobject",
151                      "HTMLParser", "select"],
152         "excludes" : ["Tkconstants","Tkinter","tcl"],
153     }
154 }
155
156 setup(name             = name,
157       version          = version,
158       description      = description,
159       long_description = long_desc,
160       url              = url,
161       author           = author,
162       author_email     = author_email,
163       classifiers      = filter(None, classifiers.split("\n")),
164       license          = license,
165       data_files       = data_files(),
166       cmdclass         = {
167             'install' : openerp_server_install,
168       },
169       scripts          = ['openerp-server'],
170       packages         = ['openerp-server',
171                           'openerp-server.addons',
172                           'openerp-server.ir',
173                           'openerp-server.osv',
174                           'openerp-server.service',
175                           'openerp-server.tools',
176                           'openerp-server.report',
177                           'openerp-server.report.printscreen',
178                           'openerp-server.report.pyPdf',
179                           'openerp-server.report.render',
180                           'openerp-server.report.render.rml2pdf',
181                           'openerp-server.report.render.rml2html',
182                           'openerp-server.wizard',
183                           'openerp-server.report.render.odt2odt',
184                           'openerp-server.report.render.html2html',
185                           'openerp-server.workflow'] + \
186                          list(find_addons()),
187       package_dir      = {'openerp-server': 'bin'},
188       console = [ { "script" : "bin\\openerp-server.py", "icon_resources" : [ (1,"pixmaps\\openerp-icon.ico") ] } ],
189       options = options,
190       )
191
192 if has_py2exe:
193   # Sometime between pytz-2008a and pytz-2008i common_timezones started to
194   # include only names of zones with a corresponding data file in zoneinfo.
195   # pytz installs the zoneinfo directory tree in the same directory
196   # as the pytz/__init__.py file. These data files are loaded using
197   # pkg_resources.resource_stream. py2exe does not copy this to library.zip so
198   # resource_stream can't find the files and common_timezones is empty when
199   # read in the py2exe executable.
200   # This manually copies zoneinfo into the zip. See also
201   # http://code.google.com/p/googletransitdatafeed/issues/detail?id=121
202   import pytz
203   import zipfile
204   # Make sure the layout of pytz hasn't changed
205   assert (pytz.__file__.endswith('__init__.pyc') or
206           pytz.__file__.endswith('__init__.py')), pytz.__file__
207   zoneinfo_dir = os.path.join(os.path.dirname(pytz.__file__), 'zoneinfo')
208   # '..\\Lib\\pytz\\__init__.py' -> '..\\Lib'
209   disk_basedir = os.path.dirname(os.path.dirname(pytz.__file__))
210   zipfile_path = os.path.join(options['py2exe']['dist_dir'], 'library.zip')
211   z = zipfile.ZipFile(zipfile_path, 'a')
212   for absdir, directories, filenames in os.walk(zoneinfo_dir):
213     assert absdir.startswith(disk_basedir), (absdir, disk_basedir)
214     zip_dir = absdir[len(disk_basedir):]
215     for f in filenames:
216       z.write(os.path.join(absdir, f), os.path.join(zip_dir, f))
217   z.close()
218