From 16064f6fb4929289905f8e7bfa6025d22b1b732c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 16 Jul 2018 02:25:25 +0200 Subject: [PATCH] Fixes for pylint 2.0 Ignore most of them - we still support python 2.7 here. Fix no-else-return. --- ci/pylintrc | 11 ++++++++- qubesadmin/backup/restore.py | 41 ++++++++++++++++------------------ qubesadmin/base.py | 15 ++++++------- qubesadmin/storage.py | 4 ++-- qubesadmin/tools/dochelpers.py | 2 +- qubesadmin/tools/qvm_check.py | 11 +++++---- qubesadmin/tools/qvm_ls.py | 2 +- qubesadmin/tools/qvm_prefs.py | 1 + qubesadmin/utils.py | 4 ++-- qubesadmin/vm/__init__.py | 2 +- 10 files changed, 49 insertions(+), 44 deletions(-) diff --git a/ci/pylintrc b/ci/pylintrc index 08d7f9a..669487d 100644 --- a/ci/pylintrc +++ b/ci/pylintrc @@ -5,6 +5,11 @@ extension-pkg-whitelist=lxml.etree [MESSAGES CONTROL] # abstract-class-little-used: see http://www.logilab.org/ticket/111138 +# disabled to keep python2 compat: +# - useless-object-inheritance +# - consider-using-set-comprehension +# - consider-using-dict-comprehension +# - not-an-iterable disable= bad-continuation, raising-format-tuple, @@ -12,7 +17,11 @@ disable= duplicate-code, fixme, locally-disabled, - locally-enabled + locally-enabled, + useless-object-inheritance, + consider-using-set-comprehension, + consider-using-dict-comprehension, + not-an-iterable [REPORTS] diff --git a/qubesadmin/backup/restore.py b/qubesadmin/backup/restore.py index c1d092a..5ad9437 100644 --- a/qubesadmin/backup/restore.py +++ b/qubesadmin/backup/restore.py @@ -209,6 +209,7 @@ def launch_proc_with_pty(args, stdin=None, stdout=None, stderr=None, echo=True): termios_p[3] &= ~termios.ECHO termios.tcsetattr(ctty_fd, termios.TCSANOW, termios_p) (pty_master, pty_slave) = os.openpty() + # pylint: disable=subprocess-popen-preexec-fn p = subprocess.Popen(args, stdin=stdin, stdout=stdout, stderr=stderr, preexec_fn=lambda: set_ctty(pty_slave, pty_master)) @@ -348,8 +349,7 @@ class ExtractWorker3(Process): except IOError as e: if e.errno == errno.EAGAIN: return - else: - raise + raise else: new_lines = self.tar2_process.stderr.readlines() @@ -1004,11 +1004,10 @@ class BackupRestore(object): self.log.debug( "File verification OK -> Sending file %s", filename) return True - else: - raise QubesException( - "ERROR: invalid hmac for file {0}: {1}. " - "Is the passphrase correct?". - format(filename, load_hmac(hmac_stdout.decode('ascii')))) + raise QubesException( + "ERROR: invalid hmac for file {0}: {1}. " + "Is the passphrase correct?". + format(filename, load_hmac(hmac_stdout.decode('ascii')))) def _verify_and_decrypt(self, filename, output=None): '''Handle scrypt-wrapped file @@ -1083,14 +1082,13 @@ class BackupRestore(object): if not filelist and 'Not found in archive' in extract_stderr: if allow_none: return None - else: - raise QubesException( - "unable to read the qubes backup file {0} ({1}): {2}". - format( - self.backup_location, - retrieve_proc.wait(), - extract_stderr - )) + raise QubesException( + "unable to read the qubes backup file {0} ({1}): {2}". + format( + self.backup_location, + retrieve_proc.wait(), + extract_stderr + )) actual_files = filelist.decode('ascii').splitlines() if sorted(actual_files) != sorted(files): raise QubesException( @@ -1101,12 +1099,11 @@ class BackupRestore(object): if not os.path.exists(os.path.join(self.tmpdir, fname)): if allow_none: return None - else: - raise QubesException( - 'Unable to retrieve file {} from backup {}: {}'.format( - fname, self.backup_location, extract_stderr - ) + raise QubesException( + 'Unable to retrieve file {} from backup {}: {}'.format( + fname, self.backup_location, extract_stderr ) + ) return files def _retrieve_backup_header(self): @@ -1694,10 +1691,10 @@ class BackupRestore(object): if isinstance(instance, BackupVM): if instance.klass == 'TemplateVM': return 0 - elif instance.properties.get('template_for_dispvms', False): + if instance.properties.get('template_for_dispvms', False): return 1 return 2 - elif hasattr(instance, 'vm'): + if hasattr(instance, 'vm'): return key_function(instance.vm) return 9 return sorted(vms, key=key_function) diff --git a/qubesadmin/base.py b/qubesadmin/base.py index f1f59d7..cb0a2db 100644 --- a/qubesadmin/base.py +++ b/qubesadmin/base.py @@ -83,7 +83,7 @@ class PropertyHolder(object): if response_data[0:2] == b'\x30\x00': return response_data[2:] - elif response_data[0:2] == b'\x32\x00': + if response_data[0:2] == b'\x32\x00': (_, exc_type, _traceback, format_string, args) = \ response_data.split(b'\x00', 4) # drop last field because of terminating '\x00' @@ -223,25 +223,24 @@ class PropertyHolder(object): value = value.decode() if prop_type == 'str': return str(value) - elif prop_type == 'bool': + if prop_type == 'bool': if value == '': raise AttributeError return value == "True" - elif prop_type == 'int': + if prop_type == 'int': if value == '': raise AttributeError return int(value) - elif prop_type == 'vm': + if prop_type == 'vm': if value == '': return None return self.app.domains[value] - elif prop_type == 'label': + if prop_type == 'label': if value == '': return None return self.app.labels.get_blind(value) - else: - raise qubesadmin.exc.QubesDaemonCommunicationError( - 'Received invalid value type: {}'.format(prop_type)) + raise qubesadmin.exc.QubesDaemonCommunicationError( + 'Received invalid value type: {}'.format(prop_type)) @classmethod def _local_properties(cls): diff --git a/qubesadmin/storage.py b/qubesadmin/storage.py index 18b1f08..c4681f5 100644 --- a/qubesadmin/storage.py +++ b/qubesadmin/storage.py @@ -98,7 +98,7 @@ class Volume(object): if isinstance(other, Volume): if self._vm and other._vm: return (self._vm, self._vm_name) < (other._vm, other._vm_name) - elif self._vid and other._vid: + if self._vid and other._vid: return (self._pool, self._vid) < (other._pool, other._vid) return NotImplemented @@ -261,7 +261,7 @@ class Pool(object): def __eq__(self, other): if isinstance(other, Pool): return self.name == other.name - elif isinstance(other, str): + if isinstance(other, str): return self.name == other return NotImplemented diff --git a/qubesadmin/tools/dochelpers.py b/qubesadmin/tools/dochelpers.py index 863f444..37b19c6 100644 --- a/qubesadmin/tools/dochelpers.py +++ b/qubesadmin/tools/dochelpers.py @@ -283,7 +283,7 @@ def check_man_args(app, doctree, docname): -def break_to_pdb(app, *dummy): +def break_to_pdb(app, *_dummy): '''DEBUG''' if not app.config.break_to_pdb: return diff --git a/qubesadmin/tools/qvm_check.py b/qubesadmin/tools/qvm_check.py index 07c4b0a..ce0b705 100644 --- a/qubesadmin/tools/qvm_check.py +++ b/qubesadmin/tools/qvm_check.py @@ -58,20 +58,19 @@ def main(args=None, app=None): if args.verbose: print_msg(running, "is running", "are running") return 0 if running else 1 - elif args.paused: + if args.paused: paused = [vm for vm in domains if vm.is_paused()] if args.verbose: print_msg(paused, "is paused", "are paused") return 0 if paused else 1 - elif args.template: + if args.template: template = [vm for vm in domains if vm.klass == 'TemplateVM'] if args.verbose: print_msg(template, "is a template", "are templates") return 0 if template else 1 - else: - if args.verbose: - print_msg(domains, "exists", "exist") - return 0 if domains else 1 + if args.verbose: + print_msg(domains, "exists", "exist") + return 0 if domains else 1 if __name__ == '__main__': sys.exit(main()) diff --git a/qubesadmin/tools/qvm_ls.py b/qubesadmin/tools/qvm_ls.py index 057ad91..14cefe8 100644 --- a/qubesadmin/tools/qvm_ls.py +++ b/qubesadmin/tools/qvm_ls.py @@ -248,7 +248,7 @@ class FlagsColumn(Column): state = vm.get_power_state().lower() if state == 'unknown': return '?' - elif state in ('running', 'transient', 'paused', 'suspended', + if state in ('running', 'transient', 'paused', 'suspended', 'halting', 'dying', 'crashed'): return state[0] diff --git a/qubesadmin/tools/qvm_prefs.py b/qubesadmin/tools/qvm_prefs.py index 3d8c3e0..e90daeb 100644 --- a/qubesadmin/tools/qvm_prefs.py +++ b/qubesadmin/tools/qvm_prefs.py @@ -74,6 +74,7 @@ def process_actions(parser, args, target): :param args: arguments to handle :param target: object on which actions should be performed ''' + # pylint: disable=no-else-return if args.help_properties: properties = target.property_list() width = max(len(prop) for prop in properties) diff --git a/qubesadmin/utils.py b/qubesadmin/utils.py index 9c76e48..edaac11 100644 --- a/qubesadmin/utils.py +++ b/qubesadmin/utils.py @@ -76,9 +76,9 @@ def size_to_human(size): """Humane readable size, with 1/10 precision""" if size < 1024: return str(size) - elif size < 1024 * 1024: + if size < 1024 * 1024: return str(round(size / 1024.0, 1)) + ' KiB' - elif size < 1024 * 1024 * 1024: + if size < 1024 * 1024 * 1024: return str(round(size / (1024.0 * 1024), 1)) + ' MiB' return str(round(size / (1024.0 * 1024 * 1024), 1)) + ' GiB' diff --git a/qubesadmin/vm/__init__.py b/qubesadmin/vm/__init__.py index 498cfb2..966cc3b 100644 --- a/qubesadmin/vm/__init__.py +++ b/qubesadmin/vm/__init__.py @@ -84,7 +84,7 @@ class QubesVM(qubesadmin.base.PropertyHolder): def __eq__(self, other): if isinstance(other, QubesVM): return self.name == other.name - elif isinstance(other, str): + if isinstance(other, str): return self.name == other return NotImplemented