From cb01f33d1e3c99399c19b2e3a7a3391be7bb698c Mon Sep 17 00:00:00 2001 From: Thomas Stringer Date: Thu, 5 Oct 2017 14:49:35 -0400 Subject: [PATCH] refactor azure dynamic inventory script configparser import to support python3 (#31370) * refactor configparser import to support python3 * change ModuleNotFoundError to ImportError --- contrib/inventory/azure_rm.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/contrib/inventory/azure_rm.py b/contrib/inventory/azure_rm.py index b3b7e1e9045..6c79d8b9a2c 100755 --- a/contrib/inventory/azure_rm.py +++ b/contrib/inventory/azure_rm.py @@ -187,14 +187,18 @@ Version: 1.0.0 ''' import argparse -import ConfigParser import json import os import re import sys import inspect -import traceback +try: + # python2 + import ConfigParser as cp +except ImportError: + # python3 + import configparser as cp from packaging.version import Version @@ -326,7 +330,7 @@ class AzureRM(object): path = expanduser("~") path += "/.azure/credentials" try: - config = ConfigParser.ConfigParser() + config = cp.ConfigParser() config.read(path) except Exception as exc: self.fail("Failed to access {0}. Check that the file exists and you have read " @@ -795,7 +799,7 @@ class AzureInventory(object): config = None settings = None try: - config = ConfigParser.ConfigParser() + config = cp.ConfigParser() config.read(path) except: pass