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
pull/27131/head
Greg Dahlman 7 years ago committed by Toshio Kuratomi
parent 640d057f3f
commit 1d8854b045

@ -133,7 +133,11 @@ import os
import re import re
import argparse import argparse
import sys import sys
import ConfigParser
try:
import configparser
except ImportError:
import ConfigParser as configparser
def get_log_filename(): def get_log_filename():
@ -421,7 +425,7 @@ class ConsulConfig(dict):
def read_settings(self): def read_settings(self):
''' Reads the settings from the consul_io.ini file (or consul.ini for backwards compatibility)''' ''' 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'): 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') config.read(os.path.dirname(os.path.realpath(__file__)) + '/consul_io.ini')
else: else:
@ -469,7 +473,10 @@ class ConsulConfig(dict):
scheme = 'http' scheme = 'http'
if hasattr(self, 'url'): if hasattr(self, 'url'):
from urlparse import urlparse try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse
o = urlparse(self.url) o = urlparse(self.url)
if o.hostname: if o.hostname:
host = o.hostname host = o.hostname

Loading…
Cancel
Save