Fixes for pylint 2.0

Ignore most of them - we still support python 2.7 here.
Fix no-else-return.
This commit is contained in:
Marek Marczykowski-Górecki 2018-07-16 02:25:25 +02:00
parent 72a2fd646d
commit 16064f6fb4
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
10 changed files with 49 additions and 44 deletions

View File

@ -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]

View File

@ -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,7 +349,6 @@ class ExtractWorker3(Process):
except IOError as e:
if e.errno == errno.EAGAIN:
return
else:
raise
else:
new_lines = self.tar2_process.stderr.readlines()
@ -1004,7 +1004,6 @@ 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?".
@ -1083,7 +1082,6 @@ 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(
@ -1101,7 +1099,6 @@ 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
@ -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)

View File

@ -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,23 +223,22 @@ 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))

View File

@ -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

View File

@ -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

View File

@ -58,17 +58,16 @@ 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

View File

@ -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]

View File

@ -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)

View File

@ -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'

View File

@ -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