fixed wrong usage of rstrip in loop.py
authorJF Ding <jian-feng.ding@intel.com>
Wed, 18 Jul 2012 10:15:53 +0000 (18:15 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Wed, 18 Jul 2012 10:15:53 +0000 (18:15 +0800)
and many code cleanup, mainly for extra length lines

mic/bootstrap.py
mic/chroot.py
mic/conf.py
mic/creator.py
mic/imager/baseimager.py
mic/imager/livecd.py
mic/imager/loop.py
mic/imager/raw.py
mic/pluginbase.py
mic/rt_util.py

index 9d223d0..0eb2b7a 100644 (file)
@@ -82,7 +82,7 @@ class Bootstrap(object):
 
     def _getRootdir(self):
         if not os.path.exists(self._rootdir):
-            raise errors.BootstrapError("Root dir: %s not exist" % self._rootdir)
+            raise errors.BootstrapError("dir: %s not exist" % self._rootdir)
         return self._rootdir
 
     rootdir = property(fget = lambda self: self._getRootdir(),
@@ -95,7 +95,8 @@ class Bootstrap(object):
             if key == name:
                 self._pkgmgr = cls
         if not self._pkgmgr:
-            raise errors.BootstrapError("Backend: %s can't be loaded correctly" % name)
+            raise errors.BootstrapError("Backend: %s can't be loaded correctly"\
+                                        % name)
 
     pkgmgr = property(fget = lambda self: self._pkgmgr,
                       fset = lambda self, name: self._setPkgmgr(name),
@@ -190,8 +191,9 @@ class Bootstrap(object):
         pkg_manager.setup()
 
         for repo in repolist:
-            if 'proxy' in repo.keys():
-                pkg_manager.addRepository(repo['name'], repo['baseurl'], proxy = repo['proxy'])
+            if 'proxy' in repo:
+                pkg_manager.addRepository(repo['name'], repo['baseurl'],
+                                          proxy=repo['proxy'])
             else:
                 pkg_manager.addRepository(repo['name'], repo['baseurl'])
 
@@ -225,8 +227,9 @@ class Bootstrap(object):
         shutil.rmtree(destdir, ignore_errors = True)
         shutil.copytree(srcdir, destdir)
         # create '/tmp' in chroot
-        if not os.path.exists(os.path.join(os.path.abspath(self.rootdir), "tmp")):
-            os.makedirs(os.path.join(os.path.abspath(self.rootdir), "tmp"))
+        _tmpdir = os.path.join(os.path.abspath(self.rootdir), "tmp")
+        if not os.path.exists(_tmpdir):
+            os.makedirs(_tmpdir)
 
         msger.info("Bootstrap created.")
 
@@ -242,9 +245,11 @@ class Bootstrap(object):
 
         shutil.copyfile("/etc/resolv.conf", chrootdir + "/etc/resolv.conf")
         try:
-            subprocess.call("zypper -n --no-gpg-checks update", preexec_fn=mychroot, shell=True)
+            subprocess.call("zypper -n --no-gpg-checks update",
+                            preexec_fn=mychroot, shell=True)
         except OSError, err:
-            raise errors.BootstrapError("Bootstrap: %s Update fail" % chrootdir)
+            raise errors.BootstrapError("Bootstrap: %s update failed" %\
+                                        chrootdir)
 
     def cleanup(self, name):
         self.rootdir = name
@@ -252,4 +257,5 @@ class Bootstrap(object):
             chroot.cleanup_mounts(self.rootdir)
             shutil.rmtree(self.rootdir, ignore_errors=True)
         except:
-            raise errors.BootstrapError("Bootstrap: %s clean up fail " % self.rootdir)
+            raise errors.BootstrapError("Bootstrap: %s clean up failed" %\
+                                        self.rootdir)
index 2cb8c38..0e7be5d 100644 (file)
@@ -144,7 +144,9 @@ def setup_chrootenv(chrootdir, bindmounts = None):
 
         """Default bind mounts"""
         for pt in BIND_MOUNTS:
-            chrootmounts.append(fs_related.BindChrootMount(pt, chrootdir, None))
+            chrootmounts.append(fs_related.BindChrootMount(pt,
+                                                           chrootdir,
+                                                           None))
 
         chrootmounts.append(fs_related.BindChrootMount("/",
                                                        chrootdir,
@@ -152,10 +154,11 @@ def setup_chrootenv(chrootdir, bindmounts = None):
                                                        "ro"))
 
         for kernel in os.listdir("/lib/modules"):
-            chrootmounts.append(fs_related.BindChrootMount("/lib/modules/"+kernel,
-                                                           chrootdir,
-                                                           None,
-                                                           "ro"))
+            chrootmounts.append(fs_related.BindChrootMount(
+                                                "/lib/modules/"+kernel,
+                                                chrootdir,
+                                                None,
+                                                "ro"))
 
         return chrootmounts
 
index 0cc5797..ec2da56 100644 (file)
@@ -175,9 +175,11 @@ class ConfigMgr(object):
 
                     if val.split(':')[0] in ('file', 'http', 'https', 'ftp'):
                         if repostr.has_key(option):
-                            repostr[option] += "name:%s,baseurl:%s," % (option, val)
+                            repostr[option] += "name:%s,baseurl:%s," % \
+                                                (option, val)
                         else:
-                            repostr[option]  = "name:%s,baseurl:%s," % (option, val)
+                            repostr[option]  = "name:%s,baseurl:%s," % \
+                                                (option, val)
                         continue
 
                 self.bootstraps[name] = repostr
index 9dabaf3..d88d7bd 100644 (file)
@@ -52,7 +52,8 @@ class Creator(cmdln.Cmdln):
 
     def get_optparser(self):
         optparser = cmdln.CmdlnOptionParser(self)
-        optparser.add_option('-d', '--debug', action='store_true', dest='debug',
+        optparser.add_option('-d', '--debug', action='store_true',
+                             dest='debug',
                              help=SUPPRESS_HELP)
         optparser.add_option('-v', '--verbose', action='store_true',
                              dest='verbose',
@@ -127,7 +128,7 @@ class Creator(cmdln.Cmdln):
                     try:
                         largs.append(argv.pop(0))
                     except IndexError:
-                        raise errors.Usage("%s option requires an argument" % arg)
+                        raise errors.Usage("option %s requires arguments" % arg)
 
             else:
                 if arg.startswith("--"):
@@ -169,6 +170,7 @@ class Creator(cmdln.Cmdln):
         if self.options.cachedir is not None:
             configmgr.create['cachedir'] = abspath(self.options.cachedir)
         os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']
+
         if self.options.local_pkgs_path is not None:
             if not os.path.exists(self.options.local_pkgs_path):
                 msger.error('Local pkgs directory: \'%s\' not exist' \
index 784d43f..6d4256d 100644 (file)
@@ -135,7 +135,7 @@ class BaseImageCreator(object):
 
         # No ks provided when called by convertor, so skip the dependency check
         if self.ks:
-            # If we have btrfs partition we need to check that we have toosl for those
+            # If we have btrfs partition we need to check necessary tools
             for part in self.ks.handler.partition.partitions:
                 if part.fstype and part.fstype == "btrfs":
                     self._dep_checks.append("mkfs.btrfs")
@@ -1232,7 +1232,6 @@ class BaseImageCreator(object):
 
     def copy_attachment(self):
         """ Subclass implement it to handle attachment files
-
         NOTE: This needs to be called before unmounting the instroot.
         """
         pass
index 2ffffd3..92da671 100644 (file)
@@ -63,7 +63,8 @@ class LiveImageCreatorBase(LoopImageCreator):
 
         #The default kernel type from kickstart.
         if self.ks:
-            self._default_kernel = kickstart.get_default_kernel(self.ks, "kernel")
+            self._default_kernel = kickstart.get_default_kernel(self.ks,
+                                                                "kernel")
         else:
             self._default_kernel = None
 
@@ -717,6 +718,5 @@ if arch in ("i386", "x86_64"):
     LiveCDImageCreator = x86LiveImageCreator
 elif arch.startswith("arm"):
     LiveCDImageCreator = LiveImageCreatorBase
-
 else:
     raise CreatorError("Architecture not supported!")
index 0a0c242..91b3e9b 100644 (file)
@@ -378,7 +378,8 @@ class LoopImageCreator(BaseImageCreator):
             misc.packing(dstfile, self.__imgdir)
 
         if self.pack_to:
-            mountfp_xml = os.path.splitext(self.pack_to)[0].rstrip('.tar') + ".xml"
+            mountfp_xml = os.path.splitext(self.pack_to)[0]
+            mountfp_xml = misc.strip_end(mountfp_xml, '.tar') + ".xml"
         else:
             mountfp_xml = self.name + ".xml"
         # save mount points mapping file to xml
index adbc19e..8c891d0 100644 (file)
@@ -103,7 +103,7 @@ class RawImageCreator(BaseImageCreator):
         return s
 
     def _create_mkinitrd_config(self):
-        #write  to tell which modules to be included in initrd
+        """write to tell which modules to be included in initrd"""
 
         mkinitrd = ""
         mkinitrd += "PROBE=\"no\"\n"
@@ -442,7 +442,7 @@ class RawImageCreator(BaseImageCreator):
                                  % (self.name,
                                     name,
                                     self.__disk_format))
-                xml += "    <disk file='%s-%s.%s' use='system' format='%s'>\n" \
+                xml += "    <disk file='%s-%s.%s' use='system' format='%s'>\n"\
                        % (self.name,
                           name,
                           self.__disk_format,
index 9ec1ba0..eb7428d 100644 (file)
@@ -44,7 +44,10 @@ class ImagerPlugin(_Plugin):
     mic_plugin_type = "imager"
 
     @classmethod
-    def check_image_exists(self, destdir, apacking=None, images=[], release=None):
+    def check_image_exists(self, destdir, apacking=None,
+                                          images=[],
+                                          release=None):
+
         # if it's a packing file, reset images
         if apacking:
             images = [apacking]
index deb6b9f..04a5291 100644 (file)
@@ -58,7 +58,7 @@ def runmic_in_runtime(runmode, opts, ksfile, argv=None):
             #repostrs = misc.get_repostrs_from_ks(opts['ks'])
             #for item in repostrs:
             #    repolist.append(convert_repostr(item))
-            msger.info("Failed to find propery bootstrap, please check config file")
+            msger.info("cannot find valid bootstrap, please check the config")
             msger.info("Back to native running")
             return
         else:
@@ -129,7 +129,8 @@ def runmic_in_bootstrap(name, argv, opts, ksfile, repolist):
     bootstrap_lst = bootstrap_env.bootstraps
     setattr(bootstrap_env, 'rootdir', name)
     if not bootstrap_lst or not name in bootstrap_lst:
-        msger.info("Creating bootstrap %s under %s" %  (name, bootstrap_env.homedir))
+        msger.info("Creating bootstrap %s under %s" % \
+                   (name, bootstrap_env.homedir))
         bootstrap_env.create(name, repolist)
 
     msger.info("Use bootstrap: %s" % bootstrap_env.rootdir)
@@ -155,7 +156,8 @@ def runmic_in_bootstrap(name, argv, opts, ksfile, repolist):
     # make unique and remain the original order
     lst = sorted(set(lst), key=lst.index)
 
-    bindmounts = ';'.join(map(lambda p: os.path.abspath(os.path.expanduser(p)), lst))
+    bindmounts = ';'.join(map(lambda p: os.path.abspath(os.path.expanduser(p)),
+                              lst))
 
     msger.info("Start mic command in bootstrap")
     bootstrap_env.run(name, argv, cwd, bindmounts)