Files
tryton/setup.py
T

402 lines
15 KiB
Python
Raw Normal View History

2008-02-19 17:55:24 +01:00
#!/usr/bin/env python
2008-09-30 10:19:09 +02:00
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
2008-02-19 17:55:24 +01:00
2008-09-30 10:19:09 +02:00
from setuptools import setup, find_packages
2008-02-19 17:55:24 +01:00
import os
2008-06-13 14:19:51 +02:00
import glob
import sys
2011-11-22 13:15:45 -05:00
import re
2008-06-13 14:19:51 +02:00
2012-04-03 20:04:58 +02:00
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
2008-06-13 14:19:51 +02:00
args = {}
2008-07-04 00:06:56 +02:00
try:
from babel.messages import frontend as babel
args['cmdclass'] = {
'compile_catalog': babel.compile_catalog,
'extract_messages': babel.extract_messages,
'init_catalog': babel.init_catalog,
'update_catalog': babel.update_catalog,
}
args['message_extractors'] = {
'tryton': [
('**.py', 'python', None),
],
}
except ImportError:
pass
languages = (
'bg_BG',
'ca_ES',
'cs_CZ',
'de_DE',
2012-04-20 17:08:49 -03:00
'es_AR',
'es_CO',
'es_ES',
'fr_FR',
'ja_JP',
'lt_LT',
'nl_NL',
'ru_RU',
'sl_SI',
)
2012-04-03 20:04:58 +02:00
def all_languages():
for lang in languages:
yield lang
yield lang.split('_')[0]
2012-04-03 20:04:58 +02:00
data_files = [
('share/pixmaps/tryton', glob.glob('share/pixmaps/tryton/*.png') + \
glob.glob('share/pixmaps/tryton/*.svg')),
]
for lang in languages:
data_files += [
('share/locale/%s/LC_MESSAGES' % lang,
glob.glob('share/locale/%s/LC_MESSAGES/*.mo')),
]
2008-06-13 14:19:51 +02:00
if os.name == 'nt':
import py2exe
2008-06-13 14:19:51 +02:00
args['windows'] = [{
'script': os.path.join('bin', 'tryton'),
2012-04-03 20:04:58 +02:00
'icon_resources': [
(1, os.path.join('share', 'pixmaps', 'tryton', 'tryton.ico'))],
2008-06-13 14:19:51 +02:00
}]
args['options'] = {
'py2exe': {
'optimize': 0,
2012-04-03 20:04:58 +02:00
'bundle_files': 3, # don't bundle because gtk doesn't support it
2008-06-13 14:19:51 +02:00
'packages': [
'encodings',
'gtk',
'pytz',
'atk',
'pango',
'pangocairo',
2011-04-06 20:18:07 +02:00
'gio',
2008-06-13 14:19:51 +02:00
],
}
}
2009-11-06 20:27:51 +01:00
args['zipfile'] = 'library.zip'
2011-07-12 23:51:23 +02:00
data_files.append(('', ['msvcr90.dll', 'msvcp90.dll', 'msvcm90.dll']))
manifest = read('Microsoft.VC90.CRT.manifest')
args['windows'][0]['other_resources'] = [(24, 1, manifest)]
2011-11-23 20:42:04 -05:00
elif sys.platform == 'darwin':
2009-04-10 01:00:45 +02:00
import py2app
2009-05-30 13:31:35 +02:00
from modulegraph.find_modules import PY_SUFFIXES
PY_SUFFIXES.append('')
args['app'] = [os.path.join('bin', 'tryton')]
2009-04-10 01:00:45 +02:00
args['options'] = {
'py2app': {
'argv_emulation': True,
'includes': 'pygtk, gtk, glib, cairo, pango, pangocairo, atk, ' \
'gobject, gio, gtk.keysyms',
2009-04-10 01:26:24 +02:00
'resources': 'tryton/plugins',
2009-04-11 18:58:39 +02:00
'frameworks': 'librsvg-2.2.dylib',
2009-04-10 01:00:45 +02:00
'plist': {
'CFBundleIdentifier': 'org.tryton',
'CFBundleName': 'Tryton',
2009-04-10 01:00:45 +02:00
},
'iconfile': os.path.join('share', 'pixmaps', 'tryton',
'tryton.icns'),
},
}
2008-02-19 17:55:24 +01:00
execfile(os.path.join('tryton', 'version.py'))
2012-02-12 17:40:02 +01:00
WEAKREF = []
if sys.version_info < (2, 7):
WEAKREF = ['weakrefset']
dist = setup(name=PACKAGE,
2008-02-19 17:55:24 +01:00
version=VERSION,
description='Tryton client',
2011-02-15 16:10:11 +01:00
long_description=read('README'),
2008-02-19 17:55:24 +01:00
author='B2CK',
author_email='info@b2ck.com',
url=WEBSITE,
2008-12-01 13:29:18 +01:00
download_url="http://downloads.tryton.org/" + \
VERSION.rsplit('.', 1)[0] + '/',
2008-09-30 10:19:09 +02:00
packages=find_packages(),
data_files=data_files,
scripts=['bin/tryton'],
2008-02-19 17:55:24 +01:00
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: X11 Applications :: GTK',
2011-09-29 23:26:08 +02:00
'Framework :: Tryton',
2008-02-19 17:55:24 +01:00
'Intended Audience :: End Users/Desktop',
2008-11-17 14:48:11 +01:00
'License :: OSI Approved :: GNU General Public License (GPL)',
2011-04-26 18:39:09 +02:00
'Natural Language :: Bulgarian',
'Natural Language :: Catalan',
2011-10-24 01:09:10 +02:00
'Natural Language :: Czech',
2011-04-26 18:39:09 +02:00
'Natural Language :: Dutch',
2008-10-15 00:40:15 +02:00
'Natural Language :: English',
'Natural Language :: French',
'Natural Language :: German',
2010-04-12 07:45:48 +02:00
'Natural Language :: Russian',
2008-10-15 00:40:15 +02:00
'Natural Language :: Spanish',
'Natural Language :: Slovak',
'Natural Language :: Slovenian',
'Natural Language :: Japanese',
2011-04-26 18:39:09 +02:00
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
2008-02-19 17:55:24 +01:00
'Topic :: Office/Business',
],
license=LICENSE,
2008-09-30 10:19:09 +02:00
install_requires=[
# "pygtk >= 2.6",
"python-dateutil",
2012-02-12 17:40:02 +01:00
] + WEAKREF,
extras_require={
'timezone': ['pytz'],
2011-10-14 09:58:00 +02:00
'simplejson': ['simplejson'],
2012-01-04 19:55:24 +01:00
'cdecimal': ['cdecimal'],
},
2008-06-13 14:19:51 +02:00
**args
2008-02-19 17:55:24 +01:00
)
if os.name == 'nt':
def find_gtk_dir():
for directory in os.environ['PATH'].split(';'):
if not os.path.isdir(directory):
continue
for file in ('gtk-demo.exe', 'gdk-pixbuf-query-loaders.exe'):
if os.path.isfile(os.path.join(directory, file)):
return os.path.dirname(directory)
return None
2009-05-30 19:03:42 +02:00
def find_makensis():
for directory in os.environ['PATH'].split(';'):
if not os.path.isdir(directory):
continue
path = os.path.join(directory, 'makensis.exe')
if os.path.isfile(path):
return path
return None
if 'py2exe' in dist.commands:
import shutil
2009-11-06 20:27:51 +01:00
import pytz
import zipfile
gtk_dir = find_gtk_dir()
dist_dir = dist.command_obj['py2exe'].dist_dir
2009-11-06 20:27:51 +01:00
# pytz installs the zoneinfo directory tree in the same directory
# Make sure the layout of pytz hasn't changed
assert (pytz.__file__.endswith('__init__.pyc') or
pytz.__file__.endswith('__init__.py')), pytz.__file__
zoneinfo_dir = os.path.join(os.path.dirname(pytz.__file__), 'zoneinfo')
disk_basedir = os.path.dirname(os.path.dirname(pytz.__file__))
zipfile_path = os.path.join(dist_dir, 'library.zip')
z = zipfile.ZipFile(zipfile_path, 'a')
for absdir, directories, filenames in os.walk(zoneinfo_dir):
assert absdir.startswith(disk_basedir), (absdir, disk_basedir)
zip_dir = absdir[len(disk_basedir):]
for f in filenames:
z.write(os.path.join(absdir, f), os.path.join(zip_dir, f))
z.close()
if os.path.isdir(os.path.join(dist_dir, 'plugins')):
shutil.rmtree(os.path.join(dist_dir, 'plugins'))
2012-04-03 20:04:58 +02:00
shutil.copytree(os.path.join(os.path.dirname(__file__), 'tryton',
'plugins'), os.path.join(dist_dir, 'plugins'))
if os.path.isdir(os.path.join(dist_dir, 'etc')):
shutil.rmtree(os.path.join(dist_dir, 'etc'))
shutil.copytree(os.path.join(gtk_dir, 'etc'),
os.path.join(dist_dir, 'etc'))
2009-10-18 18:57:39 +02:00
from subprocess import Popen, PIPE
2012-04-03 20:04:58 +02:00
query_loaders = Popen(os.path.join(gtk_dir, 'bin',
'gdk-pixbuf-query-loaders'), stdout=PIPE).stdout.read()
query_loaders = query_loaders.replace(
gtk_dir.replace(os.sep, '/') + '/', '')
2011-06-07 20:03:04 +02:00
loaders_path = os.path.join(dist_dir, 'etc', 'gtk-2.0',
'gdk-pixbuf.loaders')
with open(loaders_path, 'w') as loaders:
loaders.writelines([line + "\n" for line in
query_loaders.split(os.linesep)])
2009-10-18 18:57:39 +02:00
if os.path.isdir(os.path.join(dist_dir, 'lib')):
shutil.rmtree(os.path.join(dist_dir, 'lib'))
shutil.copytree(os.path.join(gtk_dir, 'lib'),
os.path.join(dist_dir, 'lib'))
2009-10-18 18:56:21 +02:00
for file in glob.iglob(os.path.join(gtk_dir, 'bin', '*.dll')):
if os.path.isfile(file):
shutil.copy(file, dist_dir)
for lang in all_languages():
if os.path.isdir(os.path.join(dist_dir, 'share', 'locale', lang)):
shutil.rmtree(os.path.join(dist_dir, 'share', 'locale', lang))
shutil.copytree(os.path.join(gtk_dir, 'share', 'locale', lang),
os.path.join(dist_dir, 'share', 'locale', lang))
2012-04-03 20:04:58 +02:00
if os.path.isdir(os.path.join(dist_dir, 'share', 'themes',
'MS-Windows')):
shutil.rmtree(os.path.join(dist_dir, 'share', 'themes',
'MS-Windows'))
shutil.copytree(os.path.join(gtk_dir, 'share', 'themes', 'MS-Windows'),
os.path.join(dist_dir, 'share', 'themes', 'MS-Windows'))
2009-05-30 19:03:42 +02:00
makensis = find_makensis()
if makensis:
from subprocess import Popen
Popen([makensis, "/DVERSION=" + VERSION,
str(os.path.join(os.path.dirname(__file__),
'setup.nsi'))]).wait()
Popen([makensis, "/DVERSION=" + VERSION,
str(os.path.join(os.path.dirname(__file__),
'setup-single.nsi'))]).wait()
2011-11-23 20:42:04 -05:00
elif sys.platform == 'darwin':
2012-04-03 20:04:58 +02:00
def find_gtk_dir():
for directory in os.environ['PATH'].split(':'):
if not os.path.isdir(directory):
continue
for file in ('gtk-demo',):
if os.path.isfile(os.path.join(directory, file)):
return os.path.dirname(directory)
return None
if 'py2app' in dist.commands:
import shutil
from subprocess import Popen, PIPE
from itertools import chain
from glob import iglob
gtk_dir = find_gtk_dir()
2012-04-03 20:04:58 +02:00
gtk_binary_version = Popen(['pkg-config',
'--variable=gtk_binary_version', 'gtk+-2.0'],
stdout=PIPE).stdout.read().strip()
dist_dir = dist.command_obj['py2app'].dist_dir
2012-04-03 20:04:58 +02:00
resources_dir = os.path.join(dist_dir, 'Tryton.app', 'Contents',
'Resources')
2009-07-23 17:07:20 +02:00
gtk_2_dist_dir = os.path.join(resources_dir, 'lib', 'gtk-2.0')
pango_dist_dir = os.path.join(resources_dir, 'lib', 'pango')
if os.path.isdir(pango_dist_dir):
shutil.rmtree(pango_dist_dir)
shutil.copytree(os.path.join(gtk_dir, 'lib', 'pango'), pango_dist_dir)
2009-07-23 17:07:20 +02:00
query_pango = Popen(os.path.join(gtk_dir, 'bin', 'pango-querymodules'),
stdout=PIPE).stdout.read()
2012-04-03 20:04:58 +02:00
query_pango = query_pango.replace(gtk_dir,
'@executable_path/../Resources')
2011-06-07 20:03:04 +02:00
pango_modules_path = os.path.join(resources_dir, 'pango.modules')
with open(pango_modules_path, 'w') as pango_modules:
pango_modules.write(query_pango)
2011-06-07 20:03:04 +02:00
with open(os.path.join(resources_dir, 'pangorc'), 'w') as pangorc:
pangorc.write('[Pango]\n')
pangorc.write('ModuleFiles=./pango.modules\n')
2012-04-03 20:04:58 +02:00
if not os.path.isdir(os.path.join(gtk_2_dist_dir, gtk_binary_version,
'engines')):
os.makedirs(os.path.join(gtk_2_dist_dir, gtk_binary_version,
'engines'))
shutil.copyfile(os.path.join(gtk_dir, 'lib', 'gtk-2.0',
gtk_binary_version, 'engines', 'libclearlooks.so'),
os.path.join(gtk_2_dist_dir, gtk_binary_version, 'engines',
'libclearlooks.so'))
2012-04-03 20:04:58 +02:00
query_loaders = Popen(os.path.join(gtk_dir, 'bin',
'gdk-pixbuf-query-loaders'), stdout=PIPE).stdout.read()
2011-11-22 13:15:45 -05:00
loader_dir, = re.findall('# LoaderDir = (.*)', query_loaders)
2012-04-03 20:04:58 +02:00
loader_pkg = (loader_dir.replace(os.path.join(gtk_dir, 'lib'),
'').split(os.path.sep)[-3])
2011-11-22 13:15:45 -05:00
loader_dist_dir = os.path.join(resources_dir, 'lib', loader_pkg,
gtk_binary_version, 'loaders')
if os.path.isdir(loader_dist_dir):
shutil.rmtree(loader_dist_dir)
if os.path.isdir(loader_dir):
shutil.copytree(loader_dir, loader_dist_dir)
2012-04-03 20:04:58 +02:00
query_loaders = query_loaders.replace(gtk_dir,
'@executable_path/../Resources')
2011-06-07 20:03:04 +02:00
loaders_path = os.path.join(resources_dir, 'gdk-pixbuf.loaders')
with open(loaders_path, 'w') as loaders:
loaders.write(query_loaders)
2009-07-23 17:07:20 +02:00
2012-04-03 20:04:58 +02:00
if os.path.isdir(os.path.join(gtk_2_dist_dir, gtk_binary_version,
'immodules')):
shutil.rmtree(os.path.join(gtk_2_dist_dir, gtk_binary_version,
'immodules'))
shutil.copytree(os.path.join(gtk_dir, 'lib', 'gtk-2.0',
gtk_binary_version, 'immodules'), os.path.join(gtk_2_dist_dir,
gtk_binary_version, 'immodules'))
2012-04-03 20:04:58 +02:00
query_immodules = Popen(os.path.join(gtk_dir, 'bin',
'gtk-query-immodules-2.0'), stdout=PIPE).stdout.read()
query_immodules = query_immodules.replace(gtk_dir,
'@executable_path/../Resources')
2011-06-07 20:03:04 +02:00
immodules_path = os.path.join(resources_dir, 'gtk.immodules')
with open(immodules_path, 'w') as immodules:
immodules.write(query_immodules)
2009-07-23 17:07:20 +02:00
shutil.copy(os.path.join(gtk_dir, 'share', 'themes', 'Clearlooks',
'gtk-2.0', 'gtkrc'), os.path.join(resources_dir, 'gtkrc'))
for lang in all_languages():
2012-04-03 20:04:58 +02:00
if os.path.isdir(os.path.join(resources_dir, 'share', 'locale',
lang)):
shutil.rmtree(os.path.join(resources_dir, 'share', 'locale',
lang))
shutil.copytree(os.path.join(gtk_dir, 'share', 'locale', lang),
os.path.join(resources_dir, 'share', 'locale', lang))
# fix pathes within shared libraries
for library in chain(
2011-11-22 13:15:45 -05:00
iglob(os.path.join(loader_dist_dir, '*.so')),
2012-04-03 20:04:58 +02:00
iglob(os.path.join(gtk_2_dist_dir, gtk_binary_version,
'engines', '*.so')),
iglob(os.path.join(gtk_2_dist_dir, gtk_binary_version,
'immodules', '*.so')),
iglob(os.path.join(pango_dist_dir, '*', 'modules', '*.so'))):
libs = [lib.split('(')[0].strip()
for lib in Popen(['otool', '-L', library],
stdout=PIPE).communicate()[0].splitlines()
if 'compatibility' in lib]
libs = dict(((lib, None) for lib in libs if gtk_dir in lib))
for lib in libs.keys():
fixed = lib.replace(gtk_dir + '/lib',
'@executable_path/../Frameworks')
2009-07-23 17:07:20 +02:00
Popen(['install_name_tool', '-change', lib, fixed,
library]).wait()
for file in ('CHANGELOG', 'COPYRIGHT', 'LICENSE', 'README', 'TODO'):
shutil.copyfile(os.path.join(os.path.dirname(__file__), file),
os.path.join(dist_dir, file + '.txt'))
doc_dist_dir = os.path.join(dist_dir, 'doc')
if os.path.isdir(doc_dist_dir):
shutil.rmtree(doc_dist_dir)
shutil.copytree(os.path.join(os.path.dirname(__file__), 'doc'),
2009-07-23 17:07:20 +02:00
doc_dist_dir)
2009-07-23 17:07:20 +02:00
dmg_file = os.path.join(os.path.dirname(__file__), 'tryton-' + VERSION
+ '.dmg')
if os.path.isfile(dmg_file):
os.remove(dmg_file)
Popen(['hdiutil', 'create', dmg_file, '-volname', 'Tryton Client ' +
VERSION, '-fs', 'HFS+', '-srcfolder', dist_dir]).wait()