Replace ConfigParser with configparser

The ConfigParser module has been renamed to configparser in
Python 3. [1] Backport of this changes is also available for
Python 2. [2]

[1] https://docs.python.org/2/library/configparser.html
[2] https://pypi.python.org/pypi/configparser/3.2.0r3
This commit is contained in:
Radostin Stoyanov 2017-10-11 12:35:39 +01:00 committed by Cole Robinson
parent 40c678783e
commit 810ee09292
3 changed files with 12 additions and 12 deletions

View File

@ -234,8 +234,8 @@ class URLTests(unittest.TestCase):
def _make_tests(): def _make_tests():
import ConfigParser import configparser
cfg = ConfigParser.ConfigParser() cfg = configparser.ConfigParser()
cfg.read("tests/test_urls.ini") cfg.read("tests/test_urls.ini")
manualpath = "tests/test_urls_manual.ini" manualpath = "tests/test_urls_manual.ini"

View File

@ -21,11 +21,11 @@
Configuration variables that can be set at build time Configuration variables that can be set at build time
""" """
import ConfigParser import configparser
import os import os
_cfg = ConfigParser.ConfigParser() _cfg = configparser.ConfigParser()
_filepath = os.path.abspath(__file__) _filepath = os.path.abspath(__file__)
_srcdir = os.path.abspath(os.path.join(os.path.dirname(_filepath), "..")) _srcdir = os.path.abspath(os.path.join(os.path.dirname(_filepath), ".."))
_cfgpath = os.path.join(os.path.dirname(_filepath), "cli.cfg") _cfgpath = os.path.join(os.path.dirname(_filepath), "cli.cfg")
@ -46,7 +46,7 @@ def _get_param(name, default):
return default return default
try: try:
return _cfg.get("config", name) return _cfg.get("config", name)
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): except (configparser.NoOptionError, configparser.NoSectionError):
return default return default

View File

@ -19,7 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA. # MA 02110-1301 USA.
import ConfigParser import configparser
import ftplib import ftplib
import io import io
import logging import logging
@ -393,14 +393,14 @@ def _grabTreeinfo(fetcher):
return None return None
try: try:
treeinfo = ConfigParser.SafeConfigParser() treeinfo = configparser.SafeConfigParser()
treeinfo.read(tmptreeinfo) treeinfo.read(tmptreeinfo)
finally: finally:
os.unlink(tmptreeinfo) os.unlink(tmptreeinfo)
try: try:
treeinfo.get("general", "family") treeinfo.get("general", "family")
except ConfigParser.NoSectionError: except configparser.NoSectionError:
logging.debug("Did not find 'family' section in treeinfo") logging.debug("Did not find 'family' section in treeinfo")
return None return None
@ -601,7 +601,7 @@ class Distro(object):
try: try:
kernelpath = self._getTreeinfoMedia("kernel") kernelpath = self._getTreeinfoMedia("kernel")
initrdpath = self._getTreeinfoMedia("initrd") initrdpath = self._getTreeinfoMedia("initrd")
except ConfigParser.NoSectionError: except configparser.NoSectionError:
pass pass
if not kernelpath or not initrdpath: if not kernelpath or not initrdpath:
@ -737,15 +737,15 @@ class GenericDistro(Distro):
self._valid_kernel_path = ( self._valid_kernel_path = (
self._getTreeinfoMedia("kernel"), self._getTreeinfoMedia("kernel"),
self._getTreeinfoMedia("initrd")) self._getTreeinfoMedia("initrd"))
except (ConfigParser.NoSectionError, except (configparser.NoSectionError,
ConfigParser.NoOptionError) as e: configparser.NoOptionError) as e:
logging.debug(e) logging.debug(e)
if self.treeinfo.has_section(isoSection): if self.treeinfo.has_section(isoSection):
try: try:
self._valid_iso_path = self.treeinfo.get(isoSection, self._valid_iso_path = self.treeinfo.get(isoSection,
"boot.iso") "boot.iso")
except ConfigParser.NoOptionError as e: except configparser.NoOptionError as e:
logging.debug(e) logging.debug(e)
if self.type == "xen": if self.type == "xen":