Make pylint happy

New pylint throw some more warnings.
This commit is contained in:
Marek Marczykowski-Górecki 2017-04-21 15:43:46 +02:00
parent 0ada6d0b64
commit fa72679b47
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
20 changed files with 43 additions and 62 deletions

View File

@ -480,7 +480,7 @@ class VMCollection(object):
# if not self[netvm_qid].is_netvm():
# return set([])
while len(new_vms) > 0:
while new_vms:
cur_vm = new_vms.pop()
for vm in cur_vm.connected_vms:
if vm in dependent_vms:

View File

@ -216,8 +216,7 @@ 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):

View File

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

View File

@ -55,8 +55,7 @@ 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):
@ -93,7 +92,7 @@ class Element(object):
for xml in self.xml.xpath('''./rng:attribute |
./rng:optional/rng:attribute |
./rng:choice/rng:attribute''', namespaces=self.nsmap):
required = xml.getparent() == self.xml and 'yes' or 'no'
required = 'yes' if xml.getparent() == self.xml else 'no'
yield (xml, required)
@ -212,6 +211,6 @@ Quick example, worth thousands lines of specification:
if __name__ == '__main__':
main(*sys.argv[1:])
main(*sys.argv[1:]) # pylint: disable=no-value-for-parameter
# vim: ts=4 sw=4 et

View File

@ -446,8 +446,7 @@ 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 '''
@ -476,8 +475,7 @@ 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):

View File

@ -378,10 +378,9 @@ 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):

View File

@ -401,8 +401,7 @@ class ThinVolume(qubes.storage.Volume):
return qubes.devices.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

View File

@ -38,10 +38,9 @@ class TarSparseInfo(tarfile.TarInfo):
@property
def realsize(self):
if len(self.sparsemap):
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):

View File

@ -258,7 +258,7 @@ class VolumeAction(QubesAction):
pool = app.pools[pool_name]
volume = [v for v in pool.volumes if v.vid == vid]
assert volume > 1, 'Duplicate vids in pool %s' % pool_name
if len(volume) == 0:
if not volume:
parser.error_runtime(
'no volume with id {!r} pool: {!r}'.format(vid,
pool_name))
@ -353,6 +353,7 @@ class QubesArgumentParser(argparse.ArgumentParser):
self.set_defaults(verbose=1, quiet=0)
def parse_args(self, *args, **kwargs):
# pylint: disable=arguments-differ
namespace = super(QubesArgumentParser, self).parse_args(*args, **kwargs)
if self._want_app and not self._want_app_no_instance:
@ -433,7 +434,7 @@ class AliasedSubParsersAction(argparse._SubParsersAction):
# source https://gist.github.com/sampsyo/471779
# pylint: disable=protected-access,too-few-public-methods
class _AliasedPseudoAction(argparse.Action):
# pylint: disable=redefined-builtin
# pylint: disable=redefined-builtin,arguments-differ
def __init__(self, name, aliases, help):
dest = name
if aliases:
@ -442,8 +443,7 @@ class AliasedSubParsersAction(argparse._SubParsersAction):
sup.__init__(option_strings=[], dest=dest, help=help)
def __call__(self, **kwargs):
super(AliasedSubParsersAction._AliasedPseudoAction, self).__call__(
**kwargs)
pass
def add_parser(self, name, **kwargs):
if 'aliases' in kwargs:

View File

@ -42,6 +42,7 @@ class QubesDaemonProtocol(asyncio.Protocol):
self.untrusted_buffer.close()
def data_received(self, untrusted_data):
# pylint: disable=arguments-differ
print('data_received(untrusted_data={!r})'.format(untrusted_data))
if self.len_untrusted_buffer + len(untrusted_data) > self.buffer_size:
self.app.log.warning('request too long')

View File

@ -204,7 +204,6 @@ def main(args=None):
"and (if encrypted) decrypt the backup: ")
encoding = sys.stdin.encoding or locale.getpreferredencoding()
# pylint: disable=redefined-variable-type
passphrase = passphrase.decode(encoding)
args.app.log.info("Checking backup content...")

View File

@ -38,6 +38,7 @@ parser.add_argument("--template", action="store_true", dest="template",
def print_msg(domains, what_single, what_plural):
# pylint: disable=len-as-condition
if len(domains) == 0:
print("None of given VM {!s}".format(what_single))
elif len(domains) == 1:

View File

@ -309,8 +309,7 @@ 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 +477,7 @@ 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):

View File

@ -84,7 +84,7 @@ def list_pools(app):
''' Prints out all known pools and their drivers '''
result = [('NAME', 'DRIVER')]
for pool in app.pools.values():
if len(pool.volumes) == 0 and issubclass(
if not pool.volumes and issubclass(
pool.__class__, qubes.storage.domain.DomainPool):
# skip empty DomainPools
continue

View File

@ -111,22 +111,19 @@ 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 +134,7 @@ 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):

View File

@ -132,7 +132,7 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
.. seealso:
:py:meth:`qubes.vm.qubesvm.QubesVM.start`
''' # pylint: disable=unused-argument
''' # pylint: disable=unused-argument,arguments-differ
raise qubes.exc.QubesVMError(self, 'Cannot start Dom0 fake domain!')
def suspend(self):

View File

@ -49,8 +49,7 @@ 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 +172,7 @@ 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

View File

@ -427,6 +427,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
doc='Kernel used by this domain.')
# CORE2: swallowed uses_default_kernelopts
# pylint: disable=no-member
kernelopts = qubes.property('kernelopts', type=str, load_stage=4,
default=(lambda self: qubes.config.defaults['kernelopts_pcidevs']
if list(self.devices['pci'].attached(persistent=True))
@ -449,6 +450,8 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
ls_width=12,
doc='FIXME')
# pylint: enable=no-member
# @property
# def default_user(self):
# if self.template is not None:
@ -1430,15 +1433,12 @@ 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'
else:
raise
raise
assert False
@ -1612,8 +1612,7 @@ 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 \

View File

@ -364,7 +364,7 @@ class PolicyAction(object):
self.target = target
self.action = Action.allow
else:
self.action = Action.deny # pylint: disable=redefined-variable-type
self.action = Action.deny
raise AccessDenied(
'denied by the user {}:{}'.format(self.rule.filename,
self.rule.lineno))
@ -569,7 +569,7 @@ class Policy(object):
else:
targets = list(
self.collect_targets_for_ask(system_info, source))
if len(targets) == 0:
if not targets:
raise AccessDenied(
'policy define \'ask\' action at {}:{} but no target is '
'available to choose from'.format(

View File

@ -119,7 +119,7 @@ class RPCConfirmationWindow:
partitioned = escaped.partition('.')
formatted = partitioned[0] + partitioned[1]
if len(partitioned[2]) > 0:
if partitioned[2]:
formatted += "<b>" + partitioned[2] + "</b>"
else:
formatted = "<b>" + formatted + "</b>"
@ -203,8 +203,7 @@ class RPCConfirmationWindow:
if self._confirmed:
return self._target_name
else:
return False
return False
def confirm_rpc(entries_info, source, rpc_operation, targets_list, target=None):