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:
parent
72a2fd646d
commit
16064f6fb4
11
ci/pylintrc
11
ci/pylintrc
@ -5,6 +5,11 @@ extension-pkg-whitelist=lxml.etree
|
|||||||
|
|
||||||
[MESSAGES CONTROL]
|
[MESSAGES CONTROL]
|
||||||
# abstract-class-little-used: see http://www.logilab.org/ticket/111138
|
# 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=
|
disable=
|
||||||
bad-continuation,
|
bad-continuation,
|
||||||
raising-format-tuple,
|
raising-format-tuple,
|
||||||
@ -12,7 +17,11 @@ disable=
|
|||||||
duplicate-code,
|
duplicate-code,
|
||||||
fixme,
|
fixme,
|
||||||
locally-disabled,
|
locally-disabled,
|
||||||
locally-enabled
|
locally-enabled,
|
||||||
|
useless-object-inheritance,
|
||||||
|
consider-using-set-comprehension,
|
||||||
|
consider-using-dict-comprehension,
|
||||||
|
not-an-iterable
|
||||||
|
|
||||||
[REPORTS]
|
[REPORTS]
|
||||||
|
|
||||||
|
@ -209,6 +209,7 @@ def launch_proc_with_pty(args, stdin=None, stdout=None, stderr=None, echo=True):
|
|||||||
termios_p[3] &= ~termios.ECHO
|
termios_p[3] &= ~termios.ECHO
|
||||||
termios.tcsetattr(ctty_fd, termios.TCSANOW, termios_p)
|
termios.tcsetattr(ctty_fd, termios.TCSANOW, termios_p)
|
||||||
(pty_master, pty_slave) = os.openpty()
|
(pty_master, pty_slave) = os.openpty()
|
||||||
|
# pylint: disable=subprocess-popen-preexec-fn
|
||||||
p = subprocess.Popen(args, stdin=stdin, stdout=stdout,
|
p = subprocess.Popen(args, stdin=stdin, stdout=stdout,
|
||||||
stderr=stderr,
|
stderr=stderr,
|
||||||
preexec_fn=lambda: set_ctty(pty_slave, pty_master))
|
preexec_fn=lambda: set_ctty(pty_slave, pty_master))
|
||||||
@ -348,8 +349,7 @@ class ExtractWorker3(Process):
|
|||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.EAGAIN:
|
if e.errno == errno.EAGAIN:
|
||||||
return
|
return
|
||||||
else:
|
raise
|
||||||
raise
|
|
||||||
else:
|
else:
|
||||||
new_lines = self.tar2_process.stderr.readlines()
|
new_lines = self.tar2_process.stderr.readlines()
|
||||||
|
|
||||||
@ -1004,11 +1004,10 @@ class BackupRestore(object):
|
|||||||
self.log.debug(
|
self.log.debug(
|
||||||
"File verification OK -> Sending file %s", filename)
|
"File verification OK -> Sending file %s", filename)
|
||||||
return True
|
return True
|
||||||
else:
|
raise QubesException(
|
||||||
raise QubesException(
|
"ERROR: invalid hmac for file {0}: {1}. "
|
||||||
"ERROR: invalid hmac for file {0}: {1}. "
|
"Is the passphrase correct?".
|
||||||
"Is the passphrase correct?".
|
format(filename, load_hmac(hmac_stdout.decode('ascii'))))
|
||||||
format(filename, load_hmac(hmac_stdout.decode('ascii'))))
|
|
||||||
|
|
||||||
def _verify_and_decrypt(self, filename, output=None):
|
def _verify_and_decrypt(self, filename, output=None):
|
||||||
'''Handle scrypt-wrapped file
|
'''Handle scrypt-wrapped file
|
||||||
@ -1083,14 +1082,13 @@ class BackupRestore(object):
|
|||||||
if not filelist and 'Not found in archive' in extract_stderr:
|
if not filelist and 'Not found in archive' in extract_stderr:
|
||||||
if allow_none:
|
if allow_none:
|
||||||
return None
|
return None
|
||||||
else:
|
raise QubesException(
|
||||||
raise QubesException(
|
"unable to read the qubes backup file {0} ({1}): {2}".
|
||||||
"unable to read the qubes backup file {0} ({1}): {2}".
|
format(
|
||||||
format(
|
self.backup_location,
|
||||||
self.backup_location,
|
retrieve_proc.wait(),
|
||||||
retrieve_proc.wait(),
|
extract_stderr
|
||||||
extract_stderr
|
))
|
||||||
))
|
|
||||||
actual_files = filelist.decode('ascii').splitlines()
|
actual_files = filelist.decode('ascii').splitlines()
|
||||||
if sorted(actual_files) != sorted(files):
|
if sorted(actual_files) != sorted(files):
|
||||||
raise QubesException(
|
raise QubesException(
|
||||||
@ -1101,12 +1099,11 @@ class BackupRestore(object):
|
|||||||
if not os.path.exists(os.path.join(self.tmpdir, fname)):
|
if not os.path.exists(os.path.join(self.tmpdir, fname)):
|
||||||
if allow_none:
|
if allow_none:
|
||||||
return None
|
return None
|
||||||
else:
|
raise QubesException(
|
||||||
raise QubesException(
|
'Unable to retrieve file {} from backup {}: {}'.format(
|
||||||
'Unable to retrieve file {} from backup {}: {}'.format(
|
fname, self.backup_location, extract_stderr
|
||||||
fname, self.backup_location, extract_stderr
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def _retrieve_backup_header(self):
|
def _retrieve_backup_header(self):
|
||||||
@ -1694,10 +1691,10 @@ class BackupRestore(object):
|
|||||||
if isinstance(instance, BackupVM):
|
if isinstance(instance, BackupVM):
|
||||||
if instance.klass == 'TemplateVM':
|
if instance.klass == 'TemplateVM':
|
||||||
return 0
|
return 0
|
||||||
elif instance.properties.get('template_for_dispvms', False):
|
if instance.properties.get('template_for_dispvms', False):
|
||||||
return 1
|
return 1
|
||||||
return 2
|
return 2
|
||||||
elif hasattr(instance, 'vm'):
|
if hasattr(instance, 'vm'):
|
||||||
return key_function(instance.vm)
|
return key_function(instance.vm)
|
||||||
return 9
|
return 9
|
||||||
return sorted(vms, key=key_function)
|
return sorted(vms, key=key_function)
|
||||||
|
@ -83,7 +83,7 @@ class PropertyHolder(object):
|
|||||||
|
|
||||||
if response_data[0:2] == b'\x30\x00':
|
if response_data[0:2] == b'\x30\x00':
|
||||||
return response_data[2:]
|
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) = \
|
(_, exc_type, _traceback, format_string, args) = \
|
||||||
response_data.split(b'\x00', 4)
|
response_data.split(b'\x00', 4)
|
||||||
# drop last field because of terminating '\x00'
|
# drop last field because of terminating '\x00'
|
||||||
@ -223,25 +223,24 @@ class PropertyHolder(object):
|
|||||||
value = value.decode()
|
value = value.decode()
|
||||||
if prop_type == 'str':
|
if prop_type == 'str':
|
||||||
return str(value)
|
return str(value)
|
||||||
elif prop_type == 'bool':
|
if prop_type == 'bool':
|
||||||
if value == '':
|
if value == '':
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
return value == "True"
|
return value == "True"
|
||||||
elif prop_type == 'int':
|
if prop_type == 'int':
|
||||||
if value == '':
|
if value == '':
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
return int(value)
|
return int(value)
|
||||||
elif prop_type == 'vm':
|
if prop_type == 'vm':
|
||||||
if value == '':
|
if value == '':
|
||||||
return None
|
return None
|
||||||
return self.app.domains[value]
|
return self.app.domains[value]
|
||||||
elif prop_type == 'label':
|
if prop_type == 'label':
|
||||||
if value == '':
|
if value == '':
|
||||||
return None
|
return None
|
||||||
return self.app.labels.get_blind(value)
|
return self.app.labels.get_blind(value)
|
||||||
else:
|
raise qubesadmin.exc.QubesDaemonCommunicationError(
|
||||||
raise qubesadmin.exc.QubesDaemonCommunicationError(
|
'Received invalid value type: {}'.format(prop_type))
|
||||||
'Received invalid value type: {}'.format(prop_type))
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _local_properties(cls):
|
def _local_properties(cls):
|
||||||
|
@ -98,7 +98,7 @@ class Volume(object):
|
|||||||
if isinstance(other, Volume):
|
if isinstance(other, Volume):
|
||||||
if self._vm and other._vm:
|
if self._vm and other._vm:
|
||||||
return (self._vm, self._vm_name) < (other._vm, other._vm_name)
|
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 (self._pool, self._vid) < (other._pool, other._vid)
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ class Pool(object):
|
|||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, Pool):
|
if isinstance(other, Pool):
|
||||||
return self.name == other.name
|
return self.name == other.name
|
||||||
elif isinstance(other, str):
|
if isinstance(other, str):
|
||||||
return self.name == other
|
return self.name == other
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ def check_man_args(app, doctree, docname):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def break_to_pdb(app, *dummy):
|
def break_to_pdb(app, *_dummy):
|
||||||
'''DEBUG'''
|
'''DEBUG'''
|
||||||
if not app.config.break_to_pdb:
|
if not app.config.break_to_pdb:
|
||||||
return
|
return
|
||||||
|
@ -58,20 +58,19 @@ def main(args=None, app=None):
|
|||||||
if args.verbose:
|
if args.verbose:
|
||||||
print_msg(running, "is running", "are running")
|
print_msg(running, "is running", "are running")
|
||||||
return 0 if running else 1
|
return 0 if running else 1
|
||||||
elif args.paused:
|
if args.paused:
|
||||||
paused = [vm for vm in domains if vm.is_paused()]
|
paused = [vm for vm in domains if vm.is_paused()]
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print_msg(paused, "is paused", "are paused")
|
print_msg(paused, "is paused", "are paused")
|
||||||
return 0 if paused else 1
|
return 0 if paused else 1
|
||||||
elif args.template:
|
if args.template:
|
||||||
template = [vm for vm in domains if vm.klass == 'TemplateVM']
|
template = [vm for vm in domains if vm.klass == 'TemplateVM']
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print_msg(template, "is a template", "are templates")
|
print_msg(template, "is a template", "are templates")
|
||||||
return 0 if template else 1
|
return 0 if template else 1
|
||||||
else:
|
if args.verbose:
|
||||||
if args.verbose:
|
print_msg(domains, "exists", "exist")
|
||||||
print_msg(domains, "exists", "exist")
|
return 0 if domains else 1
|
||||||
return 0 if domains else 1
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
@ -248,7 +248,7 @@ class FlagsColumn(Column):
|
|||||||
state = vm.get_power_state().lower()
|
state = vm.get_power_state().lower()
|
||||||
if state == 'unknown':
|
if state == 'unknown':
|
||||||
return '?'
|
return '?'
|
||||||
elif state in ('running', 'transient', 'paused', 'suspended',
|
if state in ('running', 'transient', 'paused', 'suspended',
|
||||||
'halting', 'dying', 'crashed'):
|
'halting', 'dying', 'crashed'):
|
||||||
return state[0]
|
return state[0]
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ def process_actions(parser, args, target):
|
|||||||
:param args: arguments to handle
|
:param args: arguments to handle
|
||||||
:param target: object on which actions should be performed
|
:param target: object on which actions should be performed
|
||||||
'''
|
'''
|
||||||
|
# pylint: disable=no-else-return
|
||||||
if args.help_properties:
|
if args.help_properties:
|
||||||
properties = target.property_list()
|
properties = target.property_list()
|
||||||
width = max(len(prop) for prop in properties)
|
width = max(len(prop) for prop in properties)
|
||||||
|
@ -76,9 +76,9 @@ def size_to_human(size):
|
|||||||
"""Humane readable size, with 1/10 precision"""
|
"""Humane readable size, with 1/10 precision"""
|
||||||
if size < 1024:
|
if size < 1024:
|
||||||
return str(size)
|
return str(size)
|
||||||
elif size < 1024 * 1024:
|
if size < 1024 * 1024:
|
||||||
return str(round(size / 1024.0, 1)) + ' KiB'
|
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), 1)) + ' MiB'
|
||||||
return str(round(size / (1024.0 * 1024 * 1024), 1)) + ' GiB'
|
return str(round(size / (1024.0 * 1024 * 1024), 1)) + ' GiB'
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ class QubesVM(qubesadmin.base.PropertyHolder):
|
|||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, QubesVM):
|
if isinstance(other, QubesVM):
|
||||||
return self.name == other.name
|
return self.name == other.name
|
||||||
elif isinstance(other, str):
|
if isinstance(other, str):
|
||||||
return self.name == other
|
return self.name == other
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user