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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Apr 16 12:53:30 CEST 2010


Author: bricks
Date: 2010-04-16 12:53:30 +0200 (Fri, 16 Apr 2010)
New Revision: 285

Modified:
   branches/scratchbox/treepkg/sbuilder.py
Log:
run_script does not work for sbdmock -> deactivated
mount and unmount of directories is now possible -> necessary for extra-pkgs


Modified: branches/scratchbox/treepkg/sbuilder.py
===================================================================
--- branches/scratchbox/treepkg/sbuilder.py	2010-04-16 09:31:16 UTC (rev 284)
+++ branches/scratchbox/treepkg/sbuilder.py	2010-04-16 10:53:30 UTC (rev 285)
@@ -39,17 +39,21 @@
         worry about quoting.
         """
         if not os.path.exists(builderconfig):
-            raise RuntimeError("Config file %s for sbdmock does not exist.")
+            raise RuntimeError("Config file %s for sbdmock does not exist.",
+                  builderconfig)
+
+        if not os.path.isabs(self.builderconfig):
+            raise RuntimeError("Config file %s must be an absolute filename.",
+                  builderconfig)
+
         self.builderconfig = builderconfig
         self.root_cmd = root_cmd
         self.release_signing_keyid = release_signing_keyid
         self.base_dir = os.path.dirname(self.builderconfig)
+        self.mounted_dirs = []
 
     def init_pbuilder(self, distribution, mirrorsite, extramirrors):
-        """Initializes the pbuilder instance"""
-        if not os.path.isabs(self.builderconfig):
-            print >>sys.stderr, "builderconfig must be an absolute filename"
-            sys.exit(1)
+        """Initializes the builder instance"""
 
         basedir = os.path.dirname(self.pbuilderrc)
         replacements = dict(basedir=basedir,
@@ -66,10 +70,10 @@
             util.ensure_directory(directory)
 
         # build OTHERMIRROR value.  We always include the extra-pkg dir.
-        othermirror = "deb file://%(extra_pkg_dir)s ./" % replacements
-        if extramirrors:
-            othermirror += " | " + extramirrors
-        replacements["othermirror"] = othermirror
+#        othermirror = "deb file://%(extra_pkg_dir)s ./" % replacements
+#        if extramirrors:
+#            othermirror += " | " + extramirrors
+#        replacements["othermirror"] = othermirror
 
         # turn the extra-pkg directory into a proper deb archive
         print "turning the extra-pkg dir into a debian archive"
@@ -105,28 +109,39 @@
         if binary_dir is not None:
             args.extend(["--resultdir=%s" % binary_dir])
             util.ensure_directory(binary_dir)
-#        for mount in bindmounts:
-#            args.extend(["--bindmounts", mount])
+        if bindmounts:
+            self.mount(bindmounts)
 #        for pkg in extra_packages:
 #            args.extend(["--extrapackages", pkg])
+        
+	logging.debug("Mointing extra-pkg apt repository")
+                
+        self.mount([self.extra_pkg_dir])
+
         logging.debug("Starting build process with sbdmock ...")
 
+
         cmd = cmdexpand("/usr/bin/sbdmock --cleanbuilddir"
                            " --config=$builderconfig"
-#                           " --dbo=" # aren't debian build options setable in treepkg.cfg?
+#                           " --dbo=" # aren't build options setable in treepkg.cfg?
                            " -u -b $dsc @args",
                            builderconfig=self.builderconfig,
                            dsc=dsc_file, args=args)
         logging.debug("sbdmock cmd: %s" % cmd)
-        run.call(cmd, 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))
+        
+        try:
+            run.call(cmd, 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 (BR: not sure if this is necessary for sbdmock)
+            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))
+        finally:
+            # remove all mounted directories
+            self.umount_all()
 
     def run_script(self, script, logfile, bindmounts=(), save_after_exec=False):
         """Execute a script in pbuilder's chroot environment
@@ -142,26 +157,8 @@
                               modifications are available in subsequent
                               uses of the pbuilder instance.
         """
-        logging.info("Running pbuilder execute on %s", script)
-        args = []
-        if logfile:
-            args.extend(["--logfile", logfile])
-            # create the logfile.  This makes sure that it is owned by
-            # the user the tree packager is running as and not root, as
-            # would be the case when it is created indirectly by
-            # pbuilder
-            open(logfile, "w").close()
-        for mount in bindmounts:
-            args.extend(["--bindmounts", mount])
-        if save_after_exec:
-            args.append("--save-after-exec")
+        logging.error("It isn't possible to run scripts withon sbdmock.")
 
-        run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder execute"
-                           " --configfile $pbuilderrc @args -- @script",
-                           rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc,
-                           args=args, script=script),
-                 suppress_output=False)
-
     def login(self, bindmounts=(), save_after_login=False):
         """Start an interactive shell in the pbuilder environment"""
         args = []
@@ -177,6 +174,20 @@
 
     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))
+            mount_dir = "/scratchbox/users/%s/%s" % (util.getuser(), mount)
+            util.ensure_directory(mount_dir)
+            logging.debug("Mounting %s to %s" % (mount, mount_dir))
+            run.call(cmdexpand("@rootcmd mount --bind $mount $mountdir", rootcmd=self.root_cmd, mount=mount, mountdir=mount_dir))
+
             #add mountpoint to a variable to for unmounting later
+            self.mounted_dirs.append(mount_dir)
+
+    def umount(self, mounts):
+        for mount in mounts:
+            logging.debug("Unmounting %s" % mount)
+            run.call(cmdexpand("@rootcmd umount $dir", rootcmd=self.root_cmd, dir=mount))
+            self.mounted_dirs.remove(mount)
+
+    def umount_all(self):
+        mounts = self.mounted_dirs[:]
+        self.umount(mounts)



More information about the Treepkg-commits mailing list