Skip to content

Commit

Permalink
Fix pylint warnings: [C0103 invalid-name]
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Turivnyi authored and bocekm committed May 25, 2020
1 parent 963215b commit ab1ee41
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 125 deletions.
10 changes: 5 additions & 5 deletions convert2rhel/cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from convert2rhel.systeminfo import system_info
from convert2rhel import utils

_redhat_release_cert_dir = "/etc/pki/product-default/"
_subscription_manager_cert_dir = "/etc/pki/product/"
_REDHAT_RELEASE_CERT_DIR = "/etc/pki/product-default/"
_SUBSCRIPTION_MANAGER_CERT_DIR = "/etc/pki/product/"


def copy_cert_for_rhel_5():
Expand All @@ -34,6 +34,6 @@ def copy_cert_for_rhel_5():
WONTFIX status.
"""
if system_info.version == "5":
for cert in glob.glob(_redhat_release_cert_dir + "*.pem"):
utils.mkdir_p(_subscription_manager_cert_dir)
shutil.copy(cert, _subscription_manager_cert_dir)
for cert in glob.glob(_REDHAT_RELEASE_CERT_DIR + "*.pem"):
utils.mkdir_p(_SUBSCRIPTION_MANAGER_CERT_DIR)
shutil.copy(cert, _SUBSCRIPTION_MANAGER_CERT_DIR)
20 changes: 10 additions & 10 deletions convert2rhel/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

LOG_DIR = "/var/log/convert2rhel"

class LOG_LEVEL_TASK:
class LogLevelTask:
level = 15
label = "TASK"


class LOG_LEVEL_FILE:
class LogLevelFile:
level = 5
label = "FILE"

Expand All @@ -52,16 +52,16 @@ def initialize_logger(log_name):
# set custom class
logging.setLoggerClass(CustomLogger)
# set custom labels
logging.addLevelName(LOG_LEVEL_TASK.level, LOG_LEVEL_TASK.label)
logging.addLevelName(LOG_LEVEL_FILE.level, LOG_LEVEL_FILE.label)
logging.addLevelName(LogLevelTask.level, LogLevelTask.label)
logging.addLevelName(LogLevelFile.level, LogLevelFile.label)
# enable raising exceptions
logging.raiseExceptions = True
# get root logger
logger = logging.getLogger("convert2rhel")
# propagate
logger.propagate = False
# set default logging level
logger.setLevel(LOG_LEVEL_FILE.level)
logger.setLevel(LogLevelFile.level)

# create sys.stdout handler for info/debug
stdout_handler = logging.StreamHandler(sys.stdout)
Expand All @@ -76,7 +76,7 @@ def initialize_logger(log_name):
handler = logging.FileHandler(os.path.join(LOG_DIR, log_name), "w")
formatter = CustomFormatter("%(message)s")
handler.setFormatter(formatter)
handler.setLevel(LOG_LEVEL_FILE.level)
handler.setLevel(LogLevelFile.level)
logger.addHandler(handler)


Expand All @@ -88,11 +88,11 @@ class and causes 'TypeError: super() argument 1 must be type, not
classobj' so we use multiple inheritance to get around the problem.
"""
def task(self, msg, *args, **kwargs):
super(CustomLogger, self).log(LOG_LEVEL_TASK.level, msg, *args,
super(CustomLogger, self).log(LogLevelTask.level, msg, *args,
**kwargs)

def file(self, msg, *args, **kwargs):
super(CustomLogger, self).log(LOG_LEVEL_FILE.level, msg, *args,
super(CustomLogger, self).log(LogLevelFile.level, msg, *args,
**kwargs)

def critical(self, msg, *args, **kwargs):
Expand All @@ -118,11 +118,11 @@ class and causes 'TypeError: super() argument 1 must be type, not
classobj' so we use multiple inheritance to get around the problem.
"""
def format(self, record):
if record.levelno == LOG_LEVEL_TASK.level:
if record.levelno == LogLevelTask.level:
temp = '*' * (90 - len(record.msg) - 25)
self._fmt = "\n[%(asctime)s] %(levelname)s - [%(message)s] " + temp
self.datefmt = "%m/%d/%Y %H:%M:%S"
elif record.levelno in [logging.INFO, LOG_LEVEL_FILE.level]:
elif record.levelno in [logging.INFO, LogLevelFile.level]:
self._fmt = "%(message)s"
self.datefmt = ""
elif record.levelno in [logging.WARNING]:
Expand Down
12 changes: 6 additions & 6 deletions convert2rhel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def main():

# backup system release file before starting conversion process
loggerinst.task("Prepare: Backup System")
redhatrelease.system_release_file.backup()
redhatrelease.yum_conf.backup()
redhatrelease.SYSTEM_RELEASE_FILE.backup()
redhatrelease.YUM_CONF.backup()

# begin conversion process
process_phase = ConversionPhase.PRE_PONR_CHANGES
Expand Down Expand Up @@ -126,7 +126,7 @@ def user_to_accept_eula():
loggerinst = logging.getLogger(__name__)

eula_filename = "GLOBAL_EULA_RHEL"
eula_filepath = os.path.join(utils.data_dir, eula_filename)
eula_filepath = os.path.join(utils.DATA_DIR, eula_filename)
eula_text = utils.get_file_content(eula_filepath)
if eula_text:
loggerinst.info(eula_text)
Expand Down Expand Up @@ -206,9 +206,9 @@ def rollback_changes():
loggerinst = logging.getLogger(__name__)

loggerinst.warn("Abnormal exit! Performing rollback ...")
utils.changed_pkgs_control.restore_pkgs()
redhatrelease.system_release_file.restore()
redhatrelease.yum_conf.restore()
utils.CHANGED_PKGS_CONTROL.restore_pkgs()
redhatrelease.SYSTEM_RELEASE_FILE.restore()
redhatrelease.YUM_CONF.restore()
subscription.rollback_renamed_repo_files()
return

Expand Down
4 changes: 2 additions & 2 deletions convert2rhel/pkghandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,15 @@ def replace_non_rhel_installed_kernel(version):
pkg = "kernel-%s" % version

ret_code = utils.download_pkg(
pkg=pkg, dest=utils.tmp_dir, disablerepo=tool_opts.disablerepo,
pkg=pkg, dest=utils.TMP_DIR, disablerepo=tool_opts.disablerepo,
enablerepo=tool_opts.enablerepo)
if ret_code != 0:
loggerinst.critical("Unable to download %s from RHEL repository" % pkg)
return

loggerinst.info("Replacing %s %s with RHEL kernel with the same NEVRA ... " % (system_info.name, pkg))
output, ret_code = utils.run_subprocess(
'rpm -i --force --replacepkgs %s*' % os.path.join(utils.tmp_dir, pkg),
'rpm -i --force --replacepkgs %s*' % os.path.join(utils.TMP_DIR, pkg),
print_output=False)
if ret_code != 0:
loggerinst.critical("Unable to replace kernel package: %s" % output)
Expand Down
8 changes: 4 additions & 4 deletions convert2rhel/redhatrelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def install_release_pkg():
loggerinst = logging.getLogger(__name__)
loggerinst.info("Installing %s package" % get_release_pkg_name())

system_release_file.remove()
pkg_path = os.path.join(utils.data_dir, "redhat-release",
SYSTEM_RELEASE_FILE.remove()
pkg_path = os.path.join(utils.DATA_DIR, "redhat-release",
tool_opts.variant, "redhat-release-*")

success = utils.install_pkgs(glob.glob(pkg_path))
Expand Down Expand Up @@ -133,5 +133,5 @@ def get_yum_conf_filepath():


# Code to be executed upon module import
system_release_file = utils.RestorableFile(get_system_release_filepath())
yum_conf = utils.RestorableFile(YumConf.get_yum_conf_filepath())
SYSTEM_RELEASE_FILE = utils.RestorableFile(get_system_release_filepath())
YUM_CONF = utils.RestorableFile(YumConf.get_yum_conf_filepath())
8 changes: 4 additions & 4 deletions convert2rhel/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def package_analysis():

def get_repo_data_files():
"""Get list of paths to dark matrix-generated repository files."""
path = os.path.join(utils.data_dir, "repo-mapping", system_info.id)
path = os.path.join(utils.DATA_DIR, "repo-mapping", system_info.id)
# Skip the files for a different variant than the one in
# config file. Note: 'Common' files hold pkg names of all
# variants.
Expand Down Expand Up @@ -179,7 +179,7 @@ def get_supported_repos():
loggerinst = logging.getLogger(__name__)
loggerinst.info("Getting supported %s repositories ... "
% tool_opts.variant)
minimap_path = os.path.join(utils.data_dir, "repo-mapping", "repo_minimap")
minimap_path = os.path.join(utils.DATA_DIR, "repo-mapping", "repo_minimap")
minimap = utils.get_file_content(minimap_path, as_list=True)
repos = {}
for line in minimap:
Expand Down Expand Up @@ -285,7 +285,7 @@ def get_avail_repos():
repo_id_prefix = "Repo-id : "
for line in repos_raw.split("\n"):
if (line.startswith(repo_id_prefix)):
repoID = line.split(repo_id_prefix)[1]
repos.append(repoID)
repo_id = line.split(repo_id_prefix)[1]
repos.append(repo_id)

return repos
12 changes: 6 additions & 6 deletions convert2rhel/rhelvariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import logging
from convert2rhel import utils

_supported_variants = None
_SUPPORTED_VARIANTS = None


def is_variant_supported(variant):
Expand Down Expand Up @@ -66,17 +66,17 @@ def get_supported_variants():
"""Set the global variable once to not load the supported variants
from file every time.
"""
global _supported_variants
if not _supported_variants:
_supported_variants = _load_supported_variants_from_file()
return _supported_variants
global _SUPPORTED_VARIANTS
if not _SUPPORTED_VARIANTS:
_SUPPORTED_VARIANTS = _load_supported_variants_from_file()
return _SUPPORTED_VARIANTS


def _load_supported_variants_from_file():
"""The repo_minimap contains all the available repos whose name are
prepended by a variant.
"""
minimap_path = os.path.join(utils.data_dir, "repo-mapping", "repo_minimap")
minimap_path = os.path.join(utils.DATA_DIR, "repo-mapping", "repo_minimap")
minimap = utils.get_file_content(minimap_path, as_list=True)
supported_variants = []
for line in minimap:
Expand Down
2 changes: 1 addition & 1 deletion convert2rhel/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def hide_password(cmd):
def install_subscription_manager():
"""Install subscription-manager RPM and its dependencies."""
loggerinst = logging.getLogger(__name__)
sm_dir = os.path.join(utils.data_dir, "subscription-manager")
sm_dir = os.path.join(utils.DATA_DIR, "subscription-manager")
if not os.path.isdir(sm_dir) or not os.listdir(sm_dir):
loggerinst.critical("The %s directory does not exist or is empty."
" Using the subscription-manager is not documented"
Expand Down
8 changes: 4 additions & 4 deletions convert2rhel/systeminfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self):
# Operating system name (e.g. Oracle Linux)
self.name = None
# Single-word lowercase identificator of the system (e.g. oracle)
self.id = None
self.id = None # pylint: disable=C0103
# Major version of the operating system (e.g. 6)
self.version = None
# Platform architecture
Expand Down Expand Up @@ -62,7 +62,7 @@ def resolve_system_info(self):
self.id = self.name.split()[0].lower()
self.version = self._get_system_version()
self.arch = self._get_architecture()
utils.mkdir_p(utils.tmp_dir)
utils.mkdir_p(utils.TMP_DIR)

self.cfg_filename = self._get_cfg_filename()
self.cfg_content = self._get_cfg_content()
Expand Down Expand Up @@ -109,7 +109,7 @@ def _get_cfg_section(self, section_name):
file.
"""
cfg_parser = ConfigParser.ConfigParser()
cfg_filepath = os.path.join(utils.data_dir, "configs",
cfg_filepath = os.path.join(utils.DATA_DIR, "configs",
self.cfg_filename)
if not cfg_parser.read(cfg_filepath):
self.logger.critical("Current combination of system distribution"
Expand Down Expand Up @@ -158,4 +158,4 @@ def _generate_rpm_va(self):


# Code to be executed upon module import
system_info = SystemInfo()
system_info = SystemInfo() # pylint: disable=C0103
6 changes: 3 additions & 3 deletions convert2rhel/toolopts.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _process_cli_options(self):
loggerinst = logging.getLogger(__name__)
parsed_opts, _ = self._parser.parse_args()

global tool_opts
global tool_opts # pylint: disable=C0103
if parsed_opts.debug:
tool_opts.debug = True

Expand Down Expand Up @@ -223,7 +223,7 @@ def print_non_interactive_opts():
loggerinst = logging.getLogger(__name__)
loggerinst.info("For the non-interactive use of the tool, run the"
" following command:")
global tool_opts
global tool_opts # pylint: disable=C0103
cmd = utils.get_executable_name()

if tool_opts.disable_submgr:
Expand Down Expand Up @@ -252,4 +252,4 @@ def print_non_interactive_opts():


# Code to be executed upon module import
tool_opts = ToolOpts()
tool_opts = ToolOpts() # pylint: disable=C0103
14 changes: 7 additions & 7 deletions convert2rhel/unit_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

from convert2rhel import logger

tmp_dir = "/tmp/convert2rhel_test/"
nonexisting_dir = os.path.join(tmp_dir, "nonexisting_dir/")
nonexisting_file = os.path.join(tmp_dir, "nonexisting.file")
TMP_DIR = "/tmp/convert2rhel_test/"
NONEXISTING_DIR = os.path.join(TMP_DIR, "nonexisting_dir/")
NONEXISTING_FILE = os.path.join(TMP_DIR, "nonexisting.file")
# Dummy file for built-in open function
dummy_file = os.path.join(os.path.dirname(__file__), "dummy_file")
DUMMY_FILE = os.path.join(os.path.dirname(__file__), "dummy_file")

try:
from functools import wraps
Expand Down Expand Up @@ -110,10 +110,10 @@ def mock(class_or_module, orig_obj, mock_obj):
-- replaces the gpgkey module-scoped variable gpg_key_system_dir with the
"/nonexisting_dir/" string
"""
def wrap(fn):
def wrap(func):
# The @wraps decorator below makes sure the original object name
# and docstring (in case of a method/function) are preserved.
@wraps(fn)
@wraps(func)
def wrapped_fn(*args, **kwargs):
# Save temporarily the original object
orig_obj_saved = getattr(class_or_module, orig_obj)
Expand All @@ -129,7 +129,7 @@ def wrapped_fn(*args, **kwargs):
return_value = None
try:
try:
return_value = fn(*args, **kwargs)
return_value = func(*args, **kwargs)
except:
raise
finally:
Expand Down
8 changes: 4 additions & 4 deletions convert2rhel/unit_tests/cert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TestCert(unittest.TestCase):

class GlobMocked(unit_tests.MockFunction):
def __call__(self, *args, **kwargs):
return [os.path.join(cert._redhat_release_cert_dir, "69.pem")]
return [os.path.join(cert._REDHAT_RELEASE_CERT_DIR, "69.pem")]

class MkdirPMocked(unit_tests.MockFunction):
def __call__(self, *args, **kwargs):
Expand All @@ -52,9 +52,9 @@ def __call__(self, source, dest):
@unit_tests.mock(utils, "mkdir_p", MkdirPMocked())
@unit_tests.mock(shutil, "copy", CopyMocked())
@unit_tests.mock(system_info, "version", "5")
@unit_tests.mock(utils, "data_dir", base_data_dir)
@unit_tests.mock(utils, "DATA_DIR", base_data_dir)
def test_copy_cert_for_rhel_5(self):
cert.copy_cert_for_rhel_5()
self.assertEqual(shutil.copy.source,
os.path.join(cert._redhat_release_cert_dir, "69.pem"))
self.assertEqual(shutil.copy.dest, cert._subscription_manager_cert_dir)
os.path.join(cert._REDHAT_RELEASE_CERT_DIR, "69.pem"))
self.assertEqual(shutil.copy.dest, cert._SUBSCRIPTION_MANAGER_CERT_DIR)
18 changes: 9 additions & 9 deletions convert2rhel/unit_tests/logger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

class TestLogger(unittest.TestCase):

@unit_tests.mock(logger, "LOG_DIR", unit_tests.tmp_dir)
@unit_tests.mock(logger, "LOG_DIR", unit_tests.TMP_DIR)
def setUp(self):
# initialize class variables
self.LOG_DIR = logger.LOG_DIR
self.log_dir = logger.LOG_DIR
self.log_file = "convert2rhel.log"
self.test_msg = "testmsg"

Expand All @@ -54,21 +54,21 @@ def test_set_logger(self):
handlers = loggerinst.handlers

# verify both StreamHandler and FileHandler have been created
hasStreamHandlerInstance = False
hasFileHandlerInstance = False
has_stream_handler_instance = False
has_file_handler_instance = False
for handler in handlers:
if isinstance(handler, logging.StreamHandler):
hasStreamHandlerInstance = True
has_stream_handler_instance = True
if isinstance(handler, logging.FileHandler):
hasFileHandlerInstance = True
has_file_handler_instance = True

self.assertTrue(hasStreamHandlerInstance)
self.assertTrue(hasFileHandlerInstance)
self.assertTrue(has_stream_handler_instance)
self.assertTrue(has_file_handler_instance)

# verify log file name
for handler in handlers:
if type(handler) is logging.FileHandler:
log_path = os.path.join(self.LOG_DIR, self.log_file)
log_path = os.path.join(self.log_dir, self.log_file)
self.assertEqual(log_path, handler.baseFilename)

def test_log_format(self):
Expand Down
Loading

0 comments on commit ab1ee41

Please sign in to comment.