From 708592ca885938db734c243732ecbcdc6413f2fa Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Tue, 19 Mar 2019 15:24:28 -0400 Subject: [PATCH] Python 2 leftovers: drop conditional import of ConfigParser We can now just use the module name as in Python 3 standard library. Signed-off-by: Cleber Rosa --- avocado/core/settings.py | 16 ++++++---------- avocado/utils/software_manager.py | 8 ++------ docs/source/Configuration.rst | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/avocado/core/settings.py b/avocado/core/settings.py index 73c54d9c..e58359b1 100644 --- a/avocado/core/settings.py +++ b/avocado/core/settings.py @@ -13,16 +13,12 @@ # Author: Travis Miller """ -Reads the avocado settings from a .ini file (from python ConfigParser). +Reads the avocado settings from a .ini file (with Python's configparser). """ import ast import os import glob - -try: - import ConfigParser -except ImportError: - import configparser as ConfigParser +import configparser from pkg_resources import resource_filename from pkg_resources import resource_isdir @@ -144,7 +140,7 @@ def convert_value_type(value, value_type): class Settings(object): """ - Simple wrapper around ConfigParser, with a key type conversion available. + Simple wrapper around configparser, with a key type conversion available. """ no_default = object() @@ -155,7 +151,7 @@ class Settings(object): :param config_path: Path to a config file. Useful for unittesting. """ - self.config = ConfigParser.ConfigParser() + self.config = configparser.ConfigParser() self.config_paths = [] self.all_config_paths = [] _source_tree_root = os.path.dirname(os.path.dirname(os.path.dirname( @@ -295,9 +291,9 @@ class Settings(object): """ try: val = self.config.get(section, key) - except ConfigParser.NoSectionError: + except configparser.NoSectionError: return self._handle_no_section(section, default) - except ConfigParser.Error: + except configparser.Error: return self._handle_no_value(section, key, default) if not val.strip() and not allow_blank: diff --git a/avocado/utils/software_manager.py b/avocado/utils/software_manager.py index 1e98d016..3acfcf8d 100644 --- a/avocado/utils/software_manager.py +++ b/avocado/utils/software_manager.py @@ -40,6 +40,7 @@ import shutil import logging import optparse import tempfile +import configparser try: import yum @@ -48,11 +49,6 @@ except ImportError: else: HAS_YUM_MODULE = True -try: - import ConfigParser -except ImportError: - import configparser as ConfigParser - from . import process from . import data_factory from . import distro @@ -403,7 +399,7 @@ class YumBackend(RpmBackend): base_arguments = '-y' self.base_command = executable + ' ' + base_arguments self.repo_file_path = '/etc/yum.repos.d/avocado-managed.repo' - self.cfgparser = ConfigParser.ConfigParser() + self.cfgparser = configparser.ConfigParser() self.cfgparser.read(self.repo_file_path) y_cmd = executable + ' --version | head -1' cmd_result = process.run(y_cmd, ignore_status=True, diff --git a/docs/source/Configuration.rst b/docs/source/Configuration.rst index ae3ad8db..7b8fb0e7 100644 --- a/docs/source/Configuration.rst +++ b/docs/source/Configuration.rst @@ -8,7 +8,7 @@ and that's why a configuration system is in place to help with those cases The Avocado config file format is based on the (informal) `INI file 'specification' `__, that is implemented by -Python's :mod:`ConfigParser`. The format is simple and straightforward, composed by `sections`, +Python's :mod:`configparser`. The format is simple and straightforward, composed by `sections`, that contain a number of `keys` and `values`. Take for example a basic Avocado config file: .. code-block:: ini -- GitLab