Only install runenv.cli.template on NT systems
[zeroinstall/solver.git] / setup.py
blob6bc188066dd2535f8947fc240546e5788c891020
1 from distutils.core import setup
2 from distutils.util import convert_path
3 from distutils.core import Command
4 from distutils.command.build_py import build_py
5 from distutils.command.install import install
6 from distutils.command.install_lib import install_lib
7 from distutils.command.install_data import install_data
8 import os, subprocess, sys
9 import glob
10 import zeroinstall
12 class adjust_scripts_for_home(Command):
13 """setup.py install --home puts libraries in ~/lib/python, but Python doesn't look there.
14 If we're installing with --home, modify the scripts to add this to sys.path.
15 Don't do this otherwise; the system copy mustn't conflict with the copy in $HOME.
16 """
17 description = "(used internally when using --home)"
19 user_options = [
20 ('scripts-dir=', 'd', "directory to install scripts to"),
21 ('lib-dir=', 'd', "directory libraries install to"),
24 def initialize_options (self):
25 self.scripts_dir = None
26 self.lib_dir = None
28 def finalize_options (self):
29 self.set_undefined_options('install',
30 ('install_scripts', 'scripts_dir'),
31 ('install_lib', 'lib_dir'),
34 def run(self):
35 for script in self.distribution.scripts:
36 outfile = os.path.join(self.scripts_dir, os.path.basename(script))
38 stream = open(outfile)
39 code = stream.read()
40 stream.close()
42 code = code.replace('## PATH ##', '''
43 import os, sys
44 sys.path.insert(0, %s)''' % repr(self.lib_dir))
45 stream = open(outfile, 'w')
46 stream.write(code)
47 stream.close()
49 class build_with_data(build_py):
50 """Python < 2.4 doesn't support package_data_files, so add it manually."""
51 package_data_files = [
52 "zeroinstall/0launch-gui/0launch-gui",
53 "zeroinstall/0launch-gui/zero-install.ui",
54 "zeroinstall/gtkui/desktop.ui",
55 "zeroinstall/gtkui/cache.ui",
56 "zeroinstall/injector/EquifaxSecureCA.crt",
57 "zeroinstall/zerostore/_unlzma",
60 if os.name == "nt":
61 package_data_files.append("zeroinstall/injector/runenv.cli.template")
63 def run(self):
64 # Copy .py files and build, as usual
65 build_py.run(self)
66 # Copy data files
67 for data_file in self.package_data_files:
68 outfile = os.path.join(self.build_lib, data_file)
69 self.copy_file(data_file, outfile, preserve_mode=0)
70 executable = (os.stat(data_file).st_mode & 0o111) != 0
71 if executable:
72 os.chmod(outfile, os.stat(outfile).st_mode | 0o111)
74 class install_lib_exec(install_lib):
75 def run(self):
76 install_lib.run(self) # super.run()
77 if os.name != 'posix': return
79 launch = os.path.join(self.install_dir, 'zeroinstall/0launch-gui/0launch-gui')
80 os.chmod(launch, os.stat(launch).st_mode | 0o111)
82 class install_data_locale(install_data):
83 def run(self):
84 self.data_files.extend(self._compile_po_files())
85 install_data.run(self) # super.run()
87 def _compile_po_files(self):
88 i18nfiles = []
89 mo_pattern = "share/locale/*/LC_MESSAGES/zero-install.mo"
90 mo_files = glob.glob(mo_pattern)
91 if not mo_files:
92 print("No translations (Git checkout?)... trying to build them...")
93 subprocess.check_call(["make", "translations"])
94 mo_files = glob.glob(mo_pattern)
95 assert mo_files
96 for mo in mo_files:
97 dest = os.path.dirname(mo)
98 i18nfiles.append((dest, [mo]))
99 return i18nfiles
101 # distutils doesn't seem to have any support for adding configuration files.
102 # Unfortunately, the freedesktop.org menu spec strangely defines part of the
103 # menu definitions as configuration.
104 class my_install(install):
105 def finalize_options(self):
106 install.finalize_options(self) # super.finalize_options()
107 if self.home:
108 self.__config_dir = os.path.join(self.home, '.config')
109 elif self.prefix == '/usr':
110 self.__config_dir = os.path.join(self.root or '/', 'etc/xdg')
111 else:
112 self.__config_dir = os.path.join(self.root or '/', self.prefix[1:], 'etc/xdg')
114 def run(self):
115 install.run(self) # super.run()
116 menus_dir = os.path.join(self.__config_dir, 'menus/applications-merged')
117 self.mkpath(menus_dir)
118 menu = convert_path('share/applications/zeroinstall.menu')
119 self.copy_file(menu, menus_dir)
121 if self.home:
122 self.run_command('adjust_scripts_for_home')
124 setup(name="zeroinstall-injector",
125 version=zeroinstall.version,
126 description="The Zero Install Injector (0launch)",
127 author="Thomas Leonard",
128 author_email="zero-install-devel@lists.sourceforge.net",
129 url="http://0install.net",
130 scripts=['0launch', '0alias', '0store', '0store-secure-add', '0desktop', '0install'],
131 data_files = [('man/man1', ['0launch.1', '0alias.1', '0store-secure-add.1', '0store.1', '0desktop.1', '0install.1']),
132 ('share/applications', ['share/applications/zeroinstall-add.desktop', 'share/applications/zeroinstall-manage.desktop']),
133 ('share/desktop-directories', ['share/desktop-directories/zeroinstall.directory']),
134 ('share/icons/hicolor/24x24/apps', ['share/icons/24x24/zeroinstall.png']),
135 ('share/icons/hicolor/48x48/apps', ['share/icons/48x48/zeroinstall.png']),
136 ('share/icons/hicolor/128x128/apps', ['share/icons/128x128/zeroinstall.png']),
137 ('share/icons/hicolor/scalable/apps', ['share/icons/scalable/zeroinstall.svg'])],
138 license='LGPL',
139 cmdclass={
140 'build_py': build_with_data,
141 'install_lib': install_lib_exec,
142 'install_data': install_data_locale,
143 'adjust_scripts_for_home': adjust_scripts_for_home,
144 'install': my_install,
146 long_description="""\
147 A running process is created by combining many different libraries (and other
148 components). In the Zero Install world, we have all versions of each library
149 available at all times. The problem then is how to choose which versions to
150 use.
152 The injector solves this problem by selecting components to meet a program's
153 requirements, according to a policy you give it. The injector finds out which
154 versions are available, and downloads and runs the ones you choose.""",
155 packages=["zeroinstall", "zeroinstall.support", "zeroinstall.zerostore", "zeroinstall.injector", "zeroinstall.0launch-gui", "zeroinstall.gtkui", "zeroinstall.cmd"])