python/nondist/sandbox/Lib bdist_dpkg.py, NONE, 1.1
Update of /cvsroot/python/python/nondist/sandbox/Lib In directory sc8-pr-cvs1:/tmp/cvs-serv3263 Added Files: bdist_dpkg.py Log Message: Stab at bdist_dpkg -- still needs a lot of work --- NEW FILE: bdist_dpkg.py --- """distutils.command.bdist_dpkg Implements the Distutils 'bdist_dpkg' command (create a Debian packaging). """ # This module should be kept compatible with Python 1.5.2. __revision__ = "$Id: bdist_dpkg.py,v 1.1 2003/09/21 19:56:14 akuchling Exp $" import sys, os, string import glob from types import * from distutils.core import Command from distutils.debug import DEBUG from distutils.util import get_platform from distutils.file_util import write_file from distutils.errors import * from distutils import log MARKER_STRING = "GENERATED BY BDIST_DPKG" class bdist_dpkg (Command): description = "create a DPKG distribution" user_options = [ ] boolean_options = [] def initialize_options (self): pass # initialize_options() def finalize_options (self): if os.name != 'posix': raise DistutilsPlatformError, \ ("don't know how to create DPKG " "distributions on platform %s" % os.name) # finalize_options() def run (self): if DEBUG: print "before _get_package_data():" self._create_dpkg_files() # build package log.info("building DPKG") #self.spawn(["dpkg-buildpackage", "-rfakeroot"]) # run() def _create_dpkg_files (self): # Files to create: # changelog, control, # Optional: docs, copyright # log.info("creating debian control files") if not os.path.exists('debian'): log.info("creating debian/ subdirectory") os.mkdir('debian') dirlist = "" for i in self.distribution.packages: dir = i dirlist += ' ' + dir dist = self.distribution package_name = dist.get_name().lower() d = {'name':dist.get_name(), 'package_name':package_name, 'pyversion': '%i.%i' % sys.version_info[0:2], 'dirlist':dirlist, 'marker':MARKER_STRING, } if not self._is_user_file('changelog') or True: log.info('writing changelog file') output = self._write_file('changelog') output.write("""%s (%s-%i) unstable; urgency=low * Dummy changelog line -- %s <%s> Wed, 11 Jun 2003 14:44:11 -0400 """ % (package_name, dist.get_version(), 1, # XXX build version dist.get_maintainer(), dist.get_maintainer_email())) output.close() if not self._is_user_file('control') or True: dist = self.distribution log.info('writing control file') output = self._write_file('control') #output.write('XXX-Dummy-Field: %s\n' % MARKER_STRING) output.write("Source: %s\n" % package_name) output.write("Priority: optional\n") output.write("Maintainer: %s <%s>\n" % (dist.get_maintainer(), dist.get_maintainer_email())) output.write("""Build-Depends: debhelper (>> 3.0.0) Standards-Version: 3.5.8 Section: libs """) output.write('\n') # Separator line output.write("Package: %s\n" % package_name) output.write("""Section: libs Architecture: all\n""") output.write("Depends: python%(pyversion)s\n" % d) output.write("Description: %s\n" % dist.get_description()) s = dist.get_long_description() s = string.replace(s, '\n', '\n ') output.write(' ' + s) output.close() if not self._is_user_file('postinst'): log.info('writing postinst file') output = self._write_file('postinst') output.write(POSTINST_FILE % d) output.close() if not self._is_user_file('prerm'): log.info('writing prerm file') output = self._write_file('prerm') output.write(PRERM_FILE % d) output.close() if not self._is_user_file('rules'): log.info('writing rules file') output = self._write_file('rules') output.write(RULES_FILE % d) output.close() os.chmod('debian/rules', 0755) def _write_file (self, filename): path = os.path.join('debian', filename) assert not self._is_user_file(path) output = open(path, 'w') return output def _is_user_file (self, filename): path = os.path.join('debian', filename) if not os.path.exists(path): return False input = open(path, 'r') while 1: L = input.readline() if L == "": break elif L.find(MARKER_STRING) != -1: return False return True # class bdist_dpkg PRERM_FILE = """#! /bin/sh # %(marker)s -- remove this line if you edit this file # prerm script for %(name)s set -e PACKAGE=%(name)s VERSION=%(pyversion)s LIB="/usr/lib/python$VERSION" DIRLIST="%(dirlist)s" case "$1" in remove|upgrade|failed-upgrade) for i in $DIRLIST ; do find $LIB/site-packages/$i -name '*.py[co]' -exec rm \{\} \; done ;; *) echo "prerm called with unknown argument \`$1'" >&2 exit 1 ;; esac exit 0 """ POSTINST_FILE = """#! /bin/sh # %(marker)s -- remove this line if you edit this file # postinst script for %(name)s # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * <postinst> `configure' <most-recently-configured-version> # * <old-postinst> `abort-upgrade' <new version> # * <conflictor's-postinst> `abort-remove' `in-favour' <package> # <new-version> # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' # <failed-install-package> <version> `removing' # <conflicting-package> <version> # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package # # quoting from the policy: # Any necessary prompting should almost always be confined to the # post-installation script, and should be protected with a conditional # so that unnecessary prompting doesn't happen if a package's # installation fails and the `postinst' is called with `abort-upgrade', # `abort-remove' or `abort-deconfigure'. PACKAGE=%(name)s VERSION=%(pyversion)s LIB="/usr/lib/python$VERSION" DIRLIST="%(dirlist)s" case "$1" in configure|abort-upgrade|abort-remove|abort-deconfigure) for i in $DIRLIST ; do /usr/bin/python$VERSION -O $LIB/compileall.py -q $LIB/site-packages/$i /usr/bin/python$VERSION $LIB/compileall.py -q $LIB/site-packages/$i done ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac exit 0 """ RULES_FILE = """#!/usr/bin/make -f # %(marker)s -- remove this line if you edit this file # Sample debian/rules that uses debhelper. # GNU copyright 1997 to 1999 by Joey Hess. # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 # This is the debhelper compatibility version to use. export DH_COMPAT=4 build: build-stamp /usr/bin/python2.2 setup.py build build-stamp: touch build-stamp configure: # Do nothing clean: dh_testdir dh_testroot rm -f build-stamp -rm -rf build dh_clean install: build dh_testdir dh_testroot dh_clean -k /usr/bin/python%(pyversion)s setup.py install --no-compile --prefix=$(CURDIR)/debian/%(package_name)s/usr # Build architecture-independent files here. binary-indep: install dh_testdir dh_testroot dh_installdocs dh_installdeb dh_gencontrol dh_md5sums dh_builddeb # We have nothing to do by default. binary: binary-indep .PHONY: build clean binary-indep binary install """
participants (1)
-
akuchling@users.sourceforge.net