[Kimchi-devel] [PATCH] Fix pep8 errors according to pep8 1.5.6
alinefm at linux.vnet.ibm.com
alinefm at linux.vnet.ibm.com
Wed Jul 30 20:08:42 UTC 2014
From: Aline Manera <alinefm at linux.vnet.ibm.com>
After updating pep8 to 1.5.6 multiple errors were identified.
Fix them.
Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
src/kimchi/auth.py | 2 +-
src/kimchi/control/base.py | 4 ++--
src/kimchi/control/debugreports.py | 2 +-
src/kimchi/control/utils.py | 2 +-
src/kimchi/mockmodel.py | 20 ++++++++++----------
src/kimchi/model/storagepools.py | 6 +++---
src/kimchi/model/utils.py | 8 +++++---
src/kimchi/model/vmstorages.py | 4 ++--
src/kimchi/swupdate.py | 2 +-
src/kimchi/template.py | 2 +-
src/kimchi/utils.py | 1 +
tests/test_model.py | 4 ++--
tests/test_rest.py | 16 ++++++++--------
tests/utils.py | 4 ++--
14 files changed, 40 insertions(+), 37 deletions(-)
diff --git a/src/kimchi/auth.py b/src/kimchi/auth.py
index e2a0a05..f775205 100644
--- a/src/kimchi/auth.py
+++ b/src/kimchi/auth.py
@@ -70,7 +70,7 @@ def __init__(self, username):
self.user[USER_ROLES] = dict.fromkeys(tabs, 'user')
def get_groups(self):
- out, err, rc = run_command([ 'id', '-Gn', self.user[USER_NAME] ])
+ out, err, rc = run_command(['id', '-Gn', self.user[USER_NAME]])
if rc == 0:
self.user[USER_GROUPS] = out.rstrip().split(" ")
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index 4d1351f..bfc20bf 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -161,8 +161,8 @@ def is_authorized(self):
if (users is not None or groups is not None) and \
user_role and user_role != 'admin' and \
- (user_name not in users or \
- (groups and list(set(user_groups) & set(groups)) == [])):
+ (user_name not in users or
+ (groups and list(set(user_groups) & set(groups)) == [])):
return False
return True
diff --git a/src/kimchi/control/debugreports.py b/src/kimchi/control/debugreports.py
index debc2eb..ce20987 100644
--- a/src/kimchi/control/debugreports.py
+++ b/src/kimchi/control/debugreports.py
@@ -32,7 +32,7 @@ def __init__(self, model):
def _get_resources(self, filter_params):
res_list = super(DebugReports, self)._get_resources(filter_params)
- return sorted(res_list, key=lambda x:x.data['time'], reverse=True)
+ return sorted(res_list, key=lambda x: x.data['time'], reverse=True)
class DebugReport(Resource):
diff --git a/src/kimchi/control/utils.py b/src/kimchi/control/utils.py
index c39dbd8..485a2a1 100644
--- a/src/kimchi/control/utils.py
+++ b/src/kimchi/control/utils.py
@@ -55,7 +55,7 @@ def validate_method(allowed, role_key, admin_methods):
def mime_in_header(header, mime):
- if not header in cherrypy.request.headers:
+ if header not in cherrypy.request.headers:
accepts = 'application/json'
else:
accepts = cherrypy.request.headers[header]
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index ed275d5..f3fd5da 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -57,7 +57,7 @@
from kimchi.vmtemplate import VMTemplate
-fake_user = { 'admin': 'letmein!' }
+fake_user = {'admin': 'letmein!'}
class MockModel(object):
@@ -583,8 +583,8 @@ def storageserver_lookup(self, server):
pool_info['source']['addr'] == server:
return dict(host=server)
except NotFoundError:
- # Avoid inconsistent pool result because
- # of lease between list and lookup
+ # Avoid inconsistent pool result because
+ # of lease between list and lookup
pass
raise NotFoundError("KCHSR0001E", {'server': server})
@@ -1257,13 +1257,13 @@ def getRepositories(self):
return self._repos.keys()
def getRepository(self, repo_id):
- if not repo_id in self._repos.keys():
+ if repo_id not in self._repos.keys():
raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})
return self._repos[repo_id]
def enableRepository(self, repo_id):
- if not repo_id in self._repos.keys():
+ if repo_id not in self._repos.keys():
raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})
info = self._repos[repo_id]
@@ -1276,7 +1276,7 @@ def enableRepository(self, repo_id):
return repo_id
def disableRepository(self, repo_id):
- if not repo_id in self._repos.keys():
+ if repo_id not in self._repos.keys():
raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})
info = self._repos[repo_id]
@@ -1289,7 +1289,7 @@ def disableRepository(self, repo_id):
return repo_id
def updateRepository(self, repo_id, params):
- if not repo_id in self._repos.keys():
+ if repo_id not in self._repos.keys():
raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})
info = self._repos[repo_id]
@@ -1299,7 +1299,7 @@ def updateRepository(self, repo_id, params):
return info['repo_id']
def removeRepository(self, repo_id):
- if not repo_id in self._repos.keys():
+ if repo_id not in self._repos.keys():
raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})
del self._repos[repo_id]
@@ -1322,7 +1322,7 @@ def get_mock_environment():
vm = MockVM(vm_uuid, name, model.template_lookup('test-template-0'))
model._mock_vms[name] = vm
- #mock storagepool
+ # mock storagepool
for i in xrange(5):
name = 'default-pool-%i' % i
defaultstoragepool = MockStoragePool(name)
@@ -1343,7 +1343,7 @@ def get_mock_environment():
mockpool = model._mock_storagepools[name]
mockpool._volumes[vol_name] = defaultstoragevolume
- #mock network
+ # mock network
for i in xrange(5):
name = 'test-network-%i' % i
testnetwork = MockNetwork(name)
diff --git a/src/kimchi/model/storagepools.py b/src/kimchi/model/storagepools.py
index c699fc6..598fb26 100644
--- a/src/kimchi/model/storagepools.py
+++ b/src/kimchi/model/storagepools.py
@@ -248,7 +248,7 @@ def lookup(self, name):
path = xmlutils.xpath_get_text(xml, "/pool/target/path")[0]
pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
source = self._get_storage_source(pool_type, xml)
- #FIXME: nfs workaround - prevent any libvirt operation
+ # FIXME: nfs workaround - prevent any libvirt operation
# for a nfs if the corresponding NFS server is down.
if pool_type == 'netfs' and not self._nfs_status_online(pool):
kimchi_log.debug("NFS pool %s is offline, reason: NFS "
@@ -328,7 +328,7 @@ def update(self, name, params):
def activate(self, name):
pool = self.get_storagepool(name, self.conn)
- #FIXME: nfs workaround - do not activate a NFS pool
+ # FIXME: nfs workaround - do not activate a NFS pool
# if the NFS server is not reachable.
xml = pool.XMLDesc(0)
pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
@@ -359,7 +359,7 @@ def deactivate(self, name):
raise InvalidOperation('KCHPOOL0034E', {'name': name})
pool = self.get_storagepool(name, self.conn)
- #FIXME: nfs workaround - do not try to deactivate a NFS pool
+ # FIXME: nfs workaround - do not try to deactivate a NFS pool
# if the NFS server is not reachable.
xml = pool.XMLDesc(0)
pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py
index c9ab1d4..41c840a 100644
--- a/src/kimchi/model/utils.py
+++ b/src/kimchi/model/utils.py
@@ -111,7 +111,8 @@ def set_metadata_node(dom, node, mode="all"):
KIMCHI_NAMESPACE, KIMCHI_META_URL,
flags=get_vm_config_flag(dom, mode))
else:
- # FIXME remove this code when all distro libvirt supports metadata element
+ # FIXME remove this code when all distro libvirt supports metadata
+ # element
_kimchi_set_metadata_node(dom, node)
@@ -123,7 +124,7 @@ def _kimchi_get_metadata_node(dom, tag):
xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)
root = etree.fromstring(xml)
kimchi = root.find("metadata/{%s}kimchi" % KIMCHI_META_URL)
- #remove the "kimchi" prefix of xml
+ # remove the "kimchi" prefix of xml
# some developers may do not like to remove prefix by children iteration
# so here, use re to remove the "kimchi" prefix of xml
# and developers please don not define element like this:
@@ -142,7 +143,8 @@ def get_metadata_node(dom, tag, mode="current"):
if CapabilitiesModel().metadata_support:
kimchi = libvirt_get_kimchi_metadata_node(dom, mode)
else:
- # FIXME remove this code when all distro libvirt supports metadata element
+ # FIXME remove this code when all distro libvirt supports metadata
+ # element
kimchi = _kimchi_get_metadata_node(dom, tag)
if kimchi is not None:
diff --git a/src/kimchi/model/vmstorages.py b/src/kimchi/model/vmstorages.py
index cd985fa..a1bd754 100644
--- a/src/kimchi/model/vmstorages.py
+++ b/src/kimchi/model/vmstorages.py
@@ -67,8 +67,8 @@ def _get_storage_xml(params, ignore_source=False):
# Working with url paths
if src_type == 'network':
output = urlparse.urlparse(params.get('path'))
- host = E.host(name=output.hostname, port=
- output.port or socket.getservbyname(output.scheme))
+ port = output.port or socket.getservbyname(output.scheme)
+ host = E.host(name=output.hostname, port=port)
source = E.source(protocol=output.scheme, name=output.path)
source.append(host)
disk.append(source)
diff --git a/src/kimchi/swupdate.py b/src/kimchi/swupdate.py
index 23e3ff0..5ea36f1 100644
--- a/src/kimchi/swupdate.py
+++ b/src/kimchi/swupdate.py
@@ -96,7 +96,7 @@ def getUpdate(self, name):
"""
Return a dictionary with all info from a given package name.
"""
- if not name in self._packages.keys():
+ if name not in self._packages.keys():
raise NotFoundError('KCHPKGUPD0002E', {'name': name})
return self._packages[name]
diff --git a/src/kimchi/template.py b/src/kimchi/template.py
index 0bee8c4..97103d3 100644
--- a/src/kimchi/template.py
+++ b/src/kimchi/template.py
@@ -62,7 +62,7 @@ def validate_language(langs):
def can_accept(mime):
- if not 'Accept' in cherrypy.request.headers:
+ if 'Accept' not in cherrypy.request.headers:
accepts = 'text/html'
else:
accepts = cherrypy.request.headers['Accept']
diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
index a992189..e48b377 100644
--- a/src/kimchi/utils.py
+++ b/src/kimchi/utils.py
@@ -109,6 +109,7 @@ def get_enabled_plugins():
except (TypeError, KeyError):
continue
+
def get_all_tabs():
files = [os.path.join(paths.prefix, 'config/ui/tabs.xml')]
diff --git a/tests/test_model.py b/tests/test_model.py
index cab8288..b77ba5b 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -337,7 +337,7 @@ def test_vm_cdrom(self):
self.assertEquals('', cdrom_info['path'])
inst.vm_poweroff(vm_name)
- # removing non existent cdrom
+ # removing non existent cdrom
self.assertRaises(NotFoundError, inst.vmstorage_delete, vm_name,
"fakedev")
@@ -1098,7 +1098,7 @@ def test_debug_reports(self):
report_list = inst.debugreports_get_list()
self.assertTrue(tmp_name in report_list)
except OperationFailed, e:
- if not 'debugreport tool not found' in e.message:
+ if 'debugreport tool not found' not in e.message:
raise e
def _wait_task(self, model, taskid, timeout=5):
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 4feb298..9266e01 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -46,7 +46,7 @@
ssl_port = None
cherrypy_port = None
-#utils.silence_server()
+# utils.silence_server()
def setUpModule():
@@ -175,8 +175,8 @@ def test_get_vms(self):
resp = self.request('/templates', req, 'POST')
self.assertEquals(201, resp.status)
- test_users = [ 'user1', 'user2', 'root']
- test_groups = [ 'group1', 'group2', 'admin' ]
+ test_users = ['user1', 'user2', 'root']
+ test_groups = ['group1', 'group2', 'admin']
# Now add a couple of VMs to the mock model
for i in xrange(10):
name = 'vm-%i' % i
@@ -696,21 +696,21 @@ def test_scsi_fc_storage(self):
self.assertEquals(201, resp.status)
# Test create vms using lun of this pool
- ### activate the storage pool
+ # activate the storage pool
resp = self.request('/storagepools/scsi_fc_pool/activate', '{}',
'POST')
- ### Get scsi pool luns and choose one
+ # Get scsi pool luns and choose one
resp = self.request('/storagepools/scsi_fc_pool/storagevolumes')
luns = json.loads(resp.read())
lun_name = random.choice(luns).get('name')
- ### Create vm in scsi pool without volumes: Error
+ # Create vm in scsi pool without volumes: Error
req = json.dumps({'template': '/templates/test_fc_pool'})
resp = self.request('/vms', req, 'POST')
self.assertEquals(400, resp.status)
- ### Create vm in scsi pool
+ # Create vm in scsi pool
req = json.dumps({'name': 'test-vm',
'template': '/templates/test_fc_pool',
'volumes': [lun_name]})
@@ -1651,7 +1651,7 @@ def test_create_debugreport(self):
self.assertEquals(200, resp.status)
req = json.dumps({'name': 'report2'})
resp = request(host, ssl_port, '/debugreports/report1',
- req, 'PUT')
+ req, 'PUT')
self.assertEquals(303, resp.status)
def test_debugreport_download(self):
diff --git a/tests/utils.py b/tests/utils.py
index f452854..0730b12 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -64,7 +64,7 @@ def assertIsInstance(self, obj, cls, msg=None):
self.fail('%s is not an instance of %r' % (repr(obj), cls))
def assertIn(self, a, b, msg=None):
- if not a in b:
+ if a not in b:
self.fail("%s is not in %b" % (repr(a), repr(b)))
def assertNotIn(self, a, b, msg=None):
@@ -154,7 +154,7 @@ def patch_auth(sudo=True):
"""
def _get_groups(self):
- return [ 'groupA', 'groupB', 'wheel' ]
+ return ['groupA', 'groupB', 'wheel']
def _has_sudo(self, result):
result.value = sudo
--
1.9.3
More information about the Kimchi-devel
mailing list