view initpbuilder.py @ 59:9cb94b9ac6a6

merge
author Bernhard Herzog <bh@intevation.de>
date Tue, 10 Apr 2007 18:17:53 +0200
parents 78cf5f6778ec
children
line wrap: on
line source
#! /usr/bin/python2.4
# Copyright (C) 2007 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh@intevation.de>
#
# 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_track, 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_track(**opts)
                           for opts in packager_opts],
                          **treepkg_opts)
    track = group.get_package_tracks()[0]
    init_pbuilder(track.pbuilderrc,
                  distribution=options.distribution,
                  mirrorsite=options.mirrorsite,
                  extramirrors=options.othermirror,
                  root_cmd=track.root_cmd)

main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)