changeset 49:38d66dc6a1e5

merge
author Bernhard Herzog <bh@intevation.de>
date Mon, 02 Apr 2007 20:48:25 +0200
parents aed3869ac04a (diff) b0a4df526d64 (current diff)
children 225206553bba
files treepkg/packager.py
diffstat 4 files changed, 142 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/demo.cfg	Mon Apr 02 19:12:20 2007 +0200
+++ b/demo.cfg	Mon Apr 02 20:48:25 2007 +0200
@@ -23,6 +23,14 @@
 # specific values
 root_cmd: sudo
 
+# The pbuilder config file to use.  It should be an absolute filename.
+# The script initpbuilder.py can create it and the rest of the pbuilder
+# files and directories.  You can override this in the pkg_ sections for
+# individual packagers if necessaary.  You will have to adapt pbuilder
+# yourself, then, though.
+pbuilderrc: %(treepkg_dir)s/pbuilder/pbuilderrc
+
+
 # Email address and name to use as the packager in the debian packages.
 # You can override this in the pkg_ sections if you need package
 # specific values
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/initpbuilder.py	Mon Apr 02 20:48:25 2007 +0200
@@ -0,0 +1,128 @@
+#! /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_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()
--- a/treepkg/packager.py	Mon Apr 02 19:12:20 2007 +0200
+++ b/treepkg/packager.py	Mon Apr 02 20:48:25 2007 +0200
@@ -185,7 +185,9 @@
         self.status.creating_binary_package()
         util.ensure_directory(self.binary_dir)
         logging.info("Building binary package; loging to %r", self.logfile)
-        cmd = ["/usr/sbin/pbuilder", "build", "--logfile", self.logfile,
+        cmd = ["/usr/sbin/pbuilder", "build",
+               "--configfile", self.pkg_line.pbuilderrc,
+               "--logfile", self.logfile,
                "--buildresult", self.binary_dir, self.dsc_file]
         run.call(self.pkg_line.root_cmd + cmd, suppress_output=True)
         self.status.binary_package_created()
@@ -253,12 +255,13 @@
 
     extra_config_desc = []
 
-    def __init__(self, name, base_dir, svn_url, root_cmd, deb_email,
+    def __init__(self, name, base_dir, svn_url, root_cmd, pbuilderrc, deb_email,
                  deb_fullname, packager_class="treepkg.packager"):
         self.name = name
         self.base_dir = base_dir
         self.svn_url = svn_url
         self.root_cmd = root_cmd
+        self.pbuilderrc = pbuilderrc
         self.deb_email = deb_email
         self.deb_fullname = deb_fullname
         self.pkg_dir_template = "%(revision)d-%(increment)d"
--- a/treepkg/readconfig.py	Mon Apr 02 19:12:20 2007 +0200
+++ b/treepkg/readconfig.py	Mon Apr 02 20:48:25 2007 +0200
@@ -17,7 +17,7 @@
 
 packager_desc = [
     "name", "base_dir", "svn_url", "packager_class",
-    ("root_cmd", shlex.split),
+    ("root_cmd", shlex.split), "pbuilderrc",
     "deb_email", "deb_fullname",
     ]
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)