setup.py revision 2180
409N/A#!/usr/bin/python2.6
290N/A#
290N/A# CDDL HEADER START
290N/A#
290N/A# The contents of this file are subject to the terms of the
290N/A# Common Development and Distribution License (the "License").
290N/A# You may not use this file except in compliance with the License.
290N/A#
290N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
290N/A# or http://www.opensolaris.org/os/licensing.
290N/A# See the License for the specific language governing permissions
290N/A# and limitations under the License.
290N/A#
290N/A# When distributing Covered Code, include this CDDL HEADER in each
290N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
290N/A# If applicable, add the following below this CDDL HEADER, with the
290N/A# fields enclosed by brackets "[]" replaced with your own identifying
290N/A# information: Portions Copyright [yyyy] [name of copyright owner]
290N/A#
290N/A# CDDL HEADER END
290N/A#
395N/A# Copyright (c) 2008, 2010 Oracle and/or its affiliates. All rights reserved.
395N/A#
395N/A
290N/Aimport errno
454N/Aimport fnmatch
290N/Aimport os
448N/Aimport platform
290N/Aimport stat
290N/Aimport sys
290N/Aimport shutil
383N/Aimport re
290N/Aimport subprocess
395N/Aimport tarfile
290N/Aimport tempfile
395N/Aimport urllib
290N/Aimport py_compile
290N/Aimport hashlib
290N/A
290N/Afrom distutils.errors import DistutilsError
290N/Afrom distutils.core import setup, Extension
383N/Afrom distutils.cmd import Command
290N/Afrom distutils.command.install import install as _install
290N/Afrom distutils.command.build import build as _build
290N/Afrom distutils.command.build_py import build_py as _build_py
290N/Afrom distutils.command.bdist import bdist as _bdist
290N/Afrom distutils.command.clean import clean as _clean
290N/A
290N/Afrom distutils.sysconfig import get_python_inc
290N/Aimport distutils.file_util as file_util
465N/Aimport distutils.dir_util as dir_util
465N/Aimport distutils.util as util
465N/A
465N/Aosname = platform.uname()[0].lower()
465N/Aostype = arch = 'unknown'
465N/Aif osname == 'sunos':
465N/A arch = platform.processor()
465N/A ostype = "posix"
465N/Aelif osname == 'linux':
465N/A arch = "linux_" + platform.machine()
465N/A ostype = "posix"
465N/Aelif osname == 'windows':
465N/A arch = osname
465N/A ostype = "windows"
465N/Aelif osname == 'darwin':
708N/A arch = osname
708N/A ostype = "posix"
708N/Aelif osname == 'aix':
708N/A arch = "aix"
708N/A ostype = "posix"
708N/A
708N/A# 3rd party software required for the build
290N/ACP = 'CherryPy'
290N/ACPIDIR = 'cherrypy'
290N/ACPVER = '3.1.2'
395N/ACPARC = '%s-%s.tar.gz' % (CP, CPVER)
395N/ACPDIR = '%s-%s' % (CP, CPVER)
290N/ACPURL = 'http://download.cherrypy.org/cherrypy/%s/%s' % (CPVER, CPARC)
395N/ACPHASH = 'a94aedfd0e675858dbcc32dd250c23d285ee9b88'
395N/A
290N/APO = 'pyOpenSSL'
395N/APOIDIR = 'OpenSSL'
395N/APOVER = '0.7'
290N/APOARC = '%s-%s.tar.gz' % (PO, POVER)
395N/APODIR = '%s-%s' % (PO, POVER)
395N/APOURL = 'http://downloads.sourceforge.net/pyopenssl/%s' % (POARC)
290N/APOHASH = 'bd072fef8eb36241852d25a9161282a051f0a63e'
448N/A
448N/ACOV = 'coveragepy'
534N/ACOVIDIR = 'coverage'
534N/ACOVVER = '3.2b2'
534N/ACOVPVER = '3.2'
534N/ACOVARC = '%s-%s.tar.gz' % (COVIDIR, COVVER)
534N/ACOVDIR = '%s-%s' % (COVIDIR, COVVER)
534N/ACOVURL = 'http://pypi.python.org/packages/source/c/coverage/%s' % COVARC
534N/ACOVHASH = '4710d033b8c6de1efaa562243e5b29e0a31fb8b9'
290N/A
290N/ALDTP = 'ldtp'
290N/ALDTPIDIR = 'ldtp'
534N/ALDTPVER = '1.7.1'
290N/ALDTPMINORVER = '1.7.x'
290N/ALDTPMAJORVER = '1.x'
290N/ALDTPARC = '%s-%s.tar.gz' % (LDTP, LDTPVER)
290N/ALDTPDIR = '%s-%s' % (LDTP, LDTPVER)
290N/ALDTPURL = 'http://download.freedesktop.org/ldtp/%s/%s/%s' % \
661N/A (LDTPMAJORVER, LDTPMINORVER, LDTPARC)
290N/ALDTPHASH = 'd31213d2b1449a0dadcace723b9ff7041169f7ce'
290N/A
290N/AMAKO = 'Mako'
395N/AMAKOIDIR = 'mako'
290N/AMAKOVER = '0.2.2'
290N/AMAKOARC = '%s-%s.tar.gz' % (MAKO, MAKOVER)
290N/AMAKODIR = '%s-%s' % (MAKO, MAKOVER)
290N/AMAKOURL = 'http://www.makotemplates.org/downloads/%s' % (MAKOARC)
290N/AMAKOHASH = '85c04ab3a6a26a1cab47067449712d15a8b29790'
395N/A
430N/APLY = 'ply'
395N/APLYIDIR = 'ply'
395N/APLYVER = '3.1'
395N/APLYARC = '%s-%s.tar.gz' % (PLY, PLYVER)
424N/APLYDIR = '%s-%s' % (PLY, PLYVER)
578N/APLYURL = 'http://www.dabeaz.com/ply/%s' % (PLYARC)
395N/APLYHASH = '38efe9e03bc39d40ee73fa566eb9c1975f1a8003'
395N/A
395N/APBJ = 'pybonjour'
578N/APBJIDIR = 'pybonjour'
395N/APBJVER = '1.1.1'
661N/APBJARC = '%s-%s.tar.gz' % (PBJ, PBJVER)
661N/APBJDIR = '%s-%s' % (PBJ, PBJVER)
661N/APBJURL = 'http://pybonjour.googlecode.com/files/%s' % (PBJARC)
395N/APBJHASH = '92cabd14e04c5f62ce067c47c2057ee3d424d29b'
290N/A
290N/APC = 'pycurl'
395N/APCIDIR = 'curl'
395N/APCVER = '7.19.0'
395N/APCPVER= '7.19.0.1'
395N/APCARC = '%s-%s.tar.gz' % (PC, PCVER)
395N/APCDIR = '%s-%s' % (PC, PCVER)
395N/APCURL = 'http://pycurl.sourceforge.net/download/%s' % PCARC
395N/APCHASH = '3fb59eca1461331bb9e9e8d6fe3b23eda961a416'
395N/APCENVIRON = {}
395N/Aif osname in ("sunos", "linux", "darwin"):
395N/A PCENVIRON = {'CFLAGS': '-O3'}
395N/A
395N/AM2C = 'M2Crypto'
395N/AM2CIDIR = 'm2crypto'
290N/AM2CVER = '0.20.2'
290N/AM2CARC = '%s-%s.tar.gz' % (M2C, M2CVER)
395N/AM2CDIR = '%s-%s' % (M2C, M2CVER)
395N/AM2CURL = 'http://pypi.python.org/packages/source/M/M2Crypto/%s' % (M2CARC)
395N/AM2CHASH = '6e85d7035971c353db74a497fca0ec2eaea4dea0'
395N/A
395N/Apwd = os.path.normpath(sys.path[0])
395N/A
395N/A#
395N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
395N/A# is properly interleaved with output from this program.
395N/A#
395N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
395N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
395N/A
290N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
290N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
430N/Aif "ROOT" in os.environ and os.environ["ROOT"] != "":
395N/A root_dir = os.environ["ROOT"]
395N/Aelse:
395N/A root_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
395N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
395N/Aextern_dir = os.path.normpath(os.path.join(pwd, "extern"))
395N/A
290N/Apy_install_dir = 'usr/lib/python2.6/vendor-packages'
395N/A
413N/Ascripts_dir = 'usr/bin'
413N/Alib_dir = 'usr/lib'
413N/Asvc_method_dir = 'lib/svc/method'
395N/A
395N/Aman1_dir = 'usr/share/man/cat1'
413N/Aman1m_dir = 'usr/share/man/cat1m'
395N/Aman5_dir = 'usr/share/man/cat5'
395N/Aresource_dir = 'usr/share/lib/pkg'
413N/Asmf_dir = 'lib/svc/manifest/application'
395N/Azones_dir = 'etc/zones'
395N/Aetcbrand_dir = 'etc/brand/ipkg'
395N/Abrand_dir = 'usr/lib/brand/ipkg'
395N/Aexecattrd_dir = 'etc/security/exec_attr.d'
395N/Aauthattrd_dir = 'etc/security/auth_attr.d'
395N/A
395N/A# A list of source, destination tuples of modules which should be hardlinked
395N/A# together if the os supports it and otherwise copied.
424N/Ahardlink_modules = [
395N/A ("%s/pkg/flavor/depthlimitedmf24" % py_install_dir,
395N/A "%s/pkg/flavor/depthlimitedmf25" % py_install_dir)
395N/A]
395N/A
395N/Ascripts_sunos = {
451N/A scripts_dir: [
395N/A ['client.py', 'pkg'],
395N/A ['pkgdep.py', 'pkgdepend'],
395N/A ['pkgrepo.py', 'pkgrepo'],
395N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
395N/A ['util/publish/pkgfmt.py', 'pkgfmt'],
395N/A ['util/publish/pkglint.py', 'pkglint'],
395N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
395N/A ['publish.py', 'pkgsend'],
395N/A ['pull.py', 'pkgrecv'],
395N/A ['sign.py', 'pkgsign'],
395N/A ['packagemanager.py', 'packagemanager'],
395N/A ['updatemanager.py', 'pm-updatemanager'],
578N/A ],
395N/A lib_dir: [
691N/A ['depot.py', 'pkg.depotd'],
691N/A ['checkforupdates.py', 'pm-checkforupdates'],
691N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
395N/A ['launch.py', 'pm-launch'],
395N/A ],
395N/A svc_method_dir: [
395N/A ['svc/svc-pkg-depot', 'svc-pkg-depot'],
395N/A ['svc/svc-pkg-mdns', 'svc-pkg-mdns'],
290N/A ],
395N/A }
395N/A
591N/Ascripts_windows = {
591N/A scripts_dir: [
591N/A ['client.py', 'client.py'],
395N/A ['pkgrepo.py', 'pkgrepo.py'],
395N/A ['publish.py', 'publish.py'],
290N/A ['pull.py', 'pull.py'],
708N/A ['scripts/pkg.bat', 'pkg.bat'],
708N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
708N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
708N/A ],
708N/A lib_dir: [
708N/A ['depot.py', 'depot.py'],
708N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
708N/A ],
708N/A }
708N/A
708N/Ascripts_other_unix = {
708N/A scripts_dir: [
708N/A ['client.py', 'client.py'],
708N/A ['pkgdep.py', 'pkgdep'],
708N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
708N/A ['util/publish/pkgfmt.py', 'pkgfmt'],
708N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
708N/A ['pull.py', 'pull.py'],
708N/A ['publish.py', 'publish.py'],
708N/A ['scripts/pkg.sh', 'pkg'],
708N/A ['scripts/pkgsend.sh', 'pkgsend'],
708N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
708N/A ],
708N/A lib_dir: [
290N/A ['depot.py', 'depot.py'],
290N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
290N/A ],
290N/A }
290N/A
290N/A# indexed by 'osname'
290N/Ascripts = {
290N/A "sunos": scripts_sunos,
290N/A "linux": scripts_other_unix,
290N/A "windows": scripts_windows,
290N/A "darwin": scripts_other_unix,
290N/A "aix" : scripts_other_unix,
290N/A "unknown": scripts_sunos,
395N/A }
395N/A
290N/Aman1_files = [
290N/A 'man/packagemanager.1',
290N/A 'man/pkg.1',
290N/A 'man/pkgdepend.1',
290N/A 'man/pkgdiff.1',
395N/A 'man/pkgfmt.1',
395N/A 'man/pkglint.1',
395N/A 'man/pkgmogrify.1',
290N/A 'man/pkgsend.1',
395N/A 'man/pkgsign.1',
395N/A 'man/pkgrecv.1',
395N/A 'man/pkgrepo.1',
395N/A 'man/pm-updatemanager.1',
591N/A ]
591N/Aman1m_files = [
591N/A 'man/pkg.depotd.1m'
591N/A ]
691N/Aman5_files = [
691N/A 'man/pkg.5'
691N/A ]
691N/Apackages = [
290N/A 'pkg',
290N/A 'pkg.actions',
290N/A 'pkg.bundle',
290N/A 'pkg.client',
290N/A 'pkg.client.transport',
591N/A 'pkg.file_layout',
591N/A 'pkg.flavor',
691N/A 'pkg.lint',
691N/A 'pkg.portable',
290N/A 'pkg.publish',
395N/A 'pkg.server'
395N/A ]
290N/A
395N/Aweb_files = []
395N/Afor entry in os.walk("web"):
395N/A web_dir, dirs, files = entry
395N/A if not files:
290N/A continue
290N/A web_files.append((os.path.join(resource_dir, web_dir), [
290N/A os.path.join(web_dir, f) for f in files
395N/A if f != "Makefile"
395N/A ]))
395N/A
395N/Azones_files = [
395N/A 'brand/SUNWipkg.xml',
395N/A ]
290N/Abrand_files = [
290N/A 'brand/pkgcreatezone',
290N/A 'brand/attach',
290N/A 'brand/clone',
290N/A 'brand/detach',
430N/A 'brand/prestate',
290N/A 'brand/poststate',
290N/A 'brand/uninstall',
395N/A 'brand/common.ksh',
290N/A ]
395N/Aetcbrand_files = [
506N/A 'brand/pkgrm.conf',
506N/A 'brand/smf_disable.conf',
506N/A ]
506N/Asmf_files = [
506N/A 'svc/pkg-mdns.xml',
506N/A 'svc/pkg-server.xml',
395N/A 'svc/pkg-update.xml',
506N/A ]
506N/Aresource_files = [
513N/A 'util/pkglintrc',
506N/A ]
506N/Aexecattrd_files = ['util/misc/exec_attr.d/SUNWipkg']
506N/Aauthattrd_files = ['util/misc/auth_attr.d/SUNWipkg']
513N/Apspawn_srcs = [
506N/A 'modules/pspawn.c'
506N/A ]
506N/Aelf_srcs = [
506N/A 'modules/elf.c',
290N/A 'modules/elfextract.c',
290N/A 'modules/liblist.c',
395N/A ]
395N/Aarch_srcs = [
395N/A 'modules/arch.c'
395N/A ]
395N/A_actions_srcs = [
395N/A 'modules/actions/_actions.c'
413N/A ]
413N/Asolver_srcs = [
413N/A 'modules/solver/solver.c',
395N/A 'modules/solver/py_solver.c'
290N/A ]
395N/Asolver_link_args = ["-lm", "-lc"]
395N/Aif osname == 'sunos':
506N/A solver_link_args = ["-ztext"] + solver_link_args
506N/A
395N/Ainclude_dirs = [ 'modules' ]
395N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
395N/A
395N/A# Runs lint on the extension module source code
430N/Aclass lint_func(Command):
395N/A description = "Runs various lint tools over IPS extension source code"
290N/A user_options = []
465N/A
465N/A def initialize_options(self):
290N/A pass
465N/A
465N/A def finalize_options(self):
465N/A pass
395N/A
465N/A # Make string shell-friendly
395N/A @staticmethod
395N/A def escape(astring):
465N/A return astring.replace(' ', '\\ ')
465N/A
465N/A def run(self):
395N/A # assumes lint is on the $PATH
465N/A if osname == 'sunos' or osname == "linux":
395N/A archcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
465N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
395N/A ['-I' + self.escape(get_python_inc())] + \
465N/A arch_srcs
465N/A elfcmd = ['lint'] + lint_flags + \
465N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
395N/A ['-I' + self.escape(get_python_inc())] + \
395N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
395N/A elf_srcs
395N/A _actionscmd = ['lint'] + lint_flags + \
465N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
465N/A ['-I' + self.escape(get_python_inc())] + \
465N/A _actions_srcs
395N/A pspawncmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
498N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
498N/A ['-I' + self.escape(get_python_inc())] + \
498N/A pspawn_srcs
498N/A
290N/A print(" ".join(archcmd))
465N/A os.system(" ".join(archcmd))
465N/A print(" ".join(elfcmd))
465N/A os.system(" ".join(elfcmd))
454N/A print(" ".join(_actionscmd))
465N/A os.system(" ".join(_actionscmd))
454N/A print(" ".join(pspawncmd))
454N/A os.system(" ".join(pspawncmd))
454N/A
454N/A proto = os.path.join(root_dir, py_install_dir)
465N/A sys.path.insert(0, proto)
290N/A
430N/A # Insert tests directory onto sys.path so any custom checkers
395N/A # can be found.
395N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
290N/A print(sys.path)
383N/A
383N/A # assumes pylint is accessible on the sys.path
395N/A from pylint import lint
383N/A scriptlist = [ 'setup.py' ]
383N/A for d, m in scripts_sunos.items():
384N/A for a in m:
383N/A # specify the filenames of the scripts, in addition
383N/A # to the package names themselves
383N/A scriptlist.append(os.path.join(root_dir, d, a[1]))
383N/A
383N/A # For some reason, the load-plugins option, when used in the
383N/A # rcfile, does not work, so we put it here instead, to load
422N/A # our custom checkers.
422N/A lint.Run(['--load-plugins=multiplatform', '--rcfile',
422N/A os.path.join(pwd, 'tests', 'pylintrc')] +
422N/A scriptlist + packages)
422N/A
422N/Aclass install_func(_install):
422N/A def initialize_options(self):
422N/A _install.initialize_options(self)
422N/A
422N/A # PRIVATE_BUILD set in the environment tells us to put the build
422N/A # directory into the .pyc files, rather than the final
422N/A # installation directory.
422N/A private_build = os.getenv("PRIVATE_BUILD", None)
422N/A
422N/A if private_build is None:
422N/A self.install_lib = py_install_dir
422N/A self.install_data = os.path.sep
383N/A self.root = root_dir
422N/A else:
383N/A self.install_lib = os.path.join(root_dir, py_install_dir)
383N/A self.install_data = root_dir
383N/A
383N/A # This is used when installing scripts, below, but it isn't a
383N/A # standard distutils variable.
383N/A self.root_dir = root_dir
383N/A
422N/A def run(self):
383N/A """
383N/A At the end of the install function, we need to rename some files
290N/A because distutils provides no way to rename files as they are
430N/A placed in their install locations.
395N/A Also, make sure that cherrypy and other external dependencies
395N/A are installed.
290N/A """
290N/A for f in man1_files + man1m_files + man5_files:
290N/A file_util.copy_file(f + ".txt", f, update=1)
290N/A
290N/A _install.run(self)
290N/A
290N/A for o_src, o_dest in hardlink_modules:
290N/A for e in [".py", ".pyc"]:
290N/A src = util.change_root(self.root_dir, o_src + e)
290N/A dest = util.change_root(
290N/A self.root_dir, o_dest + e)
395N/A if ostype == "posix":
290N/A if os.path.exists(dest) and \
395N/A os.stat(src)[stat.ST_INO] != \
290N/A os.stat(dest)[stat.ST_INO]:
395N/A os.remove(dest)
290N/A file_util.copy_file(src, dest,
534N/A link="hard", update=1)
534N/A else:
465N/A file_util.copy_file(src, dest, update=1)
465N/A
290N/A for d, files in scripts[osname].iteritems():
290N/A for (srcname, dstname) in files:
448N/A dst_dir = util.change_root(self.root_dir, d)
430N/A dst_path = util.change_root(self.root_dir,
448N/A os.path.join(d, dstname))
448N/A dir_util.mkpath(dst_dir, verbose = True)
448N/A file_util.copy_file(srcname, dst_path, update = True)
448N/A # make scripts executable
290N/A os.chmod(dst_path,
290N/A os.stat(dst_path).st_mode
290N/A | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
448N/A
448N/A prep_sw(CP, CPARC, CPDIR, CPURL, CPHASH)
430N/A install_sw(CP, CPDIR, CPIDIR)
448N/A if osname == "sunos" and platform.uname()[2] == "5.11":
430N/A prep_sw(LDTP, LDTPARC, LDTPDIR, LDTPURL,
290N/A LDTPHASH)
290N/A saveenv = os.environ.copy()
290N/A os.environ["LDFLAGS"] = os.environ.get("LDFLAGS", "") + \
290N/A " -lsocket -lnsl"
290N/A install_ldtp(LDTP, LDTPDIR, LDTPIDIR)
290N/A os.environ = saveenv
448N/A
448N/A if "BUILD_PYOPENSSL" in os.environ and \
448N/A os.environ["BUILD_PYOPENSSL"] != "":
448N/A #
448N/A # Include /usr/sfw/lib in the build environment
430N/A # to ensure that this builds and runs on older
448N/A # nevada builds, before openssl moved out of /usr/sfw.
290N/A #
290N/A saveenv = os.environ.copy()
290N/A if osname == "sunos":
430N/A os.environ["CFLAGS"] = "-I/usr/sfw/include " + \
395N/A os.environ.get("CFLAGS", "")
290N/A os.environ["LDFLAGS"] = \
290N/A "-L/usr/sfw/lib -R/usr/sfw/lib " + \
290N/A os.environ.get("LDFLAGS", "")
290N/A prep_sw(PO, POARC, PODIR, POURL, POHASH)
290N/A install_sw(PO, PODIR, POIDIR)
613N/A os.environ = saveenv
613N/A prep_sw(M2C, M2CARC, M2CDIR, M2CURL, M2CHASH)
613N/A install_sw(M2C, M2CDIR, M2CIDIR)
613N/A prep_sw(MAKO, MAKOARC, MAKODIR, MAKOURL, MAKOHASH)
613N/A install_sw(MAKO, MAKODIR, MAKOIDIR)
613N/A prep_sw(PLY, PLYARC, PLYDIR, PLYURL, PLYHASH)
613N/A install_sw(PLY, PLYDIR, PLYIDIR)
613N/A prep_sw(PC, PCARC, PCDIR, PCURL, PCHASH)
613N/A install_sw(PC, PCDIR, PCIDIR, extra_env=PCENVIRON)
290N/A prep_sw(COV, COVARC, COVDIR, COVURL, COVHASH)
430N/A install_sw(COV, COVDIR, COVIDIR)
395N/A prep_sw(PBJ, PBJARC, PBJDIR, PBJURL, PBJHASH)
395N/A install_sw(PBJ, PBJDIR, PBJIDIR)
395N/A
395N/A # Remove some bits that we're not going to package, but be sure
395N/A # not to complain if we try to remove them twice.
395N/A def onerror(func, path, exc_info):
395N/A if exc_info[1].errno != errno.ENOENT:
395N/A raise
708N/A
395N/A for dir in ("cherrypy/scaffold", "cherrypy/test",
395N/A "cherrypy/tutorial"):
290N/A shutil.rmtree(os.path.join(root_dir, py_install_dir, dir),
383N/A onerror=onerror)
395N/A try:
395N/A os.remove(os.path.join(root_dir, "usr/bin/mako-render"))
395N/A except EnvironmentError, e:
395N/A if e.errno != errno.ENOENT:
395N/A raise
290N/A
290N/Adef hash_sw(swname, swarc, swhash):
395N/A if swhash == None:
395N/A return True
395N/A
395N/A print "checksumming %s" % swname
395N/A hash = hashlib.sha1()
395N/A f = open(swarc, "rb")
290N/A while True:
290N/A data = f.read(65536)
395N/A if data == "":
395N/A break
395N/A hash.update(data)
613N/A f.close()
290N/A
395N/A if hash.hexdigest() == swhash:
395N/A return True
395N/A else:
395N/A print >> sys.stderr, "bad checksum! %s != %s" % \
395N/A (swhash, hash.hexdigest())
395N/A return False
395N/A
395N/Adef prep_sw(swname, swarc, swdir, swurl, swhash):
290N/A swarc = os.path.join(extern_dir, swarc)
395N/A swdir = os.path.join(extern_dir, swdir)
395N/A if not os.path.exists(extern_dir):
395N/A os.mkdir(extern_dir)
395N/A
395N/A if not os.path.exists(swarc):
395N/A print "downloading %s" % swname
430N/A try:
395N/A fname, hdr = urllib.urlretrieve(swurl, swarc)
395N/A except IOError:
395N/A pass
395N/A if not os.path.exists(swarc):
395N/A print >> sys.stderr, "Unable to retrieve %s.\n" \
395N/A "Please retrieve the file " \
691N/A "and place it at: %s\n" % (swurl, swarc)
691N/A # remove a partial download or error message from proxy
691N/A remove_sw(swname)
691N/A sys.exit(1)
691N/A if not os.path.exists(swdir):
691N/A if not hash_sw(swname, swarc, swhash):
691N/A sys.exit(1)
691N/A
395N/A print "unpacking %s" % swname
395N/A tar = tarfile.open(swarc)
395N/A # extractall doesn't exist until python 2.5
395N/A for m in tar.getmembers():
395N/A tar.extract(m, extern_dir)
395N/A tar.close()
395N/A
395N/A # If there are patches, apply them now.
395N/A patchdir = os.path.join("patch", swname)
395N/A already_patched = os.path.join(swdir, ".patched")
395N/A if os.path.exists(patchdir) and not os.path.exists(already_patched):
395N/A patches = os.listdir(patchdir)
395N/A for p in patches:
patchpath = os.path.join(os.path.pardir,
os.path.pardir, patchdir, p)
print "Applying %s to %s" % (p, swname)
args = ["patch", "-d", swdir, "-i", patchpath, "-p0"]
if osname == "windows":
args.append("--binary")
ret = subprocess.Popen(args).wait()
if ret != 0:
print >> sys.stderr, \
"patch failed and returned %d." % ret
print >> sys.stderr, \
"Command was: %s" % " ".join(args)
sys.exit(1)
file(already_patched, "w").close()
def install_ldtp(swname, swdir, swidir):
swdir = os.path.join(extern_dir, swdir)
swinst_file = os.path.join(root_dir, py_install_dir, swidir + ".py")
if not os.path.exists(swinst_file):
print "installing %s" % swname
args_config = ['./configure',
'--prefix=/usr',
'--bindir=/usr/bin',
'PYTHONPATH=""',
]
args_make_install = ['make', 'install',
'DESTDIR=%s' % root_dir
]
run_cmd(args_config, swdir)
run_cmd(args_make_install, swdir)
def install_sw(swname, swdir, swidir, extra_env=None):
swdir = os.path.join(extern_dir, swdir)
swinst_dir = os.path.join(root_dir, py_install_dir, swidir)
inst_env = os.environ.copy()
if extra_env:
inst_env.update(extra_env)
if not os.path.exists(swinst_dir):
print "installing %s" % swname
args = ['python2.6', 'setup.py', 'install',
'--root=%s' % root_dir,
'--install-lib=%s' % py_install_dir,
'--install-data=%s' % py_install_dir]
run_cmd(args, swdir, env=inst_env)
def run_cmd(args, swdir, env=None):
if env is None:
env = os.environ
ret = subprocess.Popen(args, cwd=swdir, env=env).wait()
if ret != 0:
print >> sys.stderr, \
"install failed and returned %d." % ret
print >> sys.stderr, \
"Command was: %s" % " ".join(args)
sys.exit(1)
def remove_sw(swname):
print("deleting %s" % swname)
for file in os.listdir(extern_dir):
if fnmatch.fnmatch(file, "%s*" % swname):
fpath = os.path.join(extern_dir, file)
if os.path.isfile(fpath):
os.unlink(fpath)
else:
shutil.rmtree(fpath, True)
class build_func(_build):
def initialize_options(self):
_build.initialize_options(self)
self.build_base = build_dir
def get_hg_version():
try:
p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
return p.communicate()[0].strip()
except OSError:
print >> sys.stderr, "ERROR: unable to obtain mercurial version"
return "unknown"
def syntax_check(filename):
""" Run python's compiler over the file, and discard the results.
Arrange to generate an exception if the file does not compile.
This is needed because distutil's own use of pycompile (in the
distutils.utils module) is broken, and doesn't stop on error. """
try:
py_compile.compile(filename, os.devnull, doraise=True)
except py_compile.PyCompileError, e:
raise DistutilsError("%s: failed syntax check: %s" %
(filename, e))
class build_py_func(_build_py):
# override the build_module method to do VERSION substitution on pkg/__init__.py
def build_module (self, module, module_file, package):
if module == "__init__" and package == "pkg":
versionre = '(?m)^VERSION[^"]*"([^"]*)"'
# Grab the previously-built version out of the build
# tree.
try:
ocontent = \
file(self.get_module_outfile(self.build_lib,
[package], module)).read()
ov = re.search(versionre, ocontent).group(1)
except IOError:
ov = None
v = get_hg_version()
vstr = 'VERSION = "%s"' % v
# If the versions haven't changed, there's no need to
# recompile.
if v == ov:
return
mcontent = file(module_file).read()
mcontent = re.sub(versionre, vstr, mcontent)
tmpfd, tmp_file = tempfile.mkstemp()
os.write(tmpfd, mcontent)
os.close(tmpfd)
print "doing version substitution: ", v
rv = _build_py.build_module(self, module, tmp_file, package)
os.unlink(tmp_file)
return rv
# Will raise a DistutilsError on failure.
syntax_check(module_file)
return _build_py.build_module(self, module, module_file, package)
class clean_func(_clean):
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 " + pkgs_dir)
shutil.rmtree(pkgs_dir, True)
print("deleting " + extern_dir)
shutil.rmtree(extern_dir, True)
class test_func(Command):
# NOTE: these options need to be in sync with tests/run.py and the
# list of options stored in initialize_options below. The first entry
# in each tuple must be the exact name of a member variable.
user_options = [
("archivedir=", 'a', "archive failed tests <dir>"),
("baselinefile=", 'b', "baseline file <file>"),
("coverage", "c", "collect code coverage data"),
("genbaseline", 'g', "generate test baseline"),
("only=", "o", "only <regex>"),
("parseable", 'p', "parseable output"),
("timing", "t", "timing file <file>"),
("verbosemode", 'v', "run tests in verbose mode"),
("stoponerr", 'x', "stop when a baseline mismatch occurs"),
("debugoutput", 'd', "emit debugging output"),
("showonexpectedfail", 'f',
"show all failure info, even for expected fails"),
("startattest=", 's', "start at indicated test"),
]
description = "Runs unit and functional tests"
def initialize_options(self):
self.only = ""
self.baselinefile = ""
self.verbosemode = 0
self.parseable = 0
self.genbaseline = 0
self.timing = 0
self.coverage = 0
self.stoponerr = 0
self.debugoutput = 0
self.showonexpectedfail = 0
self.startattest = ""
self.archivedir = ""
def finalize_options(self):
pass
def run(self):
os.putenv('PYEXE', sys.executable)
os.chdir(os.path.join(pwd, "tests"))
# Reconstruct the cmdline and send that to run.py
cmd = [sys.executable, "run.py"]
args = ""
if "test" in sys.argv:
args = sys.argv[sys.argv.index("test")+1:]
cmd.extend(args)
subprocess.call(cmd)
class dist_func(_bdist):
def initialize_options(self):
_bdist.initialize_options(self)
self.dist_dir = dist_dir
class info_func(Command):
user_options = [
("pkg=", None, "Component package name")
]
description = "Print component information"
def initialize_options(self):
self.pkg = ""
def finalize_options(self):
self.pkg = urllib.unquote(self.pkg.rsplit(".", 1)[0])
pkginfo = {
"library/python-2/cherrypy": (CPVER, CPVER, CPURL),
"library/python-2/coverage": (COVVER, COVPVER, COVURL),
"library/python-2/m2crypto": (M2CVER, M2CVER, M2CURL),
"library/python-2/mako": (MAKOVER, MAKOVER, MAKOURL),
"library/python-2/ply": (PLYVER, PLYVER, PLYURL),
"library/python-2/pybonjour": (PBJVER, PBJVER, PBJURL),
"library/python-2/pycurl": (PCVER, PCPVER, PCURL),
"system/desktop/ldtp": (LDTPVER, LDTPVER, LDTPURL)
}
def run(self):
if self.pkg in self.pkginfo:
print "-D SOURCE_VER=%s -D PKG_VER=%s " \
"-D SOURCE_URL=%s" % self.pkginfo[self.pkg]
# These are set to real values based on the platform, down below
compile_args = None
if osname in ("sunos", "linux", "darwin"):
compile_args = [ "-O3" ]
link_args = None
ext_modules = [
Extension(
'actions._actions',
_actions_srcs,
include_dirs = include_dirs,
extra_compile_args = compile_args,
extra_link_args = link_args
),
Extension(
'solver',
solver_srcs,
include_dirs = include_dirs + ["."],
extra_compile_args = compile_args,
extra_link_args = solver_link_args,
define_macros = [('_FILE_OFFSET_BITS', '64')]
),
]
elf_libraries = None
data_files = 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,
'info': info_func,
}
# all builds of IPS should have manpages
data_files += [
(man1_dir, man1_files),
(man1m_dir, man1m_files),
(man5_dir, man5_files),
(resource_dir, resource_files),
]
if osname == 'sunos':
# Solaris-specific extensions are added here
data_files += [
(zones_dir, zones_files),
(brand_dir, brand_files),
(etcbrand_dir, etcbrand_files),
(smf_dir, smf_files),
(execattrd_dir, execattrd_files),
(authattrd_dir, authattrd_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')]
),
Extension(
'pspawn',
pspawn_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 = 'pkg',
version = '0.1',
package_dir = {'pkg':'modules'},
packages = packages,
data_files = data_files,
ext_package = 'pkg',
ext_modules = ext_modules,
)