# HG changeset patch # User Bernhard Herzog # Date 1175539645 -7200 # Node ID aed3869ac04a2415cd402abc3541e3568b298796 # Parent 2802be4101567db527a37701bc233dc465067a8d add script to initialize treepkg pbuilder environment diff -r 2802be410156 -r aed3869ac04a initpbuilder.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/initpbuilder.py Mon Apr 02 20:47:25 2007 +0200 @@ -0,0 +1,128 @@ +#! /usr/bin/python2.4 +# Copyright (C) 2007 by Intevation GmbH +# Authors: +# Bernhard Herzog +# +# This program is free software under the GPL (>=v2) +# Read the file COPYING coming with the software for details. + +"""Script to initialize the pbuilder environment for the tree packager + +The script assumes that the config file for the tree packager already +contains the pbuilder settings. Also, this script assumes that there is +only one pbuilder setting for all packagers. +""" + +import sys +import os +from optparse import OptionParser + +from treepkg.packager import create_package_line, PackagerGroup +from treepkg.readconfig import read_config +from treepkg.util import ensure_directory, writefile +from treepkg.run import call + + +pbuilderrc_template = '''\ +# This file was automatically generated by initpbuilder.py. +# for the possible settings see "man pbuilderrc" + +BASETGZ=%(basedir)s/base.tgz +BUILDPLACE=%(builddir)s +USEPROC=yes +USEDEVPTS=yes +BUILDRESULT=%(resultdir)s +DISTRIBUTION=%(distribution)s +APTCACHE=%(basedir)s/aptcache +APTCACHEHARDLINK=yes +REMOVEPACKAGES=lilo +MIRRORSITE="%(mirrorsite)s" +OTHERMIRROR="%(othermirror)s" +BINDMOUNTS="%(extra-pkgdir)s" +PKGNAME_LOGFILE=yes +''' + + +def init_pbuilder(pbuilderrc, distribution, mirrorsite, extramirrors, root_cmd): + if not os.path.isabs(pbuilderrc): + print >>sys.stderr, "pbuilderrc must be an absolute filename" + sys.exit(1) + + if os.path.exists(pbuilderrc): + print >>sys.stderr, "pbuilderrc %r already exists." % pbuilderrc + sys.exit(1) + + basedir = os.path.dirname(pbuilderrc) + replacements = dict(basedir=basedir, + distribution=distribution, + mirrorsite=mirrorsite) + + # create the pbuilder directories. basedir is created implicitly by + # creating its subdirectories. + for subdir in ["base", "build", "result", "aptcache", "extra-pkg"]: + directory = os.path.join(basedir, subdir) + replacements[subdir + "dir"] = directory + print "creating directory:", repr(directory) + ensure_directory(directory) + + # build OTHERMIRROR value. We always include the extra-pkg dir. + othermirror = "deb file://%(extra-pkgdir)s ./" % replacements + if extramirrors: + othermirror += " | " + extramirrors + replacements["othermirror"] = othermirror + + # create the pbuilderrcfile + print "creating pbuilderrc:", repr(pbuilderrc) + writefile(pbuilderrc, pbuilderrc_template % replacements) + + # turn the extra-pkg directory into a property deb archive + print "turn the extra-pkg dir into a debian archive" + extra_pkgdir = replacements["extra-pkgdir"] + call(["apt-ftparchive", "packages", "."], + stdout=open(os.path.join(extra_pkgdir, "Packages"), "w"), + cwd=extra_pkgdir) + + # create the base.tgz chroot + print "Run pbuilder create" + call(root_cmd + ["pbuilder", "create", "--configfile", pbuilderrc]) + + +def parse_commandline(): + parser = OptionParser() + parser.set_defaults(config_file=os.path.join(os.path.dirname(__file__), + "treepkg.cfg"), + distribution="etch") + parser.add_option("--config-file", + help=("The tree packager config file." + " Default is treepkg.cfg")) + parser.add_option("--mirrorsite", + help=("The debian mirror site" + " (pbuilder MIRRORSITE setting). Required.")) + parser.add_option("--othermirror", + help=("Extra contents of the OTHERMIRROR setting." + " See the pbuilder documentation for the format.")) + parser.add_option("--distribution", + help=("The debian distribution for the pbuilder chroot." + " Default is etch.")) + return parser.parse_args() + + +def main(): + options, args = parse_commandline() + + if options.mirrorsite is None: + print >>sys.stderr, "Missing required option --mirrorsite" + sys.exit(1) + + treepkg_opts, packager_opts = read_config(options.config_file) + group = PackagerGroup([create_package_line(**opts) + for opts in packager_opts], + **treepkg_opts) + pkg_line = group.get_package_lines()[0] + init_pbuilder(pkg_line.pbuilderrc, + distribution=options.distribution, + mirrorsite=options.mirrorsite, + extramirrors=options.othermirror, + root_cmd=pkg_line.root_cmd) + +main()