pre-upload: import configparser from six.moves
This has been renamed in Python 3 from ConfigParser to configparser.
BUG=chromium:1003955
TEST=unittests pass
Change-Id: I1af519d821872ea73dcadb9672ffa2b52c5e55e0
Reviewed-on: https://chromium-review.googlesource.com/1803857
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Will Bradley <wbbradley@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index d20381c..c1c49ad 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -13,7 +13,6 @@
import argparse
import collections
-import ConfigParser
import datetime
import fnmatch
import functools
@@ -24,6 +23,8 @@
import stat
import StringIO
+from six.moves import configparser
+
from errors import (VerifyException, HookFailure, PrintErrorForProject,
PrintErrorsForCommit)
@@ -1561,14 +1562,15 @@
# pre-cq configs it requests are existing ones.
for f in files:
try:
- parser = ConfigParser.SafeConfigParser()
+ parser = configparser.SafeConfigParser()
# Prior to python3, ConfigParser has no read_string method, so we must
# pass it either a file path or file like object. And we must use
# _get_file_content to fetch file contents to ensure we are examining the
# commit diff, rather than whatever's on disk.
+ # TODO(vapier): Once we migrate this to Python 3 only, cut it over.
contents = _get_file_content(f, commit)
parser.readfp(StringIO.StringIO(contents))
- except ConfigParser.Error as e:
+ except configparser.Error as e:
msg = ('Unable to parse COMMIT-QUEUE.ini file at %s due to %s.' %
(f, e))
return HookFailure(msg)
@@ -1847,7 +1849,7 @@
options = config.get(SECTION_OPTIONS, flag)
hooks[flag] = functools.partial(hooks[flag], options=options.split())
hooks[flag].__name__ = flag
- except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
+ except (configparser.NoOptionError, configparser.NoSectionError):
pass
enabled_hooks = set(hooks[x] for x in enable_flags)
@@ -1877,12 +1879,12 @@
project: A string, name of the project.
presubmit: A Boolean, True if the check is run as a git pre-submit script.
"""
- config = ConfigParser.RawConfigParser()
+ config = configparser.RawConfigParser()
try:
config.read(_CONFIG_FILE)
- except ConfigParser.Error:
+ except configparser.Error:
# Just use an empty config file
- config = ConfigParser.RawConfigParser()
+ config = configparser.RawConfigParser()
if presubmit:
hooks = _COMMON_HOOKS