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