From 328b4db86925343e42c603389daaba5ffe26bde3 Mon Sep 17 00:00:00 2001 From: Kowshik Jois B S Date: Wed, 30 Oct 2024 19:54:17 +0530 Subject: [PATCH] Fixed static check issues! Signed-off-by: Kowshik Jois B S --- scripts/regression.py | 10 +++------- virttest/asset.py | 8 ++------ virttest/staging/utils_koji.py | 9 +++------ virttest/tests/unattended_install.py | 8 ++------ virttest/utils_config.py | 10 +++------- virttest/utils_disk.py | 8 ++------ virttest/utils_test/__init__.py | 4 ++-- 7 files changed, 17 insertions(+), 40 deletions(-) diff --git a/scripts/regression.py b/scripts/regression.py index b270c1ca56..bdebc992df 100755 --- a/scripts/regression.py +++ b/scripts/regression.py @@ -8,16 +8,12 @@ """ from __future__ import division +import configparser import os import re import sys import warnings -try: - import configparser as ConfigParser -except ImportError: - import ConfigParser - import MySQLdb @@ -32,7 +28,7 @@ def getoutput(cmd): def exec_sql(cmd, conf="../../global_config.ini"): - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read(conf) user = config.get("AUTOTEST_WEB", "user") passwd = config.get("AUTOTEST_WEB", "password") @@ -490,7 +486,7 @@ def tee_line(content, filepath, n=None): def analyze(test, sample_type, arg1, arg2, configfile): """Compute averages/p-vales of two samples, print results nicely""" - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read(configfile) ignore_col = int(config.get(test, "ignore_col")) avg_update = config.get(test, "avg_update") diff --git a/virttest/asset.py b/virttest/asset.py index 6ef69b311f..d40af7352b 100644 --- a/virttest/asset.py +++ b/virttest/asset.py @@ -1,3 +1,4 @@ +import configparser import glob import logging import os @@ -6,11 +7,6 @@ from six import StringIO -try: - import configparser as ConfigParser -except ImportError: - import ConfigParser - from avocado.utils import astring, crypto, download, genio, git, process from six import string_types from six.moves import urllib @@ -39,7 +35,7 @@ def __init__(self, cfg, tmpdir=data_dir.get_tmp_dir(), raise_errors=False): ValueError exceptions. """ # Base Parser - self.parser = ConfigParser.ConfigParser() + self.parser = configparser.ConfigParser() # Raise errors when lacking values self.raise_errors = raise_errors # File is already a file like object diff --git a/virttest/staging/utils_koji.py b/virttest/staging/utils_koji.py index 14ac30cd66..ea0ac9d67e 100644 --- a/virttest/staging/utils_koji.py +++ b/virttest/staging/utils_koji.py @@ -1,3 +1,4 @@ +import configparser import logging import os import time @@ -6,10 +7,6 @@ from html.parser import HTMLParser except ImportError: from HTMLParser import HTMLParser -try: - import configparser as ConfigParser -except ImportError: - import ConfigParser from avocado.utils import astring, download, path from six.moves import urllib @@ -223,7 +220,7 @@ def read_config(self, check_is_valid=True): if not self.is_config_valid(): raise ValueError('Koji config "%s" is not valid' % self.config) - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read(self.config) basename = os.path.basename(self.command) @@ -287,7 +284,7 @@ def is_config_valid(self): LOG.error('Koji config "%s" is not readable', self.config) koji_config_ok = False - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read(self.config) basename = os.path.basename(self.command) if not config.has_section(basename): diff --git a/virttest/tests/unattended_install.py b/virttest/tests/unattended_install.py index 706a979cf2..5e6bf79e96 100644 --- a/virttest/tests/unattended_install.py +++ b/virttest/tests/unattended_install.py @@ -1,5 +1,6 @@ from __future__ import division +import configparser import logging import os import re @@ -10,11 +11,6 @@ import time import xml.dom.minidom -try: - import configparser as ConfigParser -except ImportError: - import ConfigParser - from aexpect import remote from avocado.core import exceptions from avocado.utils import astring, crypto, download, iso9660, process @@ -523,7 +519,7 @@ def answer_kickstart(self, answer_path): answer_file.write(contents) def answer_windows_ini(self, answer_path): - parser = ConfigParser.ConfigParser() + parser = configparser.ConfigParser() parser.read(self.unattended_file) # First, replacing the CDKEY if self.cdkey: diff --git a/virttest/utils_config.py b/virttest/utils_config.py index 6e2006126e..a476c13da4 100644 --- a/virttest/utils_config.py +++ b/virttest/utils_config.py @@ -1,14 +1,10 @@ import ast +import configparser import logging import os.path from six import StringIO -try: - import configparser as ConfigParser -except ImportError: - import ConfigParser - from avocado.utils import distro LOG = logging.getLogger("avocado." + __name__) @@ -92,7 +88,7 @@ class SectionlessConfig(object): def __init__(self, path): self.path = path - self.parser = ConfigParser.ConfigParser() + self.parser = configparser.ConfigParser() # Prevent of converting option names to lower case self.parser.optionxform = str self.backup_content = open(path, "r").read() @@ -112,7 +108,7 @@ def __len__(self): def __getitem__(self, option): try: return self.parser.get("root", option) - except ConfigParser.NoOptionError: + except configparser.NoOptionError: raise ConfigNoOptionError(option, self.path) def __setitem__(self, option, value): diff --git a/virttest/utils_disk.py b/virttest/utils_disk.py index 0981b1ea6f..510b793918 100644 --- a/virttest/utils_disk.py +++ b/virttest/utils_disk.py @@ -3,6 +3,7 @@ :copyright: Red Hat Inc. """ +import configparser import glob import logging import os @@ -14,11 +15,6 @@ import string import tempfile -try: - import configparser as ConfigParser -except ImportError: - import ConfigParser - from functools import cmp_to_key from avocado.core import exceptions @@ -1438,7 +1434,7 @@ def setup_virtio_win2003(self, virtio_floppy, virtio_oemsetup_id): "driver image has this file" ) - parser = ConfigParser.ConfigParser() + parser = configparser.ConfigParser() parser.read(txtsetup_oem) if not parser.has_section("Defaults"): diff --git a/virttest/utils_test/__init__.py b/virttest/utils_test/__init__.py index 778bbcd1c2..d687fccbaf 100755 --- a/virttest/utils_test/__init__.py +++ b/virttest/utils_test/__init__.py @@ -1601,9 +1601,9 @@ def config_control(control_path, job_args=None): except Exception: # Leak global_config.ini, generate a mini configuration # to ensure client tests can work. - import configParser + import configparser - config = configParser.ConfigParser() + config = configparser.ConfigParser() for section in ["CLIENT", "COMMON"]: config.add_section(section) config.set("COMMON", "crash_handling_enabled", "True")