Browse Source

Make pylint happy

no-else-raise warning
Marek Marczykowski-Górecki 5 years ago
parent
commit
d7430d42ce

+ 24 - 28
qubesadmin/backup/restore.py

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

+ 2 - 3
qubesadmin/base.py

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

+ 1 - 1
qubesadmin/firewall.py

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

+ 3 - 4
qubesadmin/tools/qvm_backup_restore.py

@@ -142,7 +142,7 @@ def handle_broken(app, args, restore_info):
             raise qubesadmin.exc.QubesException(
                 "Install them before proceeding with the restore."
                 "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 "
                             "missing TemplateVMs will NOT be restored.")
         elif args.ignore_missing:
@@ -160,7 +160,7 @@ def handle_broken(app, args, restore_info):
             raise qubesadmin.exc.QubesException(
                 "Install them before proceeding with the restore."
                 "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 "
                             "missing NetVMs will NOT be restored.")
         elif args.ignore_missing:
@@ -180,8 +180,7 @@ def handle_broken(app, args, restore_info):
                     "Skip restoring the dom0 home directory "
                     "(--skip-dom0-home), or pass "
                     "--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 "
             "will be restored to a new directory "
             "'home-restore-<current-time>' "

+ 1 - 1
qubesadmin/utils.py

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