From 1d8854b04515f768b5d72207738e6372abcedae3 Mon Sep 17 00:00:00 2001 From: Greg Dahlman Date: Thu, 20 Jul 2017 10:35:17 -0700 Subject: [PATCH] Python 3 fix for consul_io inventory (#26510) * Python 3 fix for consul_io inventory * Remove configparser CamelCase try statement * revert to python2.6 compatible try;except * Fix pip8 error E302 --- contrib/inventory/consul_io.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/contrib/inventory/consul_io.py b/contrib/inventory/consul_io.py index 27406c6167b..4a7ed021d0f 100755 --- a/contrib/inventory/consul_io.py +++ b/contrib/inventory/consul_io.py @@ -133,7 +133,11 @@ import os import re import argparse import sys -import ConfigParser + +try: + import configparser +except ImportError: + import ConfigParser as configparser def get_log_filename(): @@ -421,7 +425,7 @@ class ConsulConfig(dict): def read_settings(self): ''' Reads the settings from the consul_io.ini file (or consul.ini for backwards compatibility)''' - config = ConfigParser.SafeConfigParser() + config = configparser.SafeConfigParser() if os.path.isfile(os.path.dirname(os.path.realpath(__file__)) + '/consul_io.ini'): config.read(os.path.dirname(os.path.realpath(__file__)) + '/consul_io.ini') else: @@ -469,7 +473,10 @@ class ConsulConfig(dict): scheme = 'http' if hasattr(self, 'url'): - from urlparse import urlparse + try: + from urlparse import urlparse + except ImportError: + from urllib.parse import urlparse o = urlparse(self.url) if o.hostname: host = o.hostname