From 626a02560d95061c126c851da86ac00e1d69247b Mon Sep 17 00:00:00 2001 From: Joey Loman Date: Fri, 31 Mar 2017 14:45:54 +0200 Subject: Make cache file names configurable --- foreman.ini | 1 + foreman_ansible_inventory.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/foreman.ini b/foreman.ini index 42312da..f6baf9d 100644 --- a/foreman.ini +++ b/foreman.ini @@ -15,4 +15,5 @@ want_facts = True [cache] path = . +filename = foreman_ansible_inventory max_age = 60 diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py index df838e0..0d2acf0 100755 --- a/foreman_ansible_inventory.py +++ b/foreman_ansible_inventory.py @@ -153,11 +153,14 @@ class ForemanInventory(object): cache_path = os.path.expanduser(config.get('cache', 'path')) except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): cache_path = '.' - (script, ext) = os.path.splitext(os.path.basename(__file__)) - self.cache_path_cache = cache_path + "/%s.cache" % script - self.cache_path_inventory = cache_path + "/%s.index" % script - self.cache_path_params = cache_path + "/%s.params" % script - self.cache_path_facts = cache_path + "/%s.facts" % script + try: + cache_filename = os.path.expanduser(config.get('cache', 'filename')) + except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): + (cache_filename, ext) = os.path.splitext(os.path.basename(__file__)) + self.cache_path_cache = cache_path + "/%s.cache" % cache_filename + self.cache_path_inventory = cache_path + "/%s.index" % cache_filename + self.cache_path_params = cache_path + "/%s.params" % cache_filename + self.cache_path_facts = cache_path + "/%s.facts" % cache_filename try: self.cache_max_age = config.getint('cache', 'max_age') except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): -- cgit v1.2.3