Change default parameters from mutable type into immutable.
authorHuang Hao <hao.h.huang@intel.com>
Wed, 6 Mar 2013 05:35:24 +0000 (13:35 +0800)
committerGerrit Code Review <gerrit2@otctools.jf.intel.com>
Tue, 12 Mar 2013 05:55:38 +0000 (22:55 -0700)
Get ride of these pylint warnings:

W0102:190,0:cleanup_chrootenv: Dangerous default value [] as argument
W0102: 47,4:ImagerPlugin.check_image_exists: Dangerous default value [] as argument
W0102:109,8:read_kickstart.KSHandlers.__init__: Dangerous default value {} as argument
W0102:708,0:get_repos: Dangerous default value {} as argument
W0102:772,0:get_attachment: Dangerous default value [] as argument
W0102:775,0:get_pre_packages: Dangerous default value [] as argument
W0102:778,0:get_packages: Dangerous default value [] as argument
W0102:781,0:get_groups: Dangerous default value [] as argument
W0102:784,0:get_excluded: Dangerous default value [] as argument
W0102:787,0:get_partitions: Dangerous default value [] as argument
W0102:877,4:BaseImageCreator.install: Dangerous default value {} as argument
W0102:210,4:Bootstrap.create: Dangerous default value [] as argument

Change-Id: Icc04896829ecfb0e2542f4d4755f4adb07b01319

mic/bootstrap.py
mic/chroot.py
mic/imager/baseimager.py
mic/kickstart/__init__.py
mic/pluginbase.py

index 9a433a1..ca42a19 100644 (file)
@@ -207,13 +207,13 @@ class Bootstrap(object):
         except:
             pass
 
-    def create(self, repomd, pkglist, optlist=[]):
+    def create(self, repomd, pkglist, optlist=()):
         try:
             pkgmgr = MiniBackend(self.get_rootdir())
             pkgmgr.arch = self.arch
             pkgmgr.repomd = repomd
-            pkgmgr.optionals = optlist
-            map(pkgmgr.selectPackage, pkglist + optlist)
+            pkgmgr.optionals = list(optlist)
+            map(pkgmgr.selectPackage, pkglist + list(optlist))
             pkgmgr.runInstall()
 
         except (OSError, IOError, errors.CreatorError), err:
index d15fdf4..546c0c8 100644 (file)
@@ -187,12 +187,11 @@ def setup_chrootenv(chrootdir, bindmounts = None, mountparent = True):
 
     return globalmounts
 
-def cleanup_chrootenv(chrootdir, bindmounts = None, globalmounts = []):
+def cleanup_chrootenv(chrootdir, bindmounts=None, globalmounts=()):
     global chroot_lockfd, chroot_lock
 
     def bind_unmount(chrootmounts):
-        chrootmounts.reverse()
-        for b in chrootmounts:
+        for b in reversed(chrootmounts):
             msger.verbose("bind_unmount: %s -> %s" % (b.src, b.dest))
             b.unmount()
 
index 1200079..b9885a0 100644 (file)
@@ -874,7 +874,7 @@ class BaseImageCreator(object):
                     fpath = os.path.join(root, fname)
                     self._attachment.append(fpath)
 
-    def install(self, repo_urls = {}):
+    def install(self, repo_urls=None):
         """Install packages into the install root.
 
         This function installs the packages listed in the supplied kickstart
index f618758..6594436 100644 (file)
@@ -106,7 +106,7 @@ def read_kickstart(path):
     superclass = ksversion.returnClassForVersion(version=using_version)
 
     class KSHandlers(superclass):
-        def __init__(self, mapping={}):
+        def __init__(self):
             superclass.__init__(self, mapping=commandMap[using_version])
             self.prepackages = ksparser.Packages()
             self.attachment = ksparser.Packages()
@@ -705,7 +705,7 @@ def get_default_kernel(ks, default = None):
         return default
     return ks.handler.bootloader.default
 
-def get_repos(ks, repo_urls = {}):
+def get_repos(ks, repo_urls=None):
     repos = {}
     for repo in ks.handler.repo.repoList:
         inc = []
@@ -719,7 +719,7 @@ def get_repos(ks, repo_urls = {}):
         baseurl = repo.baseurl
         mirrorlist = repo.mirrorlist
 
-        if repo.name in repo_urls:
+        if repo_urls and repo.name in repo_urls:
             baseurl = repo_urls[repo.name]
             mirrorlist = None
 
@@ -769,22 +769,22 @@ def convert_method_to_repo(ks):
     except (AttributeError, kserrors.KickstartError):
         pass
 
-def get_attachment(ks, required = []):
-    return ks.handler.attachment.packageList + required
+def get_attachment(ks, required=()):
+    return ks.handler.attachment.packageList + list(required)
 
-def get_pre_packages(ks, required = []):
-    return ks.handler.prepackages.packageList + required
+def get_pre_packages(ks, required=()):
+    return ks.handler.prepackages.packageList + list(required)
 
-def get_packages(ks, required = []):
-    return ks.handler.packages.packageList + required
+def get_packages(ks, required=()):
+    return ks.handler.packages.packageList + list(required)
 
-def get_groups(ks, required = []):
-    return ks.handler.packages.groupList + required
+def get_groups(ks, required=()):
+    return ks.handler.packages.groupList + list(required)
 
-def get_excluded(ks, required = []):
-    return ks.handler.packages.excludedList + required
+def get_excluded(ks, required=()):
+    return ks.handler.packages.excludedList + list(required)
 
-def get_partitions(ks, required = []):
+def get_partitions(ks):
     return ks.handler.partition.partitions
 
 def ignore_missing(ks):
index eb4a0ad..6ac195b 100644 (file)
@@ -45,7 +45,7 @@ class ImagerPlugin(_Plugin):
 
     @classmethod
     def check_image_exists(self, destdir, apacking=None,
-                                          images=[],
+                                          images=(),
                                           release=None):
 
         # if it's a packing file, reset images