Make pylint happy

no-else-raise warning
This commit is contained in:
Marek Marczykowski-Górecki 2019-03-07 03:07:42 +01:00
parent 05f0d4ca0f
commit d7430d42ce
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
5 changed files with 31 additions and 37 deletions

View File

@ -1003,8 +1003,7 @@ class BackupRestore(object):
if f_one.read() != f_two.read(): if f_one.read() != f_two.read():
raise QubesException( raise QubesException(
'Invalid hmac on {}'.format(filename)) 'Invalid hmac on {}'.format(filename))
else: return True
return True
with open(os.path.join(self.tmpdir, filename), 'rb') as f_input: with open(os.path.join(self.tmpdir, filename), 'rb') as f_input:
hmac_proc = subprocess.Popen( hmac_proc = subprocess.Popen(
@ -1016,23 +1015,22 @@ class BackupRestore(object):
if hmac_stderr: if hmac_stderr:
raise QubesException( raise QubesException(
"ERROR: verify file {0}: {1}".format(filename, hmac_stderr)) "ERROR: verify file {0}: {1}".format(filename, hmac_stderr))
else: self.log.debug("Loading hmac for file %s", filename)
self.log.debug("Loading hmac for file %s", filename) try:
try: with open(os.path.join(self.tmpdir, hmacfile), 'r',
with open(os.path.join(self.tmpdir, hmacfile), 'r', encoding='ascii') as f_hmac:
encoding='ascii') as f_hmac: hmac = load_hmac(f_hmac.read())
hmac = load_hmac(f_hmac.read()) except UnicodeDecodeError as err:
except UnicodeDecodeError as err: raise QubesException('Cannot load hmac file: ' + str(err))
raise QubesException('Cannot load hmac file: ' + str(err)) if hmac and load_hmac(hmac_stdout.decode('ascii')) == hmac:
if hmac and load_hmac(hmac_stdout.decode('ascii')) == hmac: os.unlink(os.path.join(self.tmpdir, hmacfile))
os.unlink(os.path.join(self.tmpdir, hmacfile)) self.log.debug(
self.log.debug( "File verification OK -> Sending file %s", filename)
"File verification OK -> Sending file %s", filename) return True
return True 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
@ -1242,7 +1240,7 @@ class BackupRestore(object):
""" """
if self.header_data.version == 1: if self.header_data.version == 1:
raise NotImplementedError('Backup format version 1 not supported') raise NotImplementedError('Backup format version 1 not supported')
elif self.header_data.version in [2, 3]: if self.header_data.version in [2, 3]:
self._retrieve_backup_header_files( self._retrieve_backup_header_files(
['qubes.xml.000', 'qubes.xml.000.hmac']) ['qubes.xml.000', 'qubes.xml.000.hmac'])
self._verify_hmac("qubes.xml.000", "qubes.xml.000.hmac") self._verify_hmac("qubes.xml.000", "qubes.xml.000.hmac")
@ -1407,12 +1405,11 @@ class BackupRestore(object):
raise QubesException( raise QubesException(
'retrieved backup size exceed expected size, if you ' 'retrieved backup size exceed expected size, if you '
'believe this is ok, use --ignore-size-limit option') 'believe this is ok, use --ignore-size-limit option')
else: raise QubesException(
raise QubesException( "unable to read the qubes backup file {} ({}): {}"
"unable to read the qubes backup file {} ({}): {}" .format(self.backup_location,
.format(self.backup_location, retrieve_proc.returncode, error_pipe.read(
retrieve_proc.returncode, error_pipe.read( MAX_STDERR_BYTES)))
MAX_STDERR_BYTES)))
# wait for other processes (if any) # wait for other processes (if any)
for proc in self.processes_to_kill_on_cancel: for proc in self.processes_to_kill_on_cancel:
proc.wait() proc.wait()
@ -1837,8 +1834,7 @@ class BackupRestore(object):
except QubesException as err: except QubesException as err:
if self.options.verify_only: if self.options.verify_only:
raise raise
else: self.log.error('Error extracting data: %s', str(err))
self.log.error('Error extracting data: %s', str(err))
finally: finally:
if self.log.getEffectiveLevel() > logging.DEBUG: if self.log.getEffectiveLevel() > logging.DEBUG:
shutil.rmtree(self.tmpdir) shutil.rmtree(self.tmpdir)

View File

@ -100,9 +100,8 @@ class PropertyHolder(object):
exc_class = qubesadmin.exc.QubesException exc_class = qubesadmin.exc.QubesException
# TODO: handle traceback if given # TODO: handle traceback if given
raise exc_class(format_string, *args) raise exc_class(format_string, *args)
else: raise qubesadmin.exc.QubesDaemonCommunicationError(
raise qubesadmin.exc.QubesDaemonCommunicationError( 'Invalid response format')
'Invalid response format')
def property_list(self): def property_list(self):
''' '''

View File

@ -89,7 +89,7 @@ class DstHost(RuleOption):
# TODO: in python >= 3.3 ipaddress module could be used # TODO: in python >= 3.3 ipaddress module could be used
if value.count('/') > 1: if value.count('/') > 1:
raise ValueError('Too many /: ' + value) raise ValueError('Too many /: ' + value)
elif not value.count('/'): if not value.count('/'):
# add prefix length to bare IP addresses # add prefix length to bare IP addresses
try: try:
socket.inet_pton(socket.AF_INET6, value) socket.inet_pton(socket.AF_INET6, value)

View File

@ -142,7 +142,7 @@ def handle_broken(app, args, restore_info):
raise qubesadmin.exc.QubesException( raise qubesadmin.exc.QubesException(
"Install them before proceeding with the restore." "Install them before proceeding with the restore."
"Or pass: --skip-broken or --ignore-missing.") "Or pass: --skip-broken or --ignore-missing.")
elif args.skip_broken: if args.skip_broken:
app.log.warning("Skipping broken entries: VMs that depend on " app.log.warning("Skipping broken entries: VMs that depend on "
"missing TemplateVMs will NOT be restored.") "missing TemplateVMs will NOT be restored.")
elif args.ignore_missing: elif args.ignore_missing:
@ -160,7 +160,7 @@ def handle_broken(app, args, restore_info):
raise qubesadmin.exc.QubesException( raise qubesadmin.exc.QubesException(
"Install them before proceeding with the restore." "Install them before proceeding with the restore."
"Or pass: --skip-broken or --ignore-missing.") "Or pass: --skip-broken or --ignore-missing.")
elif args.skip_broken: if args.skip_broken:
app.log.warning("Skipping broken entries: VMs that depend on " app.log.warning("Skipping broken entries: VMs that depend on "
"missing NetVMs will NOT be restored.") "missing NetVMs will NOT be restored.")
elif args.ignore_missing: elif args.ignore_missing:
@ -180,8 +180,7 @@ def handle_broken(app, args, restore_info):
"Skip restoring the dom0 home directory " "Skip restoring the dom0 home directory "
"(--skip-dom0-home), or pass " "(--skip-dom0-home), or pass "
"--ignore-username-mismatch to continue anyway.") "--ignore-username-mismatch to continue anyway.")
else: app.log.warning("Continuing as directed.")
app.log.warning("Continuing as directed.")
app.log.warning("NOTE: The archived dom0 home directory " app.log.warning("NOTE: The archived dom0 home directory "
"will be restored to a new directory " "will be restored to a new directory "
"'home-restore-<current-time>' " "'home-restore-<current-time>' "

View File

@ -91,7 +91,7 @@ def get_entry_point_one(group, name):
epoints = tuple(pkg_resources.iter_entry_points(group, name)) epoints = tuple(pkg_resources.iter_entry_points(group, name))
if not epoints: if not epoints:
raise KeyError(name) raise KeyError(name)
elif len(epoints) > 1: if len(epoints) > 1:
raise TypeError( raise TypeError(
'more than 1 implementation of {!r} found: {}'.format(name, 'more than 1 implementation of {!r} found: {}'.format(name,
', '.join('{}.{}'.format(ep.module_name, '.'.join(ep.attrs)) ', '.join('{}.{}'.format(ep.module_name, '.'.join(ep.attrs))