commit 4ce4d030f02925aafa12599b0d2d1f6531a9e591
Author: Yi Yang <[email protected]>
Date:   Thu Feb 10 11:51:25 2011 +0800

    Should't call find_binary_path on importing mic/imgcreate/fs.py
    
    Note: fix bug #13391

diff --git a/mic/appcreate/appliance.py b/mic/appcreate/appliance.py
index cb5ef2b..058ddba 100644
--- a/mic/appcreate/appliance.py
+++ b/mic/appcreate/appliance.py
@@ -275,6 +275,7 @@ class ApplianceImageCreator(ImageCreator):
 
         # Set MBR
         mbrsize = os.stat("%s/usr/share/syslinux/mbr.bin" % 
self._instroot)[stat.ST_SIZE]
+        ddcmd = find_binary_path("dd")
         rc = subprocess.call([ddcmd, "if=%s/usr/share/syslinux/mbr.bin" % 
self._instroot, "of=" + loopdev])
         if rc != 0:
             raise MountError("Unable to set MBR to %s" % loopdev)
diff --git a/mic/chroot/chroot.py b/mic/chroot/chroot.py
index aec51d5..eff3756 100755
--- a/mic/chroot/chroot.py
+++ b/mic/chroot/chroot.py
@@ -155,10 +155,12 @@ def setup_chrootenv(chrootdir, bindmounts = None):
 def cleanup_mounts(chrootdir):
     checkpoints = ["/proc/sys/fs/binfmt_misc", "/proc", "/sys", "/dev/pts", 
"/dev/shm", "/dev", "/var/lib/dbus", "/var/run/dbus"]
     dev_null = os.open("/dev/null", os.O_WRONLY)
+    umountcmd = find_binary_path("umount")
     for point in checkpoints:
         print point
         args = [ umountcmd, "-l", chrootdir + point ]
         subprocess.call(args, stdout=dev_null, stderr=dev_null)
+    catcmd = find_binary_path("cat")
     args = [ catcmd, "/proc/mounts" ]
     proc_mounts = subprocess.Popen(args, stdout=subprocess.PIPE, 
stderr=dev_null)
     outputs = proc_mounts.communicate()[0].strip().split("\n")
@@ -409,6 +411,7 @@ def chroot(chrootdir, bindmounts = None, execute = 
"/bin/bash"):
         if not os.path.exists(ftc):
             continue
 
+        filecmd = find_binary_path("file")
         initp1 = subprocess.Popen([filecmd, ftc], stdout=subprocess.PIPE, 
stderr=dev_null)
         fileOutput = initp1.communicate()[0].strip().split("\n")
         
diff --git a/mic/imgcreate/bootstrap.py b/mic/imgcreate/bootstrap.py
index 98f7013..db628da 100644
--- a/mic/imgcreate/bootstrap.py
+++ b/mic/imgcreate/bootstrap.py
@@ -49,6 +49,8 @@ def get_repo_metadata(repo, cachedir, reponame, proxies = {}, 
arch = None):
     if not repo:
         raise BootstrapError("Repository can't be empty string.")
     
+    gunzip = find_binary_path('gunzip')
+    bunzip2 = find_binary_path('bunzip2')
     makedirs(cachedir + "/" + reponame)
     url = str(repo + "/repodata/repomd.xml")
     filename = str("%s/%s/repomd.xml" % (cachedir, reponame))
@@ -606,6 +608,7 @@ def clean_files(pattern, dir):
 def copy_mic2(bootstrap, bin_path = "/usr/bin", python_lib_path = 
"/usr/lib/python2.6/site-packages"):
         bootstrap_mic = bootstrap + "/usr/lib/python2.6/site-packages/mic"
         shutil.rmtree(bootstrap_mic, ignore_errors = True)
+        copycmd = find_binary_path("cp")
         subprocess.call([copycmd, "-af", python_lib_path + "/mic", 
os.path.dirname(bootstrap_mic)])
         clean_files(".*\.py[co]$", bootstrap_mic)
         for file in glob.glob(bootstrap + "/usr/bin/mic-*"):
diff --git a/mic/imgcreate/creator.py b/mic/imgcreate/creator.py
index f7b02f8..f01c2ec 100644
--- a/mic/imgcreate/creator.py
+++ b/mic/imgcreate/creator.py
@@ -969,6 +969,7 @@ class ImageCreator(object):
             rc = None
             img_location = os.path.join(self._outdir,self._img_name)
             if self.__img_compression_method == "bz2":
+                bzip2 = find_binary_path('bzip2')
                 print "Compressing %s with bzip2. Please wait..." % 
img_location
                 rc = subprocess.call([bzip2, "-f", img_location])
                 if rc:
@@ -989,6 +990,7 @@ class ImageCreator(object):
             makedirs(destdir)
 
         # Ensure all data is flushed to _outdir
+        synccmd = find_binary_path("sync")
         subprocess.call([synccmd])
 
         for f in os.listdir(self._outdir):
@@ -1286,6 +1288,7 @@ class FsImageCreator(ImageCreator):
         print "Moving %s to %s, please be patient to wait (it is slow if they 
are on different file systems/partitons/disks)" \
                % (self._instroot, destdir + "/" + self.name)
 
+        copycmd = find_binary_path("cp")
         args = [ copycmd, "-af", self._instroot + "/dev", 
os.path.dirname(self._instroot) ]
         subprocess.call(args)
         shutil.rmtree(self._instroot + "/dev", ignore_errors = True)
diff --git a/mic/imgcreate/fs.py b/mic/imgcreate/fs.py
index 69a361c..7da4517 100644
--- a/mic/imgcreate/fs.py
+++ b/mic/imgcreate/fs.py
@@ -85,21 +85,6 @@ def find_binary_path(binary):
             return bin_path
     raise CreatorError("Command '%s' is not available." % binary)
 
-
-""" Get often-used bianry paths here """
-bunzip2 = find_binary_path('bunzip2')
-gunzip = find_binary_path('gunzip')
-bzip2 = find_binary_path('bzip2')
-copycmd = find_binary_path("cp")
-ddcmd = find_binary_path("dd")
-mountcmd = find_binary_path("mount")
-umountcmd = find_binary_path("umount")
-filecmd = find_binary_path("file")
-catcmd = find_binary_path("cat")
-synccmd = find_binary_path("sync")
-losetupcmd = find_binary_path("losetup")
-modprobecmd = find_binary_path("modprobe")
-
 def makedirs(dirname):
     """A version of os.makedirs() that doesn't throw an
     exception if the leaf directory already exists.
@@ -163,10 +148,13 @@ class BindChrootMount:
         self.dest = self.root + "/" + dest
 
         self.mounted = False
+        self.mountcmd = find_binary_path("mount")
+        self.umountcmd = find_binary_path("umount")
 
     def ismounted(self):
         ret = False
         dev_null = os.open("/dev/null", os.O_WRONLY)
+        catcmd = find_binary_path("cat")
         args = [ catcmd, "/proc/mounts" ]
         proc_mounts = subprocess.Popen(args, stdout=subprocess.PIPE, 
stderr=dev_null)
         outputs = proc_mounts.communicate()[0].strip().split("\n")
@@ -186,12 +174,12 @@ class BindChrootMount:
             return
 
         makedirs(self.dest)
-        rc = subprocess.call([mountcmd, "--bind", self.src, self.dest])
+        rc = subprocess.call([self.mountcmd, "--bind", self.src, self.dest])
         if rc != 0:
             raise MountError("Bind-mounting '%s' to '%s' failed" %
                              (self.src, self.dest))
         if self.option:
-            rc = subprocess.call([mountcmd, "-o", "remount,%s" % self.option, 
self.dest])
+            rc = subprocess.call([self.mountcmd, "-o", "remount,%s" % 
self.option, self.dest])
             if rc != 0:
                 raise MountError("Bind-remounting '%s' failed" % self.dest)
         self.mounted = True
@@ -201,7 +189,7 @@ class BindChrootMount:
             return
 
         if self.ismounted():
-            subprocess.call([umountcmd, "-l", self.dest])
+            subprocess.call([self.umountcmd, "-l", self.dest])
         self.mounted = False
 
 class LoopbackMount:
@@ -209,6 +197,7 @@ class LoopbackMount:
     def __init__(self, lofile, mountdir, fstype = None):
         self.diskmount = DiskMount(LoopbackDisk(lofile,size = 
0),mountdir,fstype,rmmountdir = True)
         self.losetup = False
+        self.losetupcmd = find_binary_path("losetup")
 
     def cleanup(self):
         self.diskmount.cleanup()
@@ -218,7 +207,7 @@ class LoopbackMount:
 
     def lounsetup(self):
         if self.losetup:
-            rc = subprocess.call([losetupcmd, "-d", self.loopdev])
+            rc = subprocess.call([self.losetupcmd, "-d", self.loopdev])
             self.losetup = False
             self.loopdev = None
 
@@ -226,7 +215,7 @@ class LoopbackMount:
         if self.losetup:
             return
 
-        losetupProc = subprocess.Popen([losetupcmd, "-f"],
+        losetupProc = subprocess.Popen([self.losetupcmd, "-f"],
                                        stdout=subprocess.PIPE)
         losetupOutput = losetupProc.communicate()[0]
 
@@ -236,7 +225,7 @@ class LoopbackMount:
 
         self.loopdev = losetupOutput.split()[0]
 
-        rc = subprocess.call([losetupcmd, self.loopdev, self.lofile])
+        rc = subprocess.call([self.losetupcmd, self.loopdev, self.lofile])
         if rc != 0:
             raise MountError("Failed to allocate loop device for '%s'" %
                              self.lofile)
@@ -336,6 +325,7 @@ class LoopbackDisk(Disk):
     def __init__(self, lofile, size):
         Disk.__init__(self, size)
         self.lofile = lofile
+        self.losetupcmd = find_binary_path("losetup")
 
     def fixed(self):
         return False
@@ -347,7 +337,7 @@ class LoopbackDisk(Disk):
         if self.device is not None:
             return
 
-        losetupProc = subprocess.Popen([losetupcmd, "-f"],
+        losetupProc = subprocess.Popen([self.losetupcmd, "-f"],
                                        stdout=subprocess.PIPE)
         losetupOutput = losetupProc.communicate()[0]
 
@@ -358,7 +348,7 @@ class LoopbackDisk(Disk):
         device = losetupOutput.split()[0]
 
         logging.debug("Losetup add %s mapping to %s"  % (device, self.lofile))
-        rc = subprocess.call([losetupcmd, device, self.lofile])
+        rc = subprocess.call([self.losetupcmd, device, self.lofile])
         if rc != 0:
             raise MountError("Failed to allocate loop device for '%s'" %
                              self.lofile)
@@ -368,7 +358,7 @@ class LoopbackDisk(Disk):
         if self.device is None:
             return
         logging.debug("Losetup remove %s" % self.device)
-        rc = subprocess.call([losetupcmd, "-d", self.device])
+        rc = subprocess.call([self.losetupcmd, "-d", self.device])
         self.device = None
 
 
@@ -440,6 +430,8 @@ class DiskMount(Mount):
             self.mkfscmd = find_binary_path("mkfs." + self.fstype)
         else:
             self.mkfscmd = None
+        self.mountcmd = find_binary_path("mount")
+        self.umountcmd = find_binary_path("umount")
 
     def cleanup(self):
         Mount.cleanup(self)
@@ -448,8 +440,9 @@ class DiskMount(Mount):
     def unmount(self):
         if self.mounted:
             logging.debug("Unmounting directory %s" % self.mountdir)
+            synccmd = find_binary_path("sync")
             subprocess.call([synccmd]) # sync the data on this mount point
-            rc = subprocess.call([umountcmd, "-l", self.mountdir])
+            rc = subprocess.call([self.umountcmd, "-l", self.mountdir])
             if rc == 0:
                 self.mounted = False
             else:
@@ -479,9 +472,9 @@ class DiskMount(Mount):
 
         logging.debug("Mounting %s at %s" % (self.disk.device, self.mountdir))
         if options:
-            args = [ mountcmd, "-o", options, self.disk.device, self.mountdir ]
+            args = [ self.mountcmd, "-o", options, self.disk.device, 
self.mountdir ]
         else:
-            args = [ mountcmd, self.disk.device, self.mountdir ]
+            args = [ self.mountcmd, self.disk.device, self.mountdir ]
         if self.fstype:
             args.extend(["-t", self.fstype])
 
@@ -924,6 +917,7 @@ def load_module(module):
     if not found:
         print "Loading %s..." % module
         dev_null = os.open("/dev/null", os.O_WRONLY)
+        modprobecmd = find_binary_path("modprobe")
         modprobe = subprocess.Popen([modprobecmd, module],
                      stdout=dev_null, stderr=dev_null)
         os.waitpid(modprobe.pid, 0)
@@ -935,6 +929,7 @@ def myurlgrab(url, filename, proxies):
         file = url.replace("file://", "")
         if not os.path.exists(file):
             raise CreatorError("URLGrabber error: can't find file %s" % file)
+        copycmd = find_binary_path("cp")
         subprocess.call([copycmd, "-f", file, filename])
     else:
         try:
diff --git a/mic/imgcreate/live.py b/mic/imgcreate/live.py
index 072396d..dd0ea6e 100644
--- a/mic/imgcreate/live.py
+++ b/mic/imgcreate/live.py
@@ -163,6 +163,7 @@ class LiveImageCreatorBase(LoopImageCreator):
         """Support Image Convertor"""
         if self.actasconvertor:
             if os.path.exists(base_on) and not os.path.isfile(base_on):
+                ddcmd = find_binary_path("dd")
                 args = [ ddcmd, "if=%s" % base_on, "of=%s" % self._image ]
                 print "dd %s -> %s" % (base_on, self._image)
                 rc = subprocess.call(args)
@@ -936,6 +937,8 @@ class LiveUSBImageCreator(LiveImageCreator):
             raise CreatorError("Can't have an swap overlay of 2048MB or 
greater on VFAT")
 
         livesize = get_file_size(isodir + "/LiveOS")
+        mountcmd = find_binary_path("mount")
+        umountcmd = find_binary_path("umount")
         if skipcompress:
             tmpmnt = self._mkdtemp("squashfs-mnt")
             rc = subprocess.call([mountcmd, "-o", "loop", isodir + 
"/LiveOS/squashfs.img", tmpmnt]);
@@ -989,6 +992,7 @@ class LiveUSBImageCreator(LiveImageCreator):
                 usblabel = "UUID=%s" % diskmount.uuid
                 overlaysuffix = "-%s-%s" % (diskmount.fslabel, diskmount.uuid)
 
+            copycmd = find_binary_path("cp")
             args = [copycmd, "-Rf", isodir + "/isolinux", usbmnt + "/syslinux"]
             rc = subprocess.call(args)
             if rc:
@@ -1023,6 +1027,7 @@ class LiveUSBImageCreator(LiveImageCreator):
             if kernelargs:
                 text = text.replace("liveimg", "liveimg " + kernelargs)
 
+            ddcmd = find_binary_path("dd")
             if overlaysizemb > 0:
                 print "Initializing persistent overlay file"
                 overfile = "overlay" + overlaysuffix
@@ -1145,6 +1150,7 @@ class LiveUSBImageCreator(LiveImageCreator):
         """Support Image Convertor"""
         if self.actasconvertor:
             if os.path.exists(base_on) and not os.path.isfile(base_on):
+                ddcmd = find_binary_path("dd")
                 args = [ ddcmd, "if=%s" % base_on, "of=%s" % self._image ]
                 print "dd %s -> %s" % (base_on, self._image)
                 rc = subprocess.call(args)
diff --git a/mic/imgcreate/misc.py b/mic/imgcreate/misc.py
index f3872ad..6351ed5 100644
--- a/mic/imgcreate/misc.py
+++ b/mic/imgcreate/misc.py
@@ -69,6 +69,7 @@ def get_image_type(path):
         return maptab["vdi"]
 
     dev_null = os.open("/dev/null", os.O_WRONLY)
+    filecmd = find_binary_path("file")
     args = [ filecmd, path ]
     file = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=dev_null)
     output = file.communicate()[0]
@@ -160,6 +161,7 @@ def oldmycopytree(src, dst, symlinks=False):
     class MyError(EnvironmentError):
         pass
 
+    copycmd = find_binary_path("cp")
     names = os.listdir(src)
     if not os.path.exists(dst):
         os.makedirs(dst)
@@ -220,6 +222,7 @@ def mycopytree(src, dst):
 def myxcopytree(src, dst):
     dev_null = os.open("/dev/null", os.O_WRONLY)
     dirnames = os.listdir(src)
+    copycmd = find_binary_path("cp")
     for dir in dirnames:
         args = [ copycmd, "-af", src + "/" + dir, dst ]
         subprocess.call(args, stdout=dev_null, stderr=dev_null)
@@ -611,9 +614,11 @@ def get_uncompressed_data_from_url(url, filename, proxies):
     suffix = None
     if filename.endswith(".gz"):
         suffix = ".gz"
+        gunzip = find_binary_path('gunzip')
         subprocess.call([gunzip, "-f", filename])
     elif filename.endswith(".bz2"):
         suffix = ".bz2"
+        bunzip2 = find_binary_path('bunzip2')
         subprocess.call([bunzip2, "-f", filename])
     if suffix:
         filename = filename.replace(suffix, "")
@@ -946,6 +951,7 @@ def get_pkglist_in_group(group, patterns):
 def is_statically_linked(binary):
     ret = False
     dev_null = os.open("/dev/null", os.O_WRONLY)
+    filecmd = find_binary_path("file")
     args = [ filecmd, binary ]
     file = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=dev_null)
     output = file.communicate()[0]
@@ -957,8 +963,10 @@ def is_statically_linked(binary):
 def setup_qemu_emulator(rootdir, arch):
     # mount binfmt_misc if it doesn't exist
     if not os.path.exists("/proc/sys/fs/binfmt_misc"):
+        modprobecmd = find_binary_path("modprobe")
         subprocess.call([modprobecmd, "binfmt_misc"])
     if not os.path.exists("/proc/sys/fs/binfmt_misc/register"):
+        mountcmd = find_binary_path("mount")
         subprocess.call([mountcmd, "-t", "binfmt_misc", "none", 
"/proc/sys/fs/binfmt_misc"])
 
     # qemu_emulator is a special case, we can't use find_binary_path
_______________________________________________
MeeGo-distribution-tools mailing list
[email protected]
http://lists.meego.com/listinfo/meego-distribution-tools

Reply via email to