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..a5ae4b0cee 100644 --- a/virttest/asset.py +++ b/virttest/asset.py @@ -1,18 +1,12 @@ +import configparser import glob import logging import os import re import shutil -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 import StringIO, string_types from six.moves import urllib from virttest import data_dir @@ -39,7 +33,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..538ca08b06 100644 --- a/virttest/staging/utils_koji.py +++ b/virttest/staging/utils_koji.py @@ -6,10 +6,8 @@ from html.parser import HTMLParser except ImportError: from HTMLParser import HTMLParser -try: - import configparser as ConfigParser -except ImportError: - import ConfigParser + +import configparser from avocado.utils import astring, download, path from six.moves import urllib @@ -223,7 +221,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 +285,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..546f7d10a1 100644 --- a/virttest/utils_config.py +++ b/virttest/utils_config.py @@ -1,15 +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 +from six import StringIO LOG = logging.getLogger("avocado." + __name__) @@ -92,7 +87,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 +107,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..57d54992c4 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 @@ -13,12 +14,6 @@ import stat 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 +1433,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")