From faa364138450fc390906956e2db358387200e19d Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 3 Oct 2016 11:42:30 +0200 Subject: Python3 (#37) * Handle python3's configparser as well * tests: Open file in text mode to avoid string bytes conversion with Python3 * tests: drop unnecessary dict These arent sortable in Python3 * Convert returned facts to list While Python2 has a list here Python3 returns dict_values which is not indexable as is. * tests: Parse url for comparison Python3 uses hash seeds for comparison so the QS parts dont have a fixed order. * Test python3.4 and python3.5 as well --- foreman_ansible_inventory.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'foreman_ansible_inventory.py') diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py index a77ca5b..d969360 100755 --- a/foreman_ansible_inventory.py +++ b/foreman_ansible_inventory.py @@ -21,7 +21,6 @@ from __future__ import print_function import argparse -import ConfigParser import copy import os import re @@ -30,6 +29,12 @@ from requests.auth import HTTPBasicAuth import sys from time import time +try: + import ConfigParser +except ImportError: + import configparser as ConfigParser + + try: import json except ImportError: @@ -237,7 +242,7 @@ class ForemanInventory(object): if len(ret.values()) == 0: facts = {} elif len(ret.values()) == 1: - facts = ret.values()[0] + facts = list(ret.values())[0] else: raise ValueError("More than one set of facts returned for '%s'" % host) return facts -- cgit v1.2.3