Browse Source

Fixes for pylint 2.0

Ignore most of them - we still support python 2.7 here.
Fix no-else-return.
Marek Marczykowski-Górecki 5 years ago
parent
commit
16064f6fb4

+ 10 - 1
ci/pylintrc

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

+ 19 - 22
qubesadmin/backup/restore.py

@@ -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,8 +349,7 @@ class ExtractWorker3(Process):
             except IOError as e:
                 if e.errno == errno.EAGAIN:
                     return
-                else:
-                    raise
+                raise
         else:
             new_lines = self.tar2_process.stderr.readlines()
 
@@ -1004,11 +1004,10 @@ 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?".
-                    format(filename, load_hmac(hmac_stdout.decode('ascii'))))
+            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
@@ -1083,14 +1082,13 @@ 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(
-                            self.backup_location,
-                            retrieve_proc.wait(),
-                            extract_stderr
-                        ))
+                raise QubesException(
+                    "unable to read the qubes backup file {0} ({1}): {2}".
+                    format(
+                        self.backup_location,
+                        retrieve_proc.wait(),
+                        extract_stderr
+                    ))
         actual_files = filelist.decode('ascii').splitlines()
         if sorted(actual_files) != sorted(files):
             raise QubesException(
@@ -1101,12 +1099,11 @@ 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
-                        )
+                raise QubesException(
+                    'Unable to retrieve file {} from backup {}: {}'.format(
+                        fname, self.backup_location, extract_stderr
                     )
+                )
         return files
 
     def _retrieve_backup_header(self):
@@ -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)

+ 7 - 8
qubesadmin/base.py

@@ -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,25 +223,24 @@ 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))
+        raise qubesadmin.exc.QubesDaemonCommunicationError(
+            'Received invalid value type: {}'.format(prop_type))
 
     @classmethod
     def _local_properties(cls):

+ 2 - 2
qubesadmin/storage.py

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

+ 1 - 1
qubesadmin/tools/dochelpers.py

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

+ 5 - 6
qubesadmin/tools/qvm_check.py

@@ -58,20 +58,19 @@ 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
+    if args.verbose:
+        print_msg(domains, "exists", "exist")
+    return 0 if domains else 1
 
 if __name__ == '__main__':
     sys.exit(main())

+ 1 - 1
qubesadmin/tools/qvm_ls.py

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

+ 1 - 0
qubesadmin/tools/qvm_prefs.py

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

+ 2 - 2
qubesadmin/utils.py

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

+ 1 - 1
qubesadmin/vm/__init__.py

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