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