Launchpad automatic translations update.
[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-2010 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 sys
30 import os
31 from os.path import join, isfile, basename
32 import glob
33
34 from pprint import pprint as pp
35
36 from setuptools import setup, find_packages
37 from setuptools.command.install import install
38 from distutils.sysconfig import get_python_lib
39
40 has_py2exe = False
41 py2exe_keywords = {}
42 if os.name == 'nt':
43     import py2exe
44     has_py2exe = True
45     py2exe_keywords['console'] = [
46         { "script": join("bin", "openerp-server.py"),
47           "icon_resources": [(1, join("pixmaps","openerp-icon.ico"))]
48         }]
49     py2exe_keywords['options'] = {
50         "py2exe": {
51             "compressed": 1,
52             "optimize": 2,
53             "dist_dir": 'dist',
54             "packages": [
55                 "lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
56                 "lxml.objectify", "decimal", "xml", "xml", "xml.dom", "xml.xpath",
57                 "encodings", "dateutil", "wizard", "pychart", "PIL", "pyparsing",
58                 "pydot", "asyncore","asynchat", "reportlab", "vobject",
59                 "HTMLParser", "select", "mako", "poplib",
60                 "imaplib", "smtplib", "email", "yaml", "DAV",
61                 "uuid", "commands",
62             ],
63             "excludes" : ["Tkconstants","Tkinter","tcl"],
64         }
65     }
66
67 sys.path.append(join(os.path.abspath(os.path.dirname(__file__)), "bin"))
68
69 execfile(join('bin', 'release.py'))
70
71 if 'bdist_rpm' in sys.argv:
72     version = version.split('-')[0]
73
74 # get python short version
75 py_short_version = '%s.%s' % sys.version_info[:2]
76
77 # backports os.walk with followlinks from python 2.6
78 def walk_followlinks(top, topdown=True, onerror=None, followlinks=False):
79     from os.path import join, isdir, islink
80     from os import listdir, error
81
82     try:
83         names = listdir(top)
84     except error, err:
85         if onerror is not None:
86             onerror(err)
87         return
88
89     dirs, nondirs = [], []
90     for name in names:
91         if isdir(join(top, name)):
92             dirs.append(name)
93         else:
94             nondirs.append(name)
95
96     if topdown:
97         yield top, dirs, nondirs
98     for name in dirs:
99         path = join(top, name)
100         if followlinks or not islink(path):
101             for x in walk_followlinks(path, topdown, onerror, followlinks):
102                 yield x
103     if not topdown:
104         yield top, dirs, nondirs
105
106 if sys.version_info < (2, 6):
107     os.walk = walk_followlinks
108
109 def find_addons():
110     for root, _, names in os.walk(join('bin', 'addons'), followlinks=True):
111         if '__openerp__.py' in names or '__terp__.py' in names:
112             yield basename(root), root
113     #look for extra modules
114     try:
115         empath = os.getenv('EXTRA_MODULES_PATH', '../addons/')
116         for mname in open(join(empath, 'server_modules.list')):
117             mname = mname.strip()
118             if not mname:
119                 continue
120
121             terp = join(empath, mname, '__openerp__.py')
122             if not os.path.exists(terp):
123                 terp = join(empath, mname, '__terp__.py')
124
125             if os.path.exists(terp):
126                 yield mname, join(empath, mname)
127             else:
128                 print "Module %s specified, but no valid path." % mname
129     except Exception:
130         pass
131
132 def data_files():
133     '''Build list of data files to be installed'''
134     files = []
135     if os.name == 'nt':
136         os.chdir('bin')
137         for (dp, dn, names) in os.walk('addons'):
138             files.append((dp, map(lambda x: join('bin', dp, x), names)))
139         os.chdir('..')
140         #for root, _, names in os.walk(join('bin','addons')):
141         #    files.append((root, [join(root, name) for name in names]))
142         for root, _, names in os.walk('doc'):
143             files.append((root, [join(root, name) for name in names]))
144         #for root, _, names in os.walk('pixmaps'):
145         #    files.append((root, [join(root, name) for name in names]))
146         files.append(('.', [join('bin', 'import_xml.rng'),]))
147     else:
148         man_directory = join('share', 'man')
149         files.append((join(man_directory, 'man1'), ['man/openerp-server.1']))
150         files.append((join(man_directory, 'man5'), ['man/openerp_serverrc.5']))
151
152         doc_directory = join('share', 'doc', 'openerp-server-%s' % version)
153         files.append((doc_directory, filter(isfile, glob.glob('doc/*'))))
154         files.append((join(doc_directory, 'migrate', '3.3.0-3.4.0'),
155                       filter(isfile, glob.glob('doc/migrate/3.3.0-3.4.0/*'))))
156         files.append((join(doc_directory, 'migrate', '3.4.0-4.0.0'),
157                       filter(isfile, glob.glob('doc/migrate/3.4.0-4.0.0/*'))))
158
159         openerp_site_packages = join(get_python_lib(prefix=''), 'openerp-server')
160
161         files.append((openerp_site_packages, [join('bin', 'import_xml.rng'),]))
162
163         if sys.version_info[0:2] == (2,5):
164             files.append((openerp_site_packages, [ join('python25-compat','BaseHTTPServer.py'),
165                                                    join('python25-compat','SimpleXMLRPCServer.py'),
166                                                    join('python25-compat','SocketServer.py')]))
167
168         for addonname, add_path in find_addons():
169             addon_path = join(get_python_lib(prefix=''), 'openerp-server','addons', addonname)
170             for root, dirs, innerfiles in os.walk(add_path):
171                 innerfiles = filter(lambda fil: os.path.splitext(fil)[1] not in ('.pyc', '.pyd', '.pyo'), innerfiles)
172                 if innerfiles:
173                     res = os.path.normpath(join(addon_path, root.replace(join(add_path), '.')))
174                     files.extend(((res, map(lambda fil: join(root, fil),
175                                             innerfiles)),))
176
177     return files
178
179 f = file('openerp-server','w')
180 f.write("""#!/bin/sh
181 echo "Error: the content of this file should have been replaced during "
182 echo "installation\n"
183 exit 1
184 """)
185 f.close()
186
187 def find_package_dirs():
188     package_dirs = {'openerp-server': 'bin'}
189     for mod, path in find_addons():
190         package_dirs['openerp-server.addons.' + mod] = path
191     return package_dirs
192
193 class openerp_server_install(install):
194     def run(self):
195         # create startup script
196         start_script = "#!/bin/sh\ncd %s\nexec %s ./openerp-server.py $@\n"\
197             % (join(self.install_libbase, "openerp-server"), sys.executable)
198         # write script
199         f = open('openerp-server', 'w')
200         f.write(start_script)
201         f.close()
202         install.run(self)
203
204
205
206
207 setup(name             = name,
208       version          = version,
209       description      = description,
210       long_description = long_desc,
211       url              = url,
212       author           = author,
213       author_email     = author_email,
214       classifiers      = filter(None, classifiers.split("\n")),
215       license          = license,
216       data_files       = data_files(),
217       cmdclass         = {
218           'install' : openerp_server_install,
219       },
220       scripts          = ['openerp-server'],
221       packages = [
222           '.'.join(['openerp-server'] + package.split('.')[1:])
223           for package in find_packages()
224       ],
225       include_package_data = True,
226       package_data = {
227           '': ['*.yml', '*.xml', '*.po', '*.pot', '*.csv'],
228       },
229       package_dir      = find_package_dirs(),
230       install_requires = [
231           'lxml',
232           'mako',
233           'python-dateutil',
234           'psycopg2',
235           'pychart',
236           'pydot',
237           'pytz',
238           'reportlab',
239           'caldav',
240           'pyyaml',
241           'pywebdav',
242           'feedparser',
243       ],
244       extras_require={
245           'SSL' : ['pyopenssl'],
246       },
247       **py2exe_keywords
248 )
249
250 if has_py2exe:
251     # Sometime between pytz-2008a and pytz-2008i common_timezones started to
252     # include only names of zones with a corresponding data file in zoneinfo.
253     # pytz installs the zoneinfo directory tree in the same directory
254     # as the pytz/__init__.py file. These data files are loaded using
255     # pkg_resources.resource_stream. py2exe does not copy this to library.zip so
256     # resource_stream can't find the files and common_timezones is empty when
257     # read in the py2exe executable.
258     # This manually copies zoneinfo into the zip. See also
259     # http://code.google.com/p/googletransitdatafeed/issues/detail?id=121
260     import pytz
261     import zipfile
262     # Make sure the layout of pytz hasn't changed
263     assert (pytz.__file__.endswith('__init__.pyc') or
264             pytz.__file__.endswith('__init__.py')), pytz.__file__
265     zoneinfo_dir = os.path.join(os.path.dirname(pytz.__file__), 'zoneinfo')
266     # '..\\Lib\\pytz\\__init__.py' -> '..\\Lib'
267     disk_basedir = os.path.dirname(os.path.dirname(pytz.__file__))
268     zipfile_path = os.path.join(py2exe_keywords['options']['py2exe']['dist_dir'], 'library.zip')
269     z = zipfile.ZipFile(zipfile_path, 'a')
270
271     for absdir, directories, filenames in os.walk(zoneinfo_dir):
272         assert absdir.startswith(disk_basedir), (absdir, disk_basedir)
273         zip_dir = absdir[len(disk_basedir):]
274         for f in filenames:
275             z.write(os.path.join(absdir, f), os.path.join(zip_dir, f))
276
277     z.close()