From 34ac7b11c72a4ef30a3c646271410578245cd582 Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Thu, 18 Dec 2014 11:07:13 -0500 Subject: changed multi_ec2.py to print the json result string instead of the python pretty print string. --- inventory/.gitignore | 2 -- inventory/multi_ec2.py | 19 +++++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) delete mode 100644 inventory/.gitignore (limited to 'inventory') diff --git a/inventory/.gitignore b/inventory/.gitignore deleted file mode 100644 index 6b11bed20..000000000 --- a/inventory/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -multi_ec2.yaml -*pyc diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index 456bda8c8..1fe18a67e 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -17,7 +17,7 @@ class MultiEc2(object): self.config = None self.all_ec2_results = {} self.result = {} - self.cache_path_cache = os.path.expanduser('~/.ansible/tmp/multi_ec2_inventory.cache') + self.cache_path = os.path.expanduser('~/.ansible/tmp/multi_ec2_inventory.cache') self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__))) self.config_file = os.path.join(self.file_path,"multi_ec2.yaml") self.parse_cli_args() @@ -167,11 +167,10 @@ class MultiEc2(object): def is_cache_valid(self): ''' Determines if the cache files have expired, or if it is still valid ''' - if os.path.isfile(self.cache_path_cache): - mod_time = os.path.getmtime(self.cache_path_cache) + if os.path.isfile(self.cache_path): + mod_time = os.path.getmtime(self.cache_path) current_time = time() if (mod_time + self.config['cache_max_age']) > current_time: - #if os.path.isfile(self.cache_path_index): return True return False @@ -190,14 +189,14 @@ class MultiEc2(object): ''' Writes data in JSON format to a file ''' json_data = self.json_format_dict(self.result, True) - with open(self.cache_path_cache, 'w') as cache: + with open(self.cache_path, 'w') as cache: cache.write(json_data) def get_inventory_from_cache(self): ''' Reads the inventory from the cache file and returns it as a JSON object ''' - with open(self.cache_path_cache, 'r') as cache: + with open(self.cache_path, 'r') as cache: self.result = json.loads(cache.read()) def json_format_dict(self, data, pretty=False): @@ -209,10 +208,10 @@ class MultiEc2(object): else: return json.dumps(data) + def result_str(self): + return self.json_format_dict(self.result, True) + if __name__ == "__main__": mi = MultiEc2() - #print mi.result - pp = pprint.PrettyPrinter(indent=2) - pp.pprint(mi.result) - + print mi.result_str() -- cgit v1.2.3