[Treepkg-commits] r273 - branches/scratchbox/treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Apr 15 16:03:15 CEST 2010


Author: bricks
Date: 2010-04-15 16:03:15 +0200 (Thu, 15 Apr 2010)
New Revision: 273

Modified:
   branches/scratchbox/treepkg/builder.py
   branches/scratchbox/treepkg/sbuilder.py
Log:
changed builder for sbdmock
both builders now derive from Builder that contains all common methods


Modified: branches/scratchbox/treepkg/builder.py
===================================================================
--- branches/scratchbox/treepkg/builder.py	2010-04-15 10:07:18 UTC (rev 272)
+++ branches/scratchbox/treepkg/builder.py	2010-04-15 14:03:15 UTC (rev 273)
@@ -17,9 +17,63 @@
 import run
 from cmdexpand import cmdexpand
 
+class Builder:
+    
+    basetgz_dir = util.filenameproperty("base")
+    build_dir = util.filenameproperty("build")
+    result_dir = util.filenameproperty("result")
+    aptcache_dir = util.filenameproperty("aptcache")
+    extra_pkg_dir = util.filenameproperty("extra-pkg")
+    
+    """ Parent class for all Builders """
+    def __init__(self):
+        pass
 
-class PBuilder(object):
+    def update_extra_pkg_dir(self):
+        run.call(cmdexpand("apt-ftparchive packages ."),
+                 stdout=open(os.path.join(self.extra_pkg_dir, "Packages"), "w"),
+                 cwd=self.extra_pkg_dir)
+        release_filename = os.path.join(self.extra_pkg_dir, "Release")
+        run.call(cmdexpand("apt-ftparchive release ."),
+                 stdout=open(release_filename, "w"), cwd=self.extra_pkg_dir)
+        # handle signatures.  remove any existing signature because it
+        # will be invalid now.
+        signature = release_filename + ".gpg"
+        try:
+            os.remove(signature)
+        except OSError:
+            pass
+        if self.release_signing_keyid:
+            run.call(cmdexpand("gpg --detach-sign --armor --local-user=$keyid"
+                               " -o $sig $release",
+                               keyid=self.release_signing_keyid,
+                               sig=release_filename + ".gpg",
+                               release=release_filename))
 
+    def add_binaries_to_extra_pkg(self, filenames, subdirectory="auto"):
+        """Adds binary packages to the extra-pkg directory.
+        The filenames parameter should be sequence of absolute
+        filenames.  The files named will be copied to a subdirectory of
+        the extra-pkg directory which is assumed to reside in the same
+        directory as the pbuilderrc.  The subdirectory is specified with
+        the subdirectory parameter and defaults to 'auto'.  Afterwards,
+        the method generates a Packages file in the directory and runs
+        pbuilder update.  All of this assumes that pbuilder was set up
+        the way bin/initpbuilder.py does.
+        """
+        target_dir = os.path.join(self.extra_pkg_dir, subdirectory)
+        util.ensure_directory(target_dir)
+        for filename in filenames:
+            logging.info("Copying %s into %s", filename, target_dir)
+            shutil.copy(filename, target_dir)
+
+        logging.info("Running apt-ftparchive in %s", self.extra_pkg_dir)
+        self.update_extra_pkg_dir()
+
+        self.update(suppress_output=True, log_info=True)
+
+class PBuilder(Builder):
+
     """Represents a way to run and manage a specific pbuilder instance"""
 
     pbuilderrc_template = '''\
@@ -41,12 +95,6 @@
 PKGNAME_LOGFILE=yes
 '''
 
-    basetgz_dir = util.filenameproperty("base")
-    build_dir = util.filenameproperty("build")
-    result_dir = util.filenameproperty("result")
-    aptcache_dir = util.filenameproperty("aptcache")
-    extra_pkg_dir = util.filenameproperty("extra-pkg")
-
     def __init__(self, pbuilderrc, root_cmd, release_signing_keyid=None):
         """Initialize the PBuilder instance with the configuration file.
         The root_cmd parameter should be a list with a command that can
@@ -104,27 +152,6 @@
         run.call(cmdexpand("@root_cmd pbuilder create --configfile $pbuilderrc",
                            root_cmd=self.root_cmd, pbuilderrc=self.pbuilderrc))
 
-    def update_extra_pkg_dir(self):
-        run.call(cmdexpand("apt-ftparchive packages ."),
-                 stdout=open(os.path.join(self.extra_pkg_dir, "Packages"), "w"),
-                 cwd=self.extra_pkg_dir)
-        release_filename = os.path.join(self.extra_pkg_dir, "Release")
-        run.call(cmdexpand("apt-ftparchive release ."),
-                 stdout=open(release_filename, "w"), cwd=self.extra_pkg_dir)
-        # handle signatures.  remove any existing signature because it
-        # will be invalid now.
-        signature = release_filename + ".gpg"
-        try:
-            os.remove(signature)
-        except OSError:
-            pass
-        if self.release_signing_keyid:
-            run.call(cmdexpand("gpg --detach-sign --armor --local-user=$keyid"
-                               " -o $sig $release",
-                               keyid=self.release_signing_keyid,
-                               sig=release_filename + ".gpg",
-                               release=release_filename)),
-
     def update(self, suppress_output=True, log_info=True):
         """Runs pbuilder update on this pbuilder instance"""
         if log_info:
@@ -204,28 +231,7 @@
                 if os.path.splitext(filename)[1] not in (".deb", ".changes"):
                     os.remove(os.path.join(binary_dir, filename))
 
-    def add_binaries_to_extra_pkg(self, filenames, subdirectory="auto"):
-        """Adds binary packages to the extra-pkg directory.
-        The filenames parameter should be sequence of absolute
-        filenames.  The files named will be copied to a subdirectory of
-        the extra-pkg directory which is assumed to reside in the same
-        directory as the pbuilderrc.  The subdirectory is specified with
-        the subdirectory parameter and defaults to 'auto'.  Afterwards,
-        the method generates a Packages file in the directory and runs
-        pbuilder update.  All of this assumes that pbuilder was set up
-        the way bin/initpbuilder.py does.
-        """
-        target_dir = os.path.join(self.extra_pkg_dir, subdirectory)
-        util.ensure_directory(target_dir)
-        for filename in filenames:
-            logging.info("Copying %s into %s", filename, target_dir)
-            shutil.copy(filename, target_dir)
 
-        logging.info("Running apt-ftparchive in %s", self.extra_pkg_dir)
-        self.update_extra_pkg_dir()
-
-        self.update(suppress_output=True, log_info=True)
-
     def run_script(self, script, logfile, bindmounts=(), save_after_exec=False):
         """Execute a script in pbuilder's chroot environment
         Parameters:

Modified: branches/scratchbox/treepkg/sbuilder.py
===================================================================
--- branches/scratchbox/treepkg/sbuilder.py	2010-04-15 10:07:18 UTC (rev 272)
+++ branches/scratchbox/treepkg/sbuilder.py	2010-04-15 14:03:15 UTC (rev 273)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 by Intevation GmbH
+# Copyright (C) 2010 by Intevation GmbH
 # Authors:
 # Bjoern Ricks <bjoern.ricks at intevation.de>
 #
@@ -15,32 +15,15 @@
 
 import util
 import run
+import builder
 from cmdexpand import cmdexpand
 
 
-class SbdmockBuilder(object):
+class SbdmockBuilder(Builder):
 
-    """Represents a way to run and manage a specific pbuilder instance"""
+    """Represents a way to run and manage a specific sbdmock instance
+    to build binary for Maemo within scratchbox environment"""
 
-    pbuilderrc_template = '''\
-# This file was automatically generated by initpbuilder.py.
-# for the possible settings see "man pbuilderrc"
-
-BASETGZ=%(basetgz_dir)s/base.tgz
-BUILDPLACE=%(build_dir)s
-USEPROC=yes
-USEDEVPTS=yes
-BUILDRESULT=%(result_dir)s
-DISTRIBUTION=%(distribution)s
-APTCACHE=%(aptcache_dir)s
-APTCACHEHARDLINK=yes
-REMOVEPACKAGES=lilo
-MIRRORSITE="%(mirrorsite)s"
-OTHERMIRROR="%(othermirror)s"
-BINDMOUNTS="%(extra_pkg_dir)s"
-PKGNAME_LOGFILE=yes
-'''
-
     basetgz_dir = util.filenameproperty("base")
     build_dir = util.filenameproperty("build")
     result_dir = util.filenameproperty("result")
@@ -62,23 +45,18 @@
 
     def init_pbuilder(self, distribution, mirrorsite, extramirrors):
         """Initializes the pbuilder instance"""
-        if not os.path.isabs(self.pbuilderrc):
-            print >>sys.stderr, "pbuilderrc must be an absolute filename"
+        if not os.path.isabs(self.builderconfig):
+            print >>sys.stderr, "builderconfig must be an absolute filename"
             sys.exit(1)
 
-        if os.path.exists(self.pbuilderrc):
-            print >>sys.stderr, ("pbuilderrc %r already exists."
-                                 % self.pbuilderrc)
-            sys.exit(1)
-
         basedir = os.path.dirname(self.pbuilderrc)
         replacements = dict(basedir=basedir,
                             distribution=distribution,
                             mirrorsite=mirrorsite)
 
-        # create the pbuilder directories.  basedir is created implicitly by
+        # create the builder directories.  basedir is created implicitly by
         # creating its subdirectories.
-        for attr in ["basetgz_dir", "build_dir", "result_dir", "aptcache_dir",
+        for attr in ["build_dir", "result_dir", "aptcache_dir",
                      "extra_pkg_dir"]:
             directory = getattr(self, attr)
             replacements[attr] = directory
@@ -91,67 +69,15 @@
             othermirror += " | " + extramirrors
         replacements["othermirror"] = othermirror
 
-        # create the pbuilderrcfile
-        print "creating pbuilderrc:", repr(self.pbuilderrc)
-        util.writefile(self.pbuilderrc, self.pbuilderrc_template % replacements)
-
         # turn the extra-pkg directory into a proper deb archive
         print "turning the extra-pkg dir into a debian archive"
         self.update_extra_pkg_dir()
 
-        # create the base.tgz chroot
-        print "running pbuilder create"
-        run.call(cmdexpand("@root_cmd pbuilder create --configfile $pbuilderrc",
-                           root_cmd=self.root_cmd, pbuilderrc=self.pbuilderrc))
-
-    def update_extra_pkg_dir(self):
-        run.call(cmdexpand("apt-ftparchive packages ."),
-                 stdout=open(os.path.join(self.extra_pkg_dir, "Packages"), "w"),
-                 cwd=self.extra_pkg_dir)
-        release_filename = os.path.join(self.extra_pkg_dir, "Release")
-        run.call(cmdexpand("apt-ftparchive release ."),
-                 stdout=open(release_filename, "w"), cwd=self.extra_pkg_dir)
-        # handle signatures.  remove any existing signature because it
-        # will be invalid now.
-        signature = release_filename + ".gpg"
-        try:
-            os.remove(signature)
-        except OSError:
-            pass
-        if self.release_signing_keyid:
-            run.call(cmdexpand("gpg --detach-sign --armor --local-user=$keyid"
-                               " -o $sig $release",
-                               keyid=self.release_signing_keyid,
-                               sig=release_filename + ".gpg",
-                               release=release_filename)),
-
     def update(self, suppress_output=True, log_info=True):
         """Runs pbuilder update on this pbuilder instance"""
         if log_info:
-            logging.info("Running pbuilder update for %s", self.pbuilderrc)
-        run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder update"
-                           " --configfile $pbuilderrc",
-                           rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc),
-                 suppress_output=suppress_output)
+            logging.info("Update of apt cache is done on every start. skipping ...")
 
-    def add_apt_key(self, keyid):
-        """Runs apt-key add in the chroot"""
-        # Creates a temporary file in extra_pkg_dir (because that's
-        # bind-mounted by default) with a script that adds the desired
-        # key.  The exported key is included in the script file so that
-        # only one file has to be created
-        script = tempfile.NamedTemporaryFile(dir=self.extra_pkg_dir)
-        try:
-            script.write("#! /bin/sh\n")
-            script.write("apt-key add $0\n")
-            script.write("exit\n\n")
-            script.flush()
-            run.call(cmdexpand("gpg --export --armor $keyid", **locals()),
-                     stdout=script.fileno())
-            self.run_script([script.name], logfile=None, save_after_exec=True)
-        finally:
-            script.close()
-
     def build(self, dsc_file, binary_dir=None, logfile=None, bindmounts=(),
               extra_packages=(), extra_env=None):
         """Build a binary packager from a source package
@@ -179,44 +105,23 @@
             args.extend(["--bindmounts", mount])
         for pkg in extra_packages:
             args.extend(["--extrapackages", pkg])
-        run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder build"
-                           " --configfile $pbuilderrc @args"
-                           " --debbuildopts -b $dsc",
-                           rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc,
-                           dsc=dsc_file, args=args),
-                 suppress_output=True,
-                 extra_env=extra_env)
-        if logfile is not None and os.path.exists(logfile):
-            run.call(cmdexpand("gzip -9 $logfile", logfile=logfile))
-        # remove the source package files put into the binary directory
-        # by pbuilder
-        if binary_dir is not None:
-            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))
+        logging.debug(" here we should run sbdmock ...")
+#        run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder build"
+#                           " --configfile $pbuilderrc @args"
+#                           " --debbuildopts -b $dsc",
+#                           rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc,
+#                           dsc=dsc_file, args=args),
+#                 suppress_output=True,
+#                 extra_env=extra_env)
+#        if logfile is not None and os.path.exists(logfile):
+#            run.call(cmdexpand("gzip -9 $logfile", logfile=logfile))
+#        # remove the source package files put into the binary directory
+#        # by pbuilder
+#        if binary_dir is not None:
+#            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))
 
-    def add_binaries_to_extra_pkg(self, filenames, subdirectory="auto"):
-        """Adds binary packages to the extra-pkg directory.
-        The filenames parameter should be sequence of absolute
-        filenames.  The files named will be copied to a subdirectory of
-        the extra-pkg directory which is assumed to reside in the same
-        directory as the pbuilderrc.  The subdirectory is specified with
-        the subdirectory parameter and defaults to 'auto'.  Afterwards,
-        the method generates a Packages file in the directory and runs
-        pbuilder update.  All of this assumes that pbuilder was set up
-        the way bin/initpbuilder.py does.
-        """
-        target_dir = os.path.join(self.extra_pkg_dir, subdirectory)
-        util.ensure_directory(target_dir)
-        for filename in filenames:
-            logging.info("Copying %s into %s", filename, target_dir)
-            shutil.copy(filename, target_dir)
-
-        logging.info("Running apt-ftparchive in %s", self.extra_pkg_dir)
-        self.update_extra_pkg_dir()
-
-        self.update(suppress_output=True, log_info=True)
-
     def run_script(self, script, logfile, bindmounts=(), save_after_exec=False):
         """Execute a script in pbuilder's chroot environment
         Parameters:
@@ -263,3 +168,9 @@
                            rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc,
                            args=args),
                  suppress_output=False)
+
+    def mount(self, bindmounts):
+        for mount in bindmounts:
+            #todo create dir if it doesn't exist
+            run.call(cmdexpand("@rootcmd mount --bind $mount /scratchbox/users/$mount", rootcmd=self.root_cmd, mount=mount))
+            #add mountpoint to a variable to for unmounting later



More information about the Treepkg-commits mailing list