Skip to content

Commit

Permalink
ConfigParser: Removed py2 support
Browse files Browse the repository at this point in the history
Signed-off-by: Kowshik Jois B S <[email protected]>
  • Loading branch information
bskjois committed Nov 1, 2024
1 parent 452d4c2 commit cdf80c8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 46 deletions.
10 changes: 3 additions & 7 deletions scripts/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 3 additions & 9 deletions virttest/asset.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions virttest/staging/utils_koji.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions virttest/tests/unattended_install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division

import configparser
import logging
import os
import re
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 4 additions & 9 deletions virttest/utils_config.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down Expand Up @@ -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()
Expand All @@ -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):
Expand Down
9 changes: 2 additions & 7 deletions virttest/utils_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:copyright: Red Hat Inc.
"""
import configparser
import glob
import logging
import os
Expand All @@ -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
Expand Down Expand Up @@ -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"):
Expand Down
4 changes: 2 additions & 2 deletions virttest/utils_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit cdf80c8

Please sign in to comment.