1
# GNU Enterprise Common Library - Installation Helper For Packages
3
# This file is part of GNU Enterprise.
5
# GNU Enterprise is free software; you can redistribute it
6
# and/or modify it under the terms of the GNU General Public
7
# License as published by the Free Software Foundation; either
8
# version 2, or (at your option) any later version.
10
# GNU Enterprise is distributed in the hope that it will be
11
# useful, but WITHOUT ANY WARRANTY; without even the implied
12
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
# PURPOSE. See the GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public
16
# License along with program; see the file COPYING. If not,
17
# write to the Free Software Foundation, Inc., 59 Temple Place
18
# - Suite 330, Boston, MA 02111-1307, USA.
20
# Copyright 2001-2005 Free Software Foundation
22
# $Id: GSetup.py,v 1.4 2003/10/06 18:33:16 reinhard Exp $
27
from distutils.core import setup
28
import distutils.command.sdist
29
import distutils.command.build
30
import distutils.command.install
32
from gnue.common.setup import ChangeLog
34
# -----------------------------------------------------------------------------
35
# Check Python version
36
# -----------------------------------------------------------------------------
39
if sys.hexversion < 0x02000000:
41
except AttributeError:
44
You are running Python %s.
46
GNU Enterprise requires at least Python 2.0 (recommended: 2.1+).
47
If you have a later version installed, you should run setup.py
48
against that version. For example, if you have Python 2.2
49
installed, you may need to run:
52
""" % string.split(sys.version)[0]
56
# -----------------------------------------------------------------------------
57
# Global GSetup instance
58
# -----------------------------------------------------------------------------
62
# =============================================================================
63
# sdist: build files to be distributed first
64
# =============================================================================
66
class sdist (distutils.command.sdist.sdist):
71
_setup.do_build_files ('sdist')
72
distutils.command.sdist.sdist.run (self)
74
# =============================================================================
75
# build: if done from SVN, build files to be installed first
76
# =============================================================================
78
class build (distutils.command.build.build):
83
if not os.path.isfile ("PKG-INFO"): # downloaded from SVN?
84
_setup.do_build_files ('build')
85
distutils.command.build.build.run (self)
87
# =============================================================================
88
# install: Some user_options are no longer allowed
89
# =============================================================================
91
class install (distutils.command.install.install):
93
user_options = distutils.command.install.install.user_options
95
allowed_options = ["root=", "compile", "no-compile", "optimize=", "force",
96
"skip-build", "record="]
98
user_options = [opt for opt in user_options if opt [0] in allowed_options]
100
# ---------------------------------------------------------------------------
101
# Finalize options - set all install targets
102
# ---------------------------------------------------------------------------
104
def finalize_options (self):
105
self.install_lib = gnue.paths.lib
106
self.install_scripts = gnue.paths.scripts
107
self.install_data = gnue.paths.data
108
self.install_config = gnue.paths.config
110
distutils.command.install.install.finalize_options (self)
112
# ---------------------------------------------------------------------------
113
# install.run: generate and install path dependent files afterwards
114
# ---------------------------------------------------------------------------
119
_setup.check_dependencies ()
123
# install translations
124
if os.path.isdir ('po'):
128
for f in os.listdir ('po'):
129
if f [-4:] == '.pot':
133
print "warning: cannot determine domain, not installing translations"
136
for f in os.listdir ('po'):
137
if f [-4:] == '.gmo':
138
src = os.path.join ('po', f)
139
dst = os.path.join (self.install_data, 'share', 'locale', f [:-4],
142
dst = os.path.join (dst, domain + '.mo')
143
self.copy_file (src, dst)
144
self.__outputs.append (dst)
146
distutils.command.install.install.run (self)
148
# ---------------------------------------------------------------------------
149
# install.get_outputs: list all installed files
150
# ---------------------------------------------------------------------------
152
def get_outputs (self):
153
return distutils.command.install.install.get_outputs (self) \
156
# =============================================================================
157
# GSetup: Basic class for setup scripts of GNUe packages
158
# =============================================================================
162
# ---------------------------------------------------------------------------
163
# Abstract methods: setup.py scripts generally override these
164
# ---------------------------------------------------------------------------
166
def set_params (self, params):
169
def build_files (self, action):
172
def check_dependencies (self):
175
# ---------------------------------------------------------------------------
176
# Build files if called from SVN
177
# ---------------------------------------------------------------------------
179
def do_build_files (self, action):
181
if os.name == 'posix':
183
# First check if we have everything installed we need to build the
186
if os.path.isdir ('po'):
188
if os.system ("pygettext --version > /dev/null") != 0:
189
print "Could not find 'pygettext'. Strange."
190
print "It should be included in the Python distribution."
194
if os.system ("msgmerge --version > /dev/null") != 0:
195
print "Could not find 'msgmerge'. Please install Gettext."
199
if os.system ("msgfmt --version > /dev/null") != 0:
200
print "Could not find 'msgfmt'. Please install Gettext."
203
# -----------------------------------------------------------------------
205
if action == 'sdist':
206
# build ChangeLog file
207
print 'building ChangeLog'
211
if os.path.isdir ('po'):
212
print "building translations"
213
if os.system ("cd po && make gmo") != 0:
217
# on non posix systems just run msgfmt on existing .po files
218
if os.path.isdir ('po'):
220
argv0_path = os.path.dirname(os.path.abspath(sys.executable))
221
sys.path.append(argv0_path + "\\tools\\i18n")
231
# pygettext.py exist in Python, but no msgmerge, so
232
# just create a placeholder...
233
potfile = open('po/'+ self.package +'.pot', 'w')
234
potfile.write("#placeholder")
238
print "building translations"
239
for f in os.listdir('po'):
242
msgfmt.make ('po/'+f, 'po/'+f[:-3]+'.gmo')
245
# -------------------------------------------------------------------------
247
# do package specific stuff
248
self.build_files (action)
250
# ---------------------------------------------------------------------------
251
# Helper methods for descendants
252
# ---------------------------------------------------------------------------
254
def allfiles (self, directory):
255
directory = os.path.normpath (directory)
256
exclude = [".svn", "CVS", "README.cvs", ".cvsignore", "Makefile"]
257
return [directory + "/" + file for file in os.listdir (directory) \
258
if not file in exclude and
259
not os.path.isdir (os.path.join (directory, file))]
261
# ---------------------------------------------------------------------------
262
# Get all packages in a directory
263
# ---------------------------------------------------------------------------
265
def __get_packages (self, directory, package):
266
content = os.listdir (directory)
268
if "__init__.py" in content:
271
fullname = os.path.join (directory, name)
272
if os.path.isdir (fullname):
273
result = result + self.__get_packages (fullname, package + "." + name)
276
# ---------------------------------------------------------------------------
277
# Call the actual setup routine
278
# ---------------------------------------------------------------------------
283
# set global variable
286
setup_params = {"cmdclass_sdist": sdist,
287
"cmdclass_build": build,
288
"cmdclass_install": install,
289
"suffix_var" : 'GNUE_VERSION_SUFFIX'
292
_setup.set_params (setup_params)
294
# handle version suffix
296
suffix = os.environ[setup_params['suffix_var']]
301
# find out all packages
302
if not setup_params.has_key ("packages"):
304
for module, directory in setup_params["package_dir"].items ():
305
packages = packages + self.__get_packages (directory, module)
306
setup_params ["packages"] = packages
308
# remove data files that are not available
309
for target, files in setup_params ["data_files"]:
311
while i < len (files):
313
if os.path.isfile (file):
316
print "warning: did not find file %s" % file
320
setup (name = setup_params ["name"],
321
version = setup_params ["version"] + suffix,
322
description = setup_params ["description"],
323
long_description = setup_params ["long_description"],
324
author = setup_params ["author"],
325
author_email = setup_params ["author_email"],
326
url = setup_params ["url"],
327
license = setup_params ["license"],
328
packages = setup_params ["packages"],
329
package_dir = setup_params ["package_dir"],
330
scripts = setup_params ["scripts"],
331
data_files = setup_params ["data_files"],
333
# Override certain command classes with our own ones
334
cmdclass = {"sdist": setup_params["cmdclass_sdist"],
335
"build": setup_params["cmdclass_build"],
336
"install": setup_params["cmdclass_install"]})