Code cleanup
authorEd Bartosh <eduard.bartosh@intel.com>
Mon, 3 Jun 2013 11:01:23 +0000 (14:01 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Mon, 3 Jun 2013 11:01:23 +0000 (14:01 +0300)
Fixed unused imports, using .keys() method for dict and other small code
style issues.

Change-Id: I9c66e60ddd3f879f51f8991c345e2a006b3b7360
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
common/builddata.py
common/repomaker.py
job_pre_release_obs.py
tests/test_backenddb.py
tests/test_builddata.py

index 59b1267..9f1b28a 100644 (file)
@@ -64,7 +64,7 @@ class BuildData(object):
 
             try:
                 bconf = get_elem(btarget, "buildconf")
-                target["buildconf"]={
+                target["buildconf"] = {
                     "location":
                         get_elem(bconf, "location").getAttribute("href"),
                     "checksum":
@@ -110,7 +110,7 @@ class BuildData(object):
             target = self.targets[name]
             content += '<buildtarget name="%s">' % name
 
-            if 'buildconf' in target.keys():
+            if 'buildconf' in target:
                 # buildconf
                 content += '<buildconf>'
                 buildconf = target['buildconf']
index 7130ed7..a34638a 100644 (file)
@@ -22,10 +22,9 @@ RepoMaker - creates download repos
 import os
 import shutil
 from hashlib import sha256
-from subprocess import check_output, CalledProcessError
 
 from common.builddata import BuildData, BuildDataError
-from common.imagedata import ImageData, ImageDataError
+from common.imagedata import ImageData
 
 class RepoMakerError(Exception):
     """Custom RepoMaker exception."""
@@ -34,7 +33,7 @@ class RepoMakerError(Exception):
 # Helper functions
 def find_files(topdir, prefix='', suffix='.rpm'):
     """Find files in the tree."""
-    for root, dirs, files in os.walk(topdir):
+    for root, _dirs, files in os.walk(topdir):
         for item in files:
             if item.startswith(prefix) and item.endswith(suffix):
                 yield os.path.join(root, item)
@@ -199,7 +198,7 @@ class RepoMaker(object):
         self.imagedata = ImageData()
         self.imagedata.extract_image_conf(rpm)
 
-    def gen_image_info(self, updated_ks = None):
+    def gen_image_info(self, updated_ks=None):
         """
         Generate images.xml and save a copy of ks file under builddata dir
         """
index d9d41a8..b83ee88 100755 (executable)
@@ -134,7 +134,7 @@ def make_repo(project, repo, backenddb):
     if not repomaker.imagedata:
         raise LocalError("Image configuration not found")
 
-    # Update ks files    
+    # Update ks files
     images_ks = update_ks(repomaker.imagedata, backenddb)
     # Generate image info to builddata/ dir
     repomaker.gen_image_info(images_ks)
@@ -161,7 +161,7 @@ def main(name, action):
     project = content.get("project")
     build = BuildService(obs_api, obs_user, obs_passwd)
 
-    # Init backend database 
+    # Init backend database
     redis_host = os.getenv("REDIS_HOST")
     redis_port = os.getenv("REDIS_PORT")
     backenddb = BackendDB(redis_host, redis_port)
index 096b88a..9648a52 100644 (file)
@@ -92,7 +92,8 @@ class RedisMock(object):
         return key in self._dict
 
     def keys(self, pattern):
-        return [key for key in self._dict.keys() \
+        """Get list of keys from db."""
+        return [key for key in self._dict \
                     if re.match("^%s" % pattern, str(key))]
 
     def hmset(self, key, value):
@@ -117,9 +118,11 @@ class RedisMock(object):
             return 'string'
 
     def set(self, key, value):
-        self._dict[key]=value
+        """Set value for the key."""
+        self._dict[key] = value
 
     def get(self, key):
+        """Get value for the key."""
         return self._dict[key]
 
 @patch('redis.Redis', RedisMock) # pylint: disable=R0904
index ffac2fd..483c048 100644 (file)
@@ -66,6 +66,7 @@ class BuildDataTest(unittest.TestCase):
     '''Tests for BuildData functionality.'''
 
     def test_load(self):
+        """Test loading of build data from xml string."""
         bdata = BuildData(build_id='test.id')
         bdata.load(TEST_XML)
         self.assertEqual(bdata.targets, OrderedDict(
@@ -130,6 +131,7 @@ class BuildDataTest(unittest.TestCase):
 
 
     def test_save(self):
+        """Test saving build data to file."""
         bdata = BuildData(build_id='test.id')
         bdata.load(TEST_XML)
         fname = 'test_save.tmp'