Skip to content

Commit

Permalink
[pylint] pylint and flake8 updates
Browse files Browse the repository at this point in the history
pylint for the following rules applied

* C0411: wrong-import-order
* R0912: too-many-branches
* R0914: too-many-locals
* R1725: super-with-arguments
* E1101: no-member

Resolves: sosreport#3597

Signed-off-by: Arif Ali <[email protected]>
  • Loading branch information
arif-ali authored and TurboTurtle committed May 3, 2024
1 parent 799425b commit 5eef057
Show file tree
Hide file tree
Showing 57 changed files with 276 additions and 233 deletions.
3 changes: 2 additions & 1 deletion plugins_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def add_valid_item(dest, item):
# split by comma; add each valid item to the `dest` list
def add_all_items(method, dest, wrapopen=r'\(', wrapclose=r'\)'):
regexp = f"{method}{wrapopen}(.*?){wrapclose}"
for match in re.findall(regexp, plugcontent, flags=re.MULTILINE | re.DOTALL):
for match in re.findall(regexp, plugcontent,
flags=re.MULTILINE | re.DOTALL):
# tuple of distros ended by either (class|from|import)
if isinstance(match, tuple):
for item in list(match):
Expand Down
2 changes: 1 addition & 1 deletion sos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import os
import sys
import gettext

from argparse import ArgumentParser
from sos.options import SosListOption

import gettext
gettext_dir = "/usr/share/locale"
gettext_app = "sos"
gettext.bindtextdomain(gettext_app, gettext_dir)
Expand Down
16 changes: 11 additions & 5 deletions sos/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def log_debug(self, msg):
return
self.log.debug(self._format_msg(msg))

def name(self):
return self._name

# this is our contract to clients of the Archive class hierarchy.
# All sub-classes need to implement these methods (or inherit concrete
# implementations from a parent class.
Expand Down Expand Up @@ -124,8 +127,7 @@ def finalize(self, method):
An archive that is subsequently compressed or simply closing an
archive that supports in-line handling. If method is automatic then
the following methods are tried in order: xz, gzip"""

self.close()
pass


class FileCacheArchive(Archive):
Expand Down Expand Up @@ -167,6 +169,7 @@ def join_sysroot(self, path):
return os.path.join(self.sysroot, path)

def _make_leading_paths(self, src, mode=0o700):
# pylint: disable=too-many-locals
"""Create leading path components
The standard python `os.makedirs` is insufficient for our
Expand Down Expand Up @@ -664,6 +667,9 @@ def _encrypt(self, archive):
msg = f"gpg exited with code {r['status']}"
raise Exception(msg)

def _build_archive(self, method):
pass


class TarFileArchive(FileCacheArchive):
""" archive class using python TarFile to create tar archives"""
Expand All @@ -673,8 +679,8 @@ class TarFileArchive(FileCacheArchive):

def __init__(self, name, tmpdir, policy, threads, enc_opts, sysroot,
manifest=None):
super(TarFileArchive, self).__init__(name, tmpdir, policy, threads,
enc_opts, sysroot, manifest)
super().__init__(name, tmpdir, policy, threads,
enc_opts, sysroot, manifest)
self._suffix = "tar"
self._archive_name = os.path.join(
tmpdir, self.name() # lgtm [py/init-calls-subclass]
Expand Down Expand Up @@ -724,7 +730,7 @@ def name(self):
def name_max(self):
# GNU Tar format supports unlimited file name length. Just return
# the limit of the underlying FileCacheArchive.
return super(TarFileArchive, self).name_max()
return super().name_max()

def _build_archive(self, method):
if method == 'auto':
Expand Down
11 changes: 7 additions & 4 deletions sos/cleaner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import logging
import os
import shutil
import sos.cleaner.preppers
import tempfile
import fnmatch

from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from pwd import getpwuid
from textwrap import fill

import sos.cleaner.preppers

from sos import __version__
from sos.component import SoSComponent
from sos.cleaner.parsers.ip_parser import SoSIPParser
Expand All @@ -34,7 +37,6 @@
from sos.cleaner.archives.generic import DataDirArchive, TarballArchive
from sos.cleaner.archives.insights import InsightsArchive
from sos.utilities import get_human_readable, import_module, ImporterHelper
from textwrap import fill


class SoSCleaner(SoSComponent):
Expand Down Expand Up @@ -97,7 +99,7 @@ def __init__(self, parser=None, args=None, cmdline=None, in_place=False,
hook_commons=None):
if not in_place:
# we are running `sos clean` directly
super(SoSCleaner, self).__init__(parser, args, cmdline)
super().__init__(parser, args, cmdline)
self.from_cmdline = True
else:
# we are being hooked by either SoSReport or SoSCollector, don't
Expand Down Expand Up @@ -665,7 +667,7 @@ def preload_all_archives_into_maps(self):
for archive in self.report_paths:
self._prepare_archive_with_prepper(archive, prepper)

def obfuscate_report(self, archive):
def obfuscate_report(self, archive): # pylint: disable=too-many-branches
"""Individually handle each archive or directory we've discovered by
running through each file therein.
Expand Down Expand Up @@ -744,6 +746,7 @@ def obfuscate_report(self, archive):
f"{archive.archive_name}: {err}")

def obfuscate_file(self, filename, short_name=None, arc_name=None):
# pylint: disable=too-many-locals
"""Obfuscate and individual file, line by line.
Lines processed, even if no substitutions occur, are then written to a
Expand Down
5 changes: 2 additions & 3 deletions sos/cleaner/archives/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
#
# See the LICENSE file in the source distribution for further information.


from sos.cleaner.archives import SoSObfuscationArchive

import os
import tarfile

from sos.cleaner.archives import SoSObfuscationArchive


class DataDirArchive(SoSObfuscationArchive):
"""A plain directory on the filesystem that is not directly associated with
Expand Down
3 changes: 1 addition & 2 deletions sos/cleaner/archives/insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
#
# See the LICENSE file in the source distribution for further information.

import tarfile

from sos.cleaner.archives import SoSObfuscationArchive

import tarfile


class InsightsArchive(SoSObfuscationArchive):
"""This class represents archives generated by the insights-client utility
Expand Down
5 changes: 2 additions & 3 deletions sos/cleaner/archives/sos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
#
# See the LICENSE file in the source distribution for further information.


from sos.cleaner.archives import SoSObfuscationArchive

import os
import tarfile

from sos.cleaner.archives import SoSObfuscationArchive


class SoSReportArchive(SoSObfuscationArchive):
"""This is the class representing an sos report, or in other words the
Expand Down
7 changes: 4 additions & 3 deletions sos/cleaner/mappings/hostname_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def domain_name_in_loaded_domains(self, domain):
return False

def get(self, item):
# pylint: disable=too-many-branches
prefix = ''
suffix = ''
final = None
Expand Down Expand Up @@ -170,21 +171,21 @@ def get(self, item):
elif not _host_substr and (_test[0].endswith('.') or
item.endswith(_existing)):
# new hostname in known domain
final = super(SoSHostnameMap, self).get(item)
final = super().get(item)
break
elif item.split(_test[0]):
# string that includes existing FQDN obfuscation substring
# so, only obfuscate the FQDN part
try:
itm = item.split(_test[0])[1]
final = _test[0] + super(SoSHostnameMap, self).get(itm)
final = _test[0] + super().get(itm)
break
except Exception:
# fallback to still obfuscating the entire item
pass

if not final:
final = super(SoSHostnameMap, self).get(item)
final = super().get(item)
return prefix + final + suffix

def sanitize_item(self, item):
Expand Down
4 changes: 2 additions & 2 deletions sos/cleaner/mappings/mac_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class SoSMacMap(SoSMap):

def add(self, item):
item = item.replace('-', ':').lower().strip('=.,').strip()
return super(SoSMacMap, self).add(item)
return super().add(item)

def get(self, item):
item = item.replace('-', ':').lower().strip('=.,').strip()
return super(SoSMacMap, self).get(item)
return super().get(item)

def sanitize_item(self, item):
"""Randomize the device hextets, and append those to our 'vendor'
Expand Down
2 changes: 2 additions & 0 deletions sos/cleaner/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
# See the LICENSE file in the source distribution for further information.

# pylint: disable=no-member

import re


Expand Down
2 changes: 1 addition & 1 deletion sos/cleaner/parsers/hostname_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SoSHostnameParser(SoSCleanerParser):

def __init__(self, config, skip_clean_files=[]):
self.mapping = SoSHostnameMap()
super(SoSHostnameParser, self).__init__(config, skip_clean_files)
super().__init__(config, skip_clean_files)

def parse_line(self, line):
"""This will be called for every line in every file we process, so that
Expand Down
2 changes: 1 addition & 1 deletion sos/cleaner/parsers/ip_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ class SoSIPParser(SoSCleanerParser):

def __init__(self, config, skip_clean_files=[]):
self.mapping = SoSIPMap()
super(SoSIPParser, self).__init__(config, skip_clean_files)
super().__init__(config, skip_clean_files)
2 changes: 1 addition & 1 deletion sos/cleaner/parsers/ipv6_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SoSIPv6Parser(SoSCleanerParser):

def __init__(self, config, skip_clean_files=[]):
self.mapping = SoSIPv6Map()
super(SoSIPv6Parser, self).__init__(config, skip_clean_files)
super().__init__(config, skip_clean_files)

def get_map_contents(self):
"""Structure the dataset contents properly so that they can be reloaded
Expand Down
2 changes: 1 addition & 1 deletion sos/cleaner/parsers/keyword_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SoSKeywordParser(SoSCleanerParser):

def __init__(self, config, skip_clean_files=[]):
self.mapping = SoSKeywordMap()
super(SoSKeywordParser, self).__init__(config, skip_clean_files)
super().__init__(config, skip_clean_files)

def _parse_line(self, line):
return line, 0
5 changes: 3 additions & 2 deletions sos/cleaner/parsers/mac_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#
# See the LICENSE file in the source distribution for further information.

import re

from sos.cleaner.parsers import SoSCleanerParser
from sos.cleaner.mappings.mac_map import SoSMacMap

import re

# aa:bb:cc:fe:ff:dd:ee:ff
IPV6_REG_8HEX = (
Expand Down Expand Up @@ -51,7 +52,7 @@ class SoSMacParser(SoSCleanerParser):

def __init__(self, config, skip_clean_files=[]):
self.mapping = SoSMacMap()
super(SoSMacParser, self).__init__(config, skip_clean_files)
super().__init__(config, skip_clean_files)

def reduce_mac_match(self, match):
"""Strips away leading and trailing non-alphanum characters from any
Expand Down
2 changes: 1 addition & 1 deletion sos/cleaner/parsers/username_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SoSUsernameParser(SoSCleanerParser):

def __init__(self, config, skip_clean_files=[]):
self.mapping = SoSUsernameMap()
super(SoSUsernameParser, self).__init__(config, skip_clean_files)
super().__init__(config, skip_clean_files)

def _parse_line(self, line):
return line, 0
4 changes: 3 additions & 1 deletion sos/collector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
# See the LICENSE file in the source distribution for further information.

# pylint: disable=too-many-locals,too-many-branches

import fnmatch
import inspect
import json
Expand Down Expand Up @@ -145,7 +147,7 @@ class SoSCollector(SoSComponent):
}

def __init__(self, parser, parsed_args, cmdline_args):
super(SoSCollector, self).__init__(parser, parsed_args, cmdline_args)
super().__init__(parser, parsed_args, cmdline_args)
os.umask(0o77)
self.client_list = []
self.node_list = []
Expand Down
4 changes: 2 additions & 2 deletions sos/collector/clusters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import logging

from threading import Lock
from sos.options import ClusterOption
from sos.utilities import bold
from threading import Lock


class Cluster():
Expand Down Expand Up @@ -91,7 +91,7 @@ def name(cls):
return cls.__name__.lower()

@classmethod
def display_help(cls, section):
def display_help(cls, section): # pylint: disable=too-many-branches
if cls is Cluster:
cls.display_self_help(section)
return
Expand Down
2 changes: 1 addition & 1 deletion sos/collector/clusters/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _attempt_oc_login(self):
return _res['status'] == 0

def check_enabled(self):
if super(ocp, self).check_enabled():
if super().check_enabled():
return True
self.token = self.get_option('token') or os.getenv('SOSOCPTOKEN', None)
if self.token:
Expand Down
2 changes: 1 addition & 1 deletion sos/collector/clusters/pacemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import re

from xml.etree import ElementTree
from sos.collector.clusters import Cluster
from sos.utilities import sos_parse_version
from xml.etree import ElementTree


class pacemaker(Cluster):
Expand Down
Loading

0 comments on commit 5eef057

Please sign in to comment.