code cleanup
authorJF Ding <jian-feng.ding@intel.com>
Mon, 19 Dec 2011 10:13:43 +0000 (18:13 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Mon, 19 Dec 2011 10:13:43 +0000 (18:13 +0800)
mic/imager/raw.py
mic/kickstart/__init__.py
mic/kickstart/custom_commands/desktop.py
mic/kickstart/custom_commands/moblinrepo.py

index 4fa74e3..a600464 100644 (file)
@@ -119,9 +119,10 @@ class RawImageCreator(BaseImageCreator):
 
     def _get_parts(self):
         if not self.ks:
-            raise CreatorError("Failed to get partition info," \
-                               "please check your kickstart setting")
-        #Set a default partition if no partition is given out
+            raise CreatorError("Failed to get partition info, "
+                               "please check your kickstart setting.")
+
+        # Set a default partition if no partition is given out
         if not self.ks.handler.partition.partitions:
             partstr = "part / --size 1900 --ondisk sda --fstype=ext3"
             args = partstr.split()
@@ -129,10 +130,8 @@ class RawImageCreator(BaseImageCreator):
             if pd not in self.ks.handler.partition.partitions:
                 self.ks.handler.partition.partitions.append(pd)
 
-        #list of partitions from kickstart file
-        parts = kickstart.get_partitions(self.ks)
-
-        return parts
+        # partitions list from kickstart file
+        return kickstart.get_partitions(self.ks)
 
     def get_diskinfo(self):
 
@@ -163,8 +162,10 @@ class RawImageCreator(BaseImageCreator):
                     break
                 else:
                     found = False
+
             if not found:
                 self._diskinfo.append({ 'name': disk, 'size': size })
+
         return self._diskinfo
 
     #
@@ -421,9 +422,14 @@ class RawImageCreator(BaseImageCreator):
                 meter = progress.TextMeter()
                 meter.start(size=disk_size,
                             text="Generating disk signature for %s-%s.%s" \
-                                 % (self.name,name,self.__disk_format))
+                                 % (self.name,
+                                    name,
+                                    self.__disk_format))
                 xml += "    <disk file='%s-%s.%s' use='system' format='%s'>\n" \
-                       % (self.name,name, self.__disk_format, self.__disk_format)
+                       % (self.name,
+                          name,
+                          self.__disk_format,
+                          self.__disk_format)
 
                 try:
                     import hashlib
@@ -457,7 +463,10 @@ class RawImageCreator(BaseImageCreator):
         else:
             for name in self.__disks.keys():
                 xml += "    <disk file='%s-%s.%s' use='system' format='%s'/>\n"\
-                       %(self.name,name, self.__disk_format, self.__disk_format)
+                       %(self.name,
+                         name,
+                         self.__disk_format,
+                         self.__disk_format)
 
         xml += "  </storage>\n"
         xml += "</image>\n"
index 3fadce3..d8c264e 100644 (file)
@@ -177,7 +177,9 @@ class TimezoneConfig(KickstartConfig):
         try:
             shutil.copyfile(tz_source, tz_dest)
         except (IOError, OSError), (errno, msg):
-            raise errors.KickstartError("Error copying timezone info from '%s' to '%s': %s" %(tz_source, tz_dest, msg))
+            raise errors.KickstartError("Error copying timezone info from "
+                                        "'%s' to '%s': %s" \
+                                        % (tz_source, tz_dest, msg))
 
 
 class AuthConfig(KickstartConfig):
@@ -214,7 +216,8 @@ class RootPasswordConfig(KickstartConfig):
     def set_unencrypted(self, password):
         for p in ("/bin/echo", "/usr/sbin/chpasswd"):
             if not os.path.exists("%s/%s" %(self.instroot, p)):
-                raise errors.KsError("Unable to set unencrypted password due to lack of %s" % p)
+                raise errors.KsError("Unable to set unencrypted password due "
+                                     "to lack of %s" % p)
 
         p1 = subprocess.Popen(["/bin/echo", "root:%s" %password],
                               stdout = subprocess.PIPE,
@@ -243,7 +246,8 @@ class UserConfig(KickstartConfig):
     def set_unencrypted_passwd(self, user, password):
         for p in ("/bin/echo", "/usr/sbin/chpasswd"):
             if not os.path.exists("%s/%s" %(self.instroot, p)):
-                raise errors.KsError("Unable to set unencrypted password due to lack of %s" % p)
+                raise errors.KsError("Unable to set unencrypted password due "
+                                     "to lack of %s" % p)
 
         p1 = subprocess.Popen(["/bin/echo", "%s:%s" %(user, password)],
                               stdout = subprocess.PIPE,
@@ -268,13 +272,16 @@ class UserConfig(KickstartConfig):
             os.close(dev_null)
             if userconfig.password not in (None, ""):
                 if userconfig.isCrypted:
-                    self.set_encrypted_passwd(userconfig.name, userconfig.password)
+                    self.set_encrypted_passwd(userconfig.name,
+                                              userconfig.password)
                 else:
-                    self.set_unencrypted_passwd(userconfig.name, userconfig.password)
+                    self.set_unencrypted_passwd(userconfig.name,
+                                                userconfig.password)
             else:
                 self.set_empty_passwd(userconfig.name)
         else:
-            raise errors.KsError("Invalid kickstart command: %s" % userconfig.__str__())
+            raise errors.KsError("Invalid kickstart command: %s" \
+                                 % userconfig.__str__())
 
     def apply(self, user):
         for userconfig in user.userList:
@@ -351,6 +358,7 @@ class MoblinRepoConfig(KickstartConfig):
                 baseurl = repo.baseurl
             if repo.mirrorlist:
                 mirrorlist = repo.mirrorlist
+
         elif type == "debuginfo":
             if repo.baseurl:
                 if repo.baseurl.endswith("/"):
@@ -358,17 +366,22 @@ class MoblinRepoConfig(KickstartConfig):
                 else:
                     baseurl = os.path.dirname(repo.baseurl)
                 baseurl += "/debug"
+
             if repo.mirrorlist:
                 variant = repo.mirrorlist[repo.mirrorlist.find("$"):]
                 mirrorlist = repo.mirrorlist[0:repo.mirrorlist.find("$")]
                 mirrorlist += "debug" + "-" + variant
+
         elif type == "source":
             if repo.baseurl:
                 if repo.baseurl.endswith("/"):
-                    baseurl = os.path.dirname(os.path.dirname(os.path.dirname(repo.baseurl)))
+                    baseurl = os.path.dirname(
+                                 os.path.dirname(
+                                    os.path.dirname(repo.baseurl)))
                 else:
                     baseurl = os.path.dirname(os.path.dirname(repo.baseurl))
                 baseurl += "/source"
+
             if repo.mirrorlist:
                 variant = repo.mirrorlist[repo.mirrorlist.find("$"):]
                 mirrorlist = repo.mirrorlist[0:repo.mirrorlist.find("$")]
@@ -418,7 +431,10 @@ class MoblinRepoConfig(KickstartConfig):
         if repodata:
             for repo in repodata:
                 if repo['repokey']:
-                    runner.quiet(['rpm', "--root=%s" % self.instroot, "--import", repo['repokey']])
+                    runner.quiet(['rpm',
+                                  "--root=%s" % self.instroot,
+                                  "--import",
+                                  repo['repokey']])
 
 class RPMMacroConfig(KickstartConfig):
     """A class to apply the specified rpm macros to the filesystem"""
@@ -780,17 +796,18 @@ def resolve_groups(creatoropts, repometadata):
     ks = creatoropts['ks']
 
     for repo in repometadata:
-        """ Mustn't replace group with package list if repo is ready for the corresponding package manager """
+        """ Mustn't replace group with package list if repo is ready for the
+            corresponding package manager.
+        """
+
         if iszypp and repo["patterns"]:
             continue
         if not iszypp and repo["comps"]:
             continue
 
-        """
-            But we also must handle such cases, use zypp but repo only has comps,
-            use yum but repo only has patterns, use zypp but use_comps is true,
-            use yum but use_comps is false.
-        """
+        # But we also must handle such cases, use zypp but repo only has comps,
+        # use yum but repo only has patterns, use zypp but use_comps is true,
+        # use yum but use_comps is false.
         groupfile = None
         if iszypp and repo["comps"]:
             groupfile = repo["comps"]
@@ -804,7 +821,9 @@ def resolve_groups(creatoropts, repometadata):
             while True:
                 if i >= len(ks.handler.packages.groupList):
                     break
-                pkglist = get_pkglist_handler(ks.handler.packages.groupList[i].name, groupfile)
+                pkglist = get_pkglist_handler(
+                                        ks.handler.packages.groupList[i].name,
+                                        groupfile)
                 if pkglist:
                     del ks.handler.packages.groupList[i]
                     for pkg in pkglist:
index eceb718..ab3f82f 100644 (file)
@@ -22,7 +22,12 @@ from pykickstart.errors import *
 from pykickstart.options import *
 
 class Moblin_Desktop(KickstartCommand):
-    def __init__(self, writePriority=0, defaultdesktop=None, defaultdm=None, autologinuser="meego", session=None):
+    def __init__(self, writePriority=0,
+                       defaultdesktop=None,
+                       defaultdm=None,
+                       autologinuser="meego",
+                       session=None):
+
         KickstartCommand.__init__(self, writePriority)
 
         self.__new_version = False
@@ -58,10 +63,22 @@ class Moblin_Desktop(KickstartCommand):
             op = KSOptionParser()
             self.__new_version = True
 
-        op.add_option("--defaultdesktop", dest="defaultdesktop", action="store", type="string", nargs=1)
-        op.add_option("--autologinuser", dest="autologinuser", action="store", type="string", nargs=1)
-        op.add_option("--defaultdm", dest="defaultdm", action="store", type="string", nargs=1)
-        op.add_option("--session", dest="session", action="store", type="string", nargs=1)
+        op.add_option("--defaultdesktop", dest="defaultdesktop",
+                                          action="store",
+                                          type="string",
+                                          nargs=1)
+        op.add_option("--autologinuser", dest="autologinuser",
+                                         action="store",
+                                         type="string",
+                                         nargs=1)
+        op.add_option("--defaultdm", dest="defaultdm",
+                                     action="store",
+                                     type="string",
+                                     nargs=1)
+        op.add_option("--session", dest="session",
+                                   action="store",
+                                   type="string",
+                                   nargs=1)
         return op
 
     def parse(self, args):
@@ -71,7 +88,8 @@ class Moblin_Desktop(KickstartCommand):
             (opts, extra) = self.op.parse_args(args=args)
 
         if extra:
-            mapping = {"command": "desktop", "options": extra}
-            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping)
+            m = _("Unexpected arguments to %(command)s command: %(options)s") \
+                  % {"command": "desktop", "options": extra}
+            raise KickstartValueError, formatErrorMsg(self.lineno, msg=m)
 
         self._setToSelf(self.op, opts)
index 420b126..f2da6fe 100644 (file)
@@ -88,10 +88,10 @@ class Moblin_Repo(F8_Repo):
                       default=False)
         op.add_option("--proxy", type="string", action="store", dest="proxy",
                       default=None, nargs=1)
-        op.add_option("--proxyuser", type="string", action="store", dest="proxy_username",
-                      default=None, nargs=1)
-        op.add_option("--proxypasswd", type="string", action="store", dest="proxy_password",
-                      default=None, nargs=1)
+        op.add_option("--proxyuser", type="string", action="store",
+                      dest="proxy_username", default=None, nargs=1)
+        op.add_option("--proxypasswd", type="string", action="store",
+                      dest="proxy_password", default=None, nargs=1)
         op.add_option("--debuginfo", action="store_true", dest="debuginfo",
                       default=False)
         op.add_option("--source", action="store_true", dest="source",
@@ -100,8 +100,8 @@ class Moblin_Repo(F8_Repo):
                       default=False)
         op.add_option("--gpgkey", type="string", action="store", dest="gpgkey",
                       default=None, nargs=1)
-        op.add_option("--ssl_verify", type="string", action="store", dest="ssl_verify",
-                      default="yes")
+        op.add_option("--ssl_verify", type="string", action="store",
+                      dest="ssl_verify", default="yes")
         op.add_option("--priority", type="int", action="store", dest="priority",
                       default=None)
         return op