[FIX]:reset page number when printing multiple report
[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 imp
30 import sys
31 import os
32 from os.path import join, isfile, basename
33 import glob
34
35 from setuptools import setup, find_packages
36 from setuptools.command.install import install
37 from distutils.sysconfig import get_python_lib
38
39 has_py2exe = False
40 if os.name == 'nt':
41     import py2exe
42     has_py2exe = True
43
44 sys.path.append(join(os.path.abspath(os.path.dirname(__file__)), "bin"))
45
46 execfile(join('bin', 'release.py'))
47
48 if 'bdist_rpm' in sys.argv:
49     version = version.split('-')[0]
50
51 # get python short version
52 py_short_version = '%s.%s' % sys.version_info[:2]
53
54 def find_addons():
55     for root, _, names in os.walk(join('bin', 'addons'), followlinks=True):
56         if '__openerp__.py' in names or '__terp__.py' in names:
57             yield basename(root), root
58
59 def data_files():
60     '''Build list of data files to be installed'''
61     files = []
62     if os.name == 'nt':
63         for root, _, names in os.walk(join('bin','addons')):
64             files.append((root, [join(root, name) for name in names]))
65         for root, _, names in os.walk('doc'):
66             files.append((root, [join(root, name) for name in names]))
67         files.append(('.', [join('bin', 'import_xml.rng'),
68                             join('bin', 'server.pkey'),
69                             join('bin', 'server.cert')]))
70     else:
71         man_directory = join('share', 'man')
72         files.append((join(man_directory, 'man1'), ['man/openerp-server.1']))
73         files.append((join(man_directory, 'man5'), ['man/openerp_serverrc.5']))
74
75         doc_directory = join('share', 'doc', 'openerp-server-%s' % version)
76         files.append((doc_directory, filter(isfile, glob.glob('doc/*'))))
77         files.append((join(doc_directory, 'migrate', '3.3.0-3.4.0'),
78                       filter(isfile, glob.glob('doc/migrate/3.3.0-3.4.0/*'))))
79         files.append((join(doc_directory, 'migrate', '3.4.0-4.0.0'),
80                       filter(isfile, glob.glob('doc/migrate/3.4.0-4.0.0/*'))))
81
82         openerp_site_packages = join(get_python_lib(prefix=''), 'openerp-server')
83
84         files.append((openerp_site_packages, [join('bin', 'import_xml.rng'),
85                                               join('bin', 'server.pkey'),
86                                               join('bin', 'server.cert')]))
87
88         if sys.version_info[0:2] == (2,5):
89             files.append((openerp_site_packages, [ join('python25-compat','BaseHTTPServer.py'),
90                                                    join('python25-compat','SimpleXMLRPCServer.py'),
91                                                    join('python25-compat','SocketServer.py')]))
92
93         for addonname, add_path in find_addons():
94             addon_path = join(get_python_lib(prefix=''), 'openerp-server','addons', addonname)
95             for root, dirs, innerfiles in os.walk(add_path):
96                 innerfiles = filter(lambda fil: os.path.splitext(fil)[1] not in ('.pyc', '.pyd', '.pyo'), innerfiles)
97                 if innerfiles:
98                     res = os.path.normpath(join(addon_path, root.replace(join(add_path), '.')))
99                     files.extend(((res, map(lambda fil: join(root, fil),
100                                             innerfiles)),))
101
102     return files
103
104 f = file('openerp-server','w')
105 f.write("""#!/bin/sh
106 echo "Error: the content of this file should have been replaced during "
107 echo "installation\n"
108 exit 1
109 """)
110 f.close()
111
112 def find_package_dirs():
113     package_dirs = {'openerp-server': 'bin'}
114     for mod, path in find_addons():
115         package_dirs['openerp-server.addons.' + mod] = path
116     return package_dirs
117
118 class openerp_server_install(install):
119     def run(self):
120         # create startup script
121         start_script = "#!/bin/sh\ncd %s\nexec %s ./openerp-server.py $@\n"\
122             % (join(self.install_libbase, "openerp-server"), sys.executable)
123         # write script
124         f = open('openerp-server', 'w')
125         f.write(start_script)
126         f.close()
127         install.run(self)
128
129
130
131 options = {
132     "py2exe": {
133         "compressed": 1,
134         "optimize": 2,
135         "dist_dir": 'dist',
136         "packages": [
137                  "lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
138                  "lxml.objectify", "decimal", "xml", "xml", "xml.dom", "xml.xpath",
139                  "encodings", "dateutil", "wizard", "pychart", "PIL", "pyparsing",
140                  "pydot", "asyncore","asynchat", "reportlab", "vobject",
141                  "HTMLParser", "select", "mako", "poplib",
142                  "imaplib", "smtplib", "email", "yaml","pywebdav",
143                  ],
144         "excludes" : ["Tkconstants","Tkinter","tcl"],
145     }
146 }
147
148 setup(name             = name,
149       version          = version,
150       description      = description,
151       long_description = long_desc,
152       url              = url,
153       author           = author,
154       author_email     = author_email,
155       classifiers      = filter(None, classifiers.split("\n")),
156       license          = license,
157       data_files       = data_files(),
158       cmdclass         = {
159           'install' : openerp_server_install,
160       },
161       scripts          = ['openerp-server'],
162       packages = [
163           '.'.join(['openerp-server'] + package.split('.')[1:]) for package in find_packages()
164       ],
165       package_dir      = find_package_dirs(),
166       console = [
167           {
168               "script": join("bin", "openerp-server.py"),
169               "icon_resources": [(1, join("pixmaps","openerp-icon.ico"))]
170           }
171       ],
172       options = options,
173       install_requires = ['lxml',
174                           'mako',
175                           'python-dateutil',
176                           'psycopg2',
177                           'pychart',
178                           'pydot',
179                           'pytz',
180                           'reportlab',
181                           'caldav',
182                           'pyyaml',
183                           'sqlalchemy',
184                           'django',
185                           'pywebdav'
186                           'cx_Oracle',
187                           'mysqldb',
188                           'feedparser',
189                           'bsddb3',
190                           'egenix-mx-base'],
191       extras_require={
192           'SSL' : ['pyopenssl'],
193       }
194 )
195
196 if has_py2exe:
197   # Sometime between pytz-2008a and pytz-2008i common_timezones started to
198   # include only names of zones with a corresponding data file in zoneinfo.
199   # pytz installs the zoneinfo directory tree in the same directory
200   # as the pytz/__init__.py file. These data files are loaded using
201   # pkg_resources.resource_stream. py2exe does not copy this to library.zip so
202   # resource_stream can't find the files and common_timezones is empty when
203   # read in the py2exe executable.
204   # This manually copies zoneinfo into the zip. See also
205   # http://code.google.com/p/googletransitdatafeed/issues/detail?id=121
206   import pytz
207   import zipfile
208   # Make sure the layout of pytz hasn't changed
209   assert (pytz.__file__.endswith('__init__.pyc') or
210           pytz.__file__.endswith('__init__.py')), pytz.__file__
211   zoneinfo_dir = join(os.path.dirname(pytz.__file__), 'zoneinfo')
212   # '..\\Lib\\pytz\\__init__.py' -> '..\\Lib'
213   disk_basedir = os.path.dirname(os.path.dirname(pytz.__file__))
214   zipfile_path = join(options['py2exe']['dist_dir'], 'library.zip')
215   z = zipfile.ZipFile(zipfile_path, 'a')
216   for absdir, directories, filenames in os.walk(zoneinfo_dir):
217     assert absdir.startswith(disk_basedir), (absdir, disk_basedir)
218     zip_dir = absdir[len(disk_basedir):]
219     for f in filenames:
220       z.write(join(absdir, f), join(zip_dir, f))
221   z.close()
222