From 5bc7a8f9e33a30a15811ee4fbb638406ada392ac Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Sat, 15 Apr 2017 20:04:38 +0200 Subject: [PATCH] Fix pylint warning no-else-return --- qubes/devices.py | 4 ++-- qubes/firewall.py | 3 +-- qubes/rngdoc.py | 4 ++-- qubes/storage/__init__.py | 8 ++++---- qubes/storage/file.py | 8 ++++---- qubes/storage/lvm.py | 4 ++-- qubes/tarwriter.py | 9 +++------ qubes/tools/qvm_ls.py | 8 ++++---- qubes/utils.py | 16 ++++++++-------- qubes/vm/mix/net.py | 8 ++++---- qubes/vm/qubesvm.py | 12 ++++++------ 11 files changed, 40 insertions(+), 44 deletions(-) diff --git a/qubes/devices.py b/qubes/devices.py index 27d4995d..90c3dd0c 100644 --- a/qubes/devices.py +++ b/qubes/devices.py @@ -269,8 +269,8 @@ class DeviceCollection(object): if dev: assert len(dev) == 1 return dev[0] - else: - return UnknownDevice(self._vm, ident) + + return UnknownDevice(self._vm, ident) class DeviceManager(dict): diff --git a/qubes/firewall.py b/qubes/firewall.py index 6861bcb3..804f7d58 100644 --- a/qubes/firewall.py +++ b/qubes/firewall.py @@ -406,8 +406,7 @@ class Firewall(object): def _translate_action(key): if xml_root.get(key, policy_v1) == 'allow': return Action.accept - else: - return Action.drop + return Action.drop self.rules.append(Rule(None, action=_translate_action('dns'), diff --git a/qubes/rngdoc.py b/qubes/rngdoc.py index 205b7ea3..df7a40bc 100755 --- a/qubes/rngdoc.py +++ b/qubes/rngdoc.py @@ -55,8 +55,8 @@ class Element(object): if wrap: return ''.join(self.schema.wrapper.fill(p) + '\n\n' for p in textwrap.dedent(xml.text.strip('\n')).split('\n\n')) - else: - return ' '.join(xml.text.strip().split()) + + return ' '.join(xml.text.strip().split()) def get_data_type(self, xml=None): diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index c0baf334..5b29b5f0 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -460,8 +460,8 @@ class Storage(object): "You need to pass a Volume or pool name as str" if isinstance(volume, Volume): return self.pools[volume.name] - else: - return self.vm.app.pools[volume] + + return self.vm.app.pools[volume] def commit(self): ''' Makes changes to an 'origin' volume persistent ''' @@ -490,8 +490,8 @@ class Storage(object): "You need to pass a Volume or pool name as str" if isinstance(volume, Volume): return self.pools[volume.name].export(volume) - else: - return self.pools[volume].export(self.vm.volumes[volume]) + + return self.pools[volume].export(self.vm.volumes[volume]) class Pool(object): diff --git a/qubes/storage/file.py b/qubes/storage/file.py index ed7f1161..6ab47283 100644 --- a/qubes/storage/file.py +++ b/qubes/storage/file.py @@ -377,10 +377,10 @@ class FileVolume(qubes.storage.Volume): if not os.path.exists(old_revision): return {} - else: - seconds = os.path.getctime(old_revision) - iso_date = qubes.storage.isodate(seconds).split('.', 1)[0] - return {iso_date: old_revision} + + seconds = os.path.getctime(old_revision) + iso_date = qubes.storage.isodate(seconds).split('.', 1)[0] + return {iso_date: old_revision} @property def usage(self): diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py index a560d513..4f3a4b56 100644 --- a/qubes/storage/lvm.py +++ b/qubes/storage/lvm.py @@ -401,8 +401,8 @@ class ThinVolume(qubes.storage.Volume): return qubes.storage.BlockDevice( '/dev/' + self._vid_snap, self.name, self.script, self.rw, self.domain, self.devtype) - else: - return super(ThinVolume, self).block_device() + + return super(ThinVolume, self).block_device() @property def usage(self): # lvm thin usage always returns at least the same usage as diff --git a/qubes/tarwriter.py b/qubes/tarwriter.py index 0c7e0d49..bc9e90dd 100644 --- a/qubes/tarwriter.py +++ b/qubes/tarwriter.py @@ -40,8 +40,7 @@ class TarSparseInfo(tarfile.TarInfo): def realsize(self): if self.sparsemap: return self.sparsemap[-1][0] + self.sparsemap[-1][1] - else: - return self.size + return self.size def sparse_header_chunk(self, index): if index < len(self.sparsemap): @@ -49,8 +48,7 @@ class TarSparseInfo(tarfile.TarInfo): tarfile.itn(self.sparsemap[index][0], 12, tarfile.GNU_FORMAT), tarfile.itn(self.sparsemap[index][1], 12, tarfile.GNU_FORMAT), ]) - else: - return b'\0' * 12 * 2 + return b'\0' * 12 * 2 def get_gnu_header(self): '''Part placed in 'prefix' field of posix header''' @@ -81,8 +79,7 @@ class TarSparseInfo(tarfile.TarInfo): header_buf = super(TarSparseInfo, self).tobuf(format, encoding, errors) if len(self.sparsemap) > 4: return header_buf + b''.join(self.create_ext_sparse_headers()) - else: - return header_buf + return header_buf def create_ext_sparse_headers(self): for ext_hdr in range(4, len(self.sparsemap), 21): diff --git a/qubes/tools/qvm_ls.py b/qubes/tools/qvm_ls.py index 4748b3f0..352f1bed 100644 --- a/qubes/tools/qvm_ls.py +++ b/qubes/tools/qvm_ls.py @@ -309,8 +309,8 @@ class StatusColumn(Column): if ret is not None: if getattr(vm, 'hvm', False): return ret.upper() - else: - return ret + + return ret @flag(2) @@ -478,8 +478,8 @@ class Table(object): '''Format single table row (all columns for one domain).''' if self.raw_data: return '|'.join(col.format(vm) for col in self.columns) - else: - return ''.join(col.cell(vm) for col in self.columns) + + return ''.join(col.cell(vm) for col in self.columns) def write_table(self, stream=sys.stdout): diff --git a/qubes/utils.py b/qubes/utils.py index 39a78943..1bd1fadb 100644 --- a/qubes/utils.py +++ b/qubes/utils.py @@ -111,22 +111,22 @@ def parse_size(size): def mbytes_to_kmg(size): if size > 1024: return "%d GiB" % (size / 1024) - else: - return "%d MiB" % size + + return "%d MiB" % size def kbytes_to_kmg(size): if size > 1024: return mbytes_to_kmg(size / 1024) - else: - return "%d KiB" % size + + return "%d KiB" % size def bytes_to_kmg(size): if size > 1024: return kbytes_to_kmg(size / 1024) - else: - return "%d B" % size + + return "%d B" % size def size_to_human(size): @@ -137,8 +137,8 @@ def size_to_human(size): return str(round(size / 1024.0, 1)) + ' KiB' elif size < 1024 * 1024 * 1024: return str(round(size / (1024.0 * 1024), 1)) + ' MiB' - else: - return str(round(size / (1024.0 * 1024 * 1024), 1)) + ' GiB' + + return str(round(size / (1024.0 * 1024 * 1024), 1)) + ' GiB' def urandom(size): diff --git a/qubes/vm/mix/net.py b/qubes/vm/mix/net.py index 8597e30f..7d1913d3 100644 --- a/qubes/vm/mix/net.py +++ b/qubes/vm/mix/net.py @@ -49,8 +49,8 @@ def _default_ip(self): return None if self.netvm is not None: return self.netvm.get_ip_for_vm(self) # pylint: disable=no-member - else: - return self.get_ip_for_vm(self) + + return self.get_ip_for_vm(self) def _setter_ip(self, prop, value): @@ -173,8 +173,8 @@ class NetVMMixin(qubes.events.Emitter): '10.139.1.1', '10.139.1.2', ) - else: - return None + + return None def __init__(self, *args, **kwargs): self._firewall = None diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 6879d593..53a3975e 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1432,10 +1432,10 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): else: if not self.is_fully_usable(): return "Transient" - else: - return "Running" - else: - return 'Halted' + + return "Running" + + return 'Halted' except libvirt.libvirtError as e: if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN: return 'Halted' @@ -1614,8 +1614,8 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): '/vm/{}/start_time'.format(self.uuid)) if start_time != '': return datetime.datetime.fromtimestamp(float(start_time)) - else: - return None + + return None def is_outdated(self): '''Check whether domain needs restart to update root image from \