setup.py revision 409
0N/A#!/usr/bin/python2.4
20N/A#
20N/A# CDDL HEADER START
20N/A#
20N/A# The contents of this file are subject to the terms of the
20N/A# Common Development and Distribution License (the "License").
20N/A# You may not use this file except in compliance with the License.
20N/A#
20N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
20N/A# or http://www.opensolaris.org/os/licensing.
20N/A# See the License for the specific language governing permissions
20N/A# and limitations under the License.
20N/A#
20N/A# When distributing Covered Code, include this CDDL HEADER in each
20N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
20N/A# If applicable, add the following below this CDDL HEADER, with the
20N/A# fields enclosed by brackets "[]" replaced with your own identifying
20N/A# information: Portions Copyright [yyyy] [name of copyright owner]
20N/A#
20N/A# CDDL HEADER END
20N/A#
20N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
20N/A# Use is subject to license terms.
20N/A#
20N/A
22N/Aimport os
0N/Aimport stat
50N/Aimport sys
50N/Aimport platform
50N/Aimport shutil
50N/Aimport re
50N/Aimport subprocess
50N/Aimport tarfile
50N/Aimport tempfile
50N/Aimport urllib
50N/A
50N/Afrom distutils.core import setup, Extension
50N/Afrom distutils.cmd import Command
50N/Afrom distutils.command.install import install as _install
50N/Afrom distutils.command.build import build as _build
50N/Afrom distutils.command.build_py import build_py as _build_py
50N/Afrom distutils.command.bdist import bdist as _bdist
50N/Afrom distutils.command.clean import clean as _clean
0N/A
55N/Afrom distutils.sysconfig import get_python_inc
54N/Aimport distutils.file_util as file_util
26N/Aimport distutils.dir_util as dir_util
0N/Aimport distutils.util as util
0N/A
0N/Apwd = os.path.normpath(sys.path[0])
0N/A
52N/Aosname = platform.uname()[0].lower()
0N/Aostype = arch = 'unknown'
22N/Aif osname == 'sunos':
119N/A arch = platform.processor()
119N/A ostype = "posix"
145N/Aelif osname == 'linux':
0N/A arch = "linux_" + platform.machine()
34N/A ostype = "posix"
22N/Aelif osname == 'windows':
22N/A arch = osname
46N/A ostype = "windows"
34N/Aelif osname == 'darwin':
22N/A arch = osname
22N/A ostype = "posix"
114N/A
26N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
23N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
23N/Aroot_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
26N/A
26N/Apy_install_dir = 'usr/lib/python2.4/vendor-packages'
135N/A
135N/Ascripts_dir = 'usr/bin'
26N/Alib_dir = 'usr/lib'
135N/A
14N/Aman1_dir = 'usr/share/man/cat1'
145N/Aman1m_dir = 'usr/share/man/cat1m'
145N/Aman5_dir = 'usr/share/man/cat5'
145N/Aresource_dir = 'usr/share/lib/pkg'
145N/Asmf_dir = 'var/svc/manifest/application'
145N/Azones_dir = 'etc/zones'
145N/Abrand_dir = 'usr/lib/brand/ipkg'
145N/A
145N/Ascripts_sunos = {
145N/A scripts_dir: [
145N/A ['client.py', 'pkg'],
145N/A ['publish.py', 'pkgsend'],
30N/A ['pull.py', 'pkgrecv'],
14N/A ],
0N/A lib_dir: [
25N/A ['depot.py', 'pkg.depotd'],
0N/A ],
26N/A }
26N/A
145N/Ascripts_windows = {
30N/A scripts_dir: [
50N/A ['client.py', 'client.py'],
50N/A ['publish.py', 'publish.py'],
50N/A ['pull.py', 'pull.py'],
30N/A ['scripts/pkg.bat', 'pkg.bat'],
30N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
30N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
30N/A ],
146N/A lib_dir: [
30N/A ['depot.py', 'depot.py'],
50N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
45N/A ],
30N/A }
50N/A
45N/Ascripts_other_unix = {
30N/A scripts_dir: [
30N/A ['client.py', 'client.py'],
30N/A ['pull.py', 'pull.py'],
30N/A ['publish.py', 'publish.py'],
45N/A ['scripts/pkg.sh', 'pkg'],
30N/A ['scripts/pkgsend.sh', 'pkgsend'],
145N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
119N/A ],
119N/A lib_dir: [
119N/A ['depot.py', 'depot.py'],
119N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
119N/A ],
119N/A }
119N/A
119N/A# indexed by 'osname'
119N/Ascripts = {
119N/A "sunos": scripts_sunos,
119N/A "linux": scripts_other_unix,
119N/A "windows": scripts_windows,
119N/A "darwin": scripts_other_unix,
119N/A "unknown": scripts_sunos,
119N/A }
119N/A
119N/Aman1_files = [
119N/A 'man/pkg.1.txt',
119N/A 'man/pkgsend.1.txt',
119N/A 'man/pkgrecv.1.txt',
119N/A ]
119N/Aman1m_files = [
119N/A 'man/pkg.depotd.1m.txt'
119N/A ]
119N/Aman5_files = [
119N/A 'man/pkg.5.txt'
119N/A ]
119N/Apackages = [
119N/A 'pkg',
119N/A 'pkg.actions',
119N/A 'pkg.bundle',
145N/A 'pkg.client',
30N/A 'pkg.portable',
30N/A 'pkg.publish',
30N/A 'pkg.server',
146N/A ]
30N/Aweb_files = [
54N/A 'web/pkg-block-icon.png',
119N/A 'web/pkg-block-logo.png',
119N/A 'web/pkg.css',
54N/A 'web/robots.txt',
54N/A ]
54N/Azones_files = [
54N/A 'brand/SUNWipkg.xml',
54N/A ]
54N/Abrand_files = [
54N/A 'brand/config.xml',
30N/A 'brand/platform.xml',
30N/A 'brand/pkgcreatezone',
30N/A ]
30N/Asmf_files = [
30N/A 'pkg-server.xml',
30N/A ]
0N/Aelf_srcs = [
145N/A 'modules/elf.c',
22N/A 'modules/elfextract.c',
22N/A 'modules/liblist.c',
135N/A ]
135N/Aarch_srcs = [
135N/A 'modules/arch.c'
135N/A ]
22N/Ainclude_dirs = [ 'modules' ]
22N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
22N/A
22N/A# Runs lint on the extension module source code
26N/Aclass lint_func(Command):
0N/A description = "Runs various lint tools over IPS extension source code"
22N/A user_options = []
22N/A
22N/A def initialize_options(self):
22N/A pass
22N/A
22N/A def finalize_options(self):
22N/A pass
22N/A
0N/A # Make string shell-friendly
0N/A @staticmethod
145N/A def escape(astring):
135N/A return astring.replace(' ', '\\ ')
135N/A
135N/A def run(self):
135N/A # assumes lint is on the $PATH
0N/A if osname == 'sunos' or osname == "linux":
146N/A archcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
0N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
22N/A ['-I' + self.escape(get_python_inc())] + \
26N/A arch_srcs
22N/A elfcmd = ['lint'] + lint_flags + \
26N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
22N/A ['-I' + self.escape(get_python_inc())] + \
145N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
135N/A elf_srcs
135N/A
135N/A print(" ".join(archcmd))
135N/A os.system(" ".join(archcmd))
22N/A print(" ".join(elfcmd))
146N/A os.system(" ".join(elfcmd))
22N/A
26N/A proto = os.path.join(root_dir, py_install_dir)
22N/A sys.path.insert(0, proto)
26N/A
0N/A # Insert tests directory onto sys.path so any custom checkers
145N/A # can be found.
135N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
135N/A print(sys.path)
135N/A
135N/A # assumes pylint is accessible on the sys.path
146N/A from pylint import lint
0N/A scriptlist = [ 'setup.py' ]
26N/A for d, m in scripts_sunos.items():
22N/A for a in m:
0N/A # specify the filenames of the scripts, in addition
20N/A # to the package names themselves
34N/A scriptlist.append(os.path.join(root_dir, d, a[1]))
21N/A
34N/A # For some reason, the load-plugins option, when used in the
0N/A # rcfile, does not work, so we put it here instead, to load
145N/A # our custom checkers.
145N/A lint.Run(['--load-plugins=multiplatform', '--rcfile',
145N/A os.path.join(pwd, 'tests', 'pylintrc')] +
145N/A scriptlist + packages)
145N/A
145N/Aclass install_func(_install):
145N/A def initialize_options(self):
145N/A _install.initialize_options(self)
145N/A # It's OK to have /'s here, python figures it out when writing files
145N/A self.install_purelib = py_install_dir
145N/A self.install_platlib = py_install_dir
145N/A self.root = root_dir
145N/A self.prefix = '.'
145N/A
145N/A def run(self):
145N/A """
145N/A At the end of the install function, we need to rename some files
145N/A because distutils provides no way to rename files as they are
0N/A placed in their install locations.
0N/A Also, make sure that cherrypy is installed.
0N/A """
145N/A _install.run(self)
145N/A if ostype == 'posix':
145N/A # only rename manpages if building for unix-derived OS
145N/A for (d, files) in [(man1_dir, man1_files), (man1m_dir,
145N/A man1m_files), (man5_dir, man5_files)]:
145N/A for f in files:
145N/A src = util.change_root(self.root,
145N/A os.path.join(d, os.path.basename(f)))
145N/A if src.endswith('.txt'):
26N/A dst = src[:-4]
145N/A os.rename(src, dst)
145N/A
145N/A for d, files in scripts[osname].iteritems():
145N/A for (srcname, dstname) in files:
145N/A dst_dir = util.change_root(self.root, d)
145N/A dst_path = util.change_root(self.root,
145N/A os.path.join(d, dstname))
145N/A dir_util.mkpath(dst_dir, verbose = True)
145N/A file_util.copy_file(srcname, dst_path, update = True)
145N/A # make scripts executable
145N/A os.chmod(dst_path,
145N/A os.stat(dst_path).st_mode | stat.S_IEXEC)
145N/A
145N/A install_cherrypy()
145N/A
26N/ACP = 'CherryPy'
145N/ACPVER = '3.0.3'
145N/ACPARC = '%s-%s.tar.gz' % (CP, CPVER)
145N/ACPDIR = '%s-%s' % (CP, CPVER)
145N/ACPURL = 'http://download.cherrypy.org/cherrypy/%s/%s' % (CPVER, CPARC)
145N/Adef install_cherrypy():
145N/A if not os.path.exists(CPARC):
145N/A print "downloading CherryPy"
145N/A try:
145N/A fname, hdr = urllib.urlretrieve(CPURL, CPARC)
145N/A except IOError:
145N/A pass
145N/A if not os.path.exists(CPARC) or \
145N/A hdr.gettype() != "application/x-gzip":
145N/A print "Unable to retrieve %s.\nPlease retrieve the file " \
145N/A "and place it at: %s\n" % (CPURL, CPARC)
145N/A # remove a partial download or error message from proxy
145N/A remove_cherrypy()
145N/A sys.exit(1)
145N/A if not os.path.exists(CPDIR):
145N/A print "unpacking CherryPy"
145N/A tar = tarfile.open(CPARC)
145N/A # extractall doesn't exist until python 2.5
0N/A for m in tar.getmembers():
0N/A tar.extract(m)
0N/A tar.close()
25N/A cherrypy_dir = os.path.join(root_dir, py_install_dir, "cherrypy")
0N/A if not os.path.exists(cherrypy_dir):
30N/A print "installing CherryPy"
30N/A subprocess.Popen(['python', 'setup.py', 'install',
0N/A '--install-lib=%s' % os.path.join(root_dir, py_install_dir),
0N/A '--install-data=%s' % os.path.join(root_dir, py_install_dir)],
0N/A cwd = CPDIR).wait()
25N/A
0N/Adef remove_cherrypy():
30N/A if os.path.exists(CPARC):
30N/A os.unlink(CPARC)
0N/A shutil.rmtree(CPDIR, True)
55N/A
55N/Aclass build_func(_build):
55N/A def initialize_options(self):
55N/A _build.initialize_options(self)
145N/A self.build_base = build_dir
145N/A
22N/Adef get_hg_version():
135N/A try:
135N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
135N/A return p.communicate()[0].strip()
135N/A except OSError:
135N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
135N/A return "unknown"
135N/A
135N/Aclass build_py_func(_build_py):
135N/A # override the build_module method to do VERSION substitution on pkg/__init__.py
135N/A def build_module (self, module, module_file, package):
135N/A if module == "__init__" and package == "pkg":
135N/A mcontent = file(module_file).read()
135N/A v = 'VERSION = "%s"' % get_hg_version()
135N/A mcontent = re.sub('(?m)^VERSION[^"]*"([^"]*)"', v, mcontent)
135N/A tmpfd, tmp_file = tempfile.mkstemp()
135N/A os.write(tmpfd, mcontent)
135N/A os.close(tmpfd)
22N/A print "doing version substitution: ", v
26N/A rv = _build_py.build_module(self, module, tmp_file, package)
26N/A os.unlink(tmp_file)
26N/A return rv
145N/A return _build_py.build_module(self, module, module_file, package)
145N/A
82N/Aclass clean_func(_clean):
22N/A def initialize_options(self):
_clean.initialize_options(self)
self.build_base = build_dir
class clobber_func(Command):
user_options = []
description = "Deletes any and all files created by setup"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# nuke everything
print("deleting " + dist_dir)
shutil.rmtree(dist_dir, True)
print("deleting " + build_dir)
shutil.rmtree(build_dir, True)
print("deleting " + root_dir)
shutil.rmtree(root_dir, True)
print("deleting cherrypy")
remove_cherrypy()
class test_func(Command):
user_options = []
description = "Runs unit and functional tests"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
os.putenv('PYEXE', sys.executable)
os.chdir(os.path.join(pwd, "tests"))
testlogfd, testlogpath = tempfile.mkstemp(suffix = '.pkg-test.log')
testlogfp = os.fdopen(testlogfd, "w")
print "logging to %s" % testlogpath
subprocess.call([sys.executable, "api-complete.py"],
stdout = testlogfp)
if ostype == 'posix':
subprocess.call([sys.executable, "cli-complete.py"],
stdout = testlogfp)
if osname == 'sunos':
subprocess.call(["/bin/ksh", "memleaks.ksh"],
stdout = testlogfp)
testlogfp.close()
class dist_func(_bdist):
def initialize_options(self):
_bdist.initialize_options(self)
self.dist_dir = dist_dir
# These are set to real values based on the platform, down below
ext_modules = None
compile_args = None
link_args = None
elf_libraries = None
data_files = [ (resource_dir, web_files) ]
cmdclasses = {
'install': install_func,
'build': build_func,
'build_py': build_py_func,
'bdist': dist_func,
'lint': lint_func,
'clean': clean_func,
'clobber': clobber_func,
'test': test_func,
}
# all builds of IPS should have manpages
data_files += [
(man1_dir, man1_files),
(man1m_dir, man1m_files),
(man5_dir, man5_files),
]
if osname == 'sunos':
# Solaris-specific extensions are added here
data_files += [
(zones_dir, zones_files),
(brand_dir, brand_files),
(smf_dir, smf_files),
]
if osname == 'sunos' or osname == "linux":
# Unix platforms which the elf extension has been ported to
# are specified here, so they are built automatically
elf_libraries = ['elf']
ext_modules = [
Extension(
'elf',
elf_srcs,
include_dirs = include_dirs,
libraries = elf_libraries,
extra_compile_args = compile_args,
extra_link_args = link_args
),
]
# Solaris has built-in md library and Solaris-specific arch extension
# All others use OpenSSL and cross-platform arch module
if osname == 'sunos':
elf_libraries += [ 'md' ]
ext_modules += [
Extension(
'arch',
arch_srcs,
include_dirs = include_dirs,
extra_compile_args = compile_args,
extra_link_args = link_args,
define_macros = [('_FILE_OFFSET_BITS', '64')]
),
]
else:
elf_libraries += [ 'ssl' ]
setup(cmdclass = cmdclasses,
name = 'ips',
version = '1.0',
package_dir = {'pkg':'modules'},
packages = packages,
data_files = data_files,
ext_package = 'pkg',
ext_modules = ext_modules,
)