changeset 112:cea98d4e4a6a

Abstract the pbuilder calls into the new class treepkg.builder.PBuilder. Use this class in treepkg.packager.
author Bernhard Herzog <bh@intevation.de>
date Thu, 20 Mar 2008 20:21:34 +0000
parents 7f6fb8103db0
children 312949e7628d
files treepkg/builder.py treepkg/packager.py
diffstat 2 files changed, 53 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/treepkg/builder.py	Thu Mar 20 20:21:34 2008 +0000
@@ -0,0 +1,50 @@
+# Copyright (C) 2007, 2008 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.
+
+"""Build binary packages from source packages"""
+
+import os
+
+import util
+import run
+from cmdexpand import cmdexpand
+
+
+class PBuilder(object):
+
+    """Represents a way to run and manage a specific pbuilder instance"""
+
+    def __init__(self, pbuilderrc, root_cmd):
+        """Initialize the PBuilder instance with the configuration file.
+        The root_cmd parameter should be a list with a command that can
+        be used to get root permissions to run pbuilder.  It may be an
+        empty list if no command is needed.  It's a list so that
+        commands with several shell-words can be used without having to
+        worry about quoting.
+        """
+        self.pbuilderrc = pbuilderrc
+        self.root_cmd = root_cmd
+
+    def build(self, dsc_file, binary_dir, logfile):
+        """Build a binary packager from a source package
+        Parameters:
+           dsc_file -- name of the debian .dsc file of the source package
+           binary_dir -- name of the directory to receive the binary packages
+           logfile -- name of the logfile of the build
+        """
+        util.ensure_directory(binary_dir)
+        run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder build"
+                           " --configfile $pbuilderrc"
+                           " --logfile $logfile --buildresult $bindir $dsc",
+                           rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc,
+                           logfile=logfile, bindir=binary_dir, dsc=dsc_file),
+                 suppress_output=True)
+        # remove the source package files put into the binary directory
+        # by pbuilder
+        for filename in os.listdir(binary_dir):
+            if os.path.splitext(filename)[1] not in (".deb", ".changes"):
+                os.remove(os.path.join(binary_dir, filename))
--- a/treepkg/packager.py	Wed Mar 19 19:50:32 2008 +0000
+++ b/treepkg/packager.py	Thu Mar 20 20:21:34 2008 +0000
@@ -19,6 +19,7 @@
 import run
 import status
 from cmdexpand import cmdexpand
+from builder import PBuilder
 
 def _filenameproperty(relative_dir):
     def get(self):
@@ -187,19 +188,7 @@
         self.status.creating_binary_package()
         util.ensure_directory(self.binary_dir)
         logging.info("Building binary package; logging to %r", self.logfile)
-        run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder build"
-                           " --configfile $pbuilderrc"
-                           " --logfile $logfile --buildresult $bindir $dsc",
-                           rootcmd=self.track.root_cmd,
-                           pbuilderrc=self.track.pbuilderrc,
-                           logfile=self.logfile, bindir=self.binary_dir,
-                           dsc=self.dsc_file),
-                 suppress_output=True)
-        # remove the source package files put into the binary directory
-        # by pbuilder
-        for filename in os.listdir(self.binary_dir):
-            if os.path.splitext(filename)[1] not in (".deb", ".changes"):
-                os.remove(os.path.join(self.binary_dir, filename))
+        self.track.builder.build(self.dsc_file, self.binary_dir, self.logfile)
         self.status.binary_package_created()
 
 
@@ -291,8 +280,7 @@
         self.name = name
         self.base_dir = base_dir
         self.svn_url = svn_url
-        self.root_cmd = root_cmd
-        self.pbuilderrc = pbuilderrc
+        self.builder = PBuilder(pbuilderrc, root_cmd)
         self.deb_email = deb_email
         self.deb_fullname = deb_fullname
         self.debrevision_prefix = debrevision_prefix
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)