X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fplanetstack%2Fconfig.py;h=f7d9c9e23ab230809cb2a377a71d0193fe8b0a7b;hb=e42cedcb2caf20b1118db570a9650348958d7590;hp=b9abd3ab891448efd8c0b39affe4c6d4336e700e;hpb=04c94ad7d56a164d1f1a5d05c3b5ced5d792bae2;p=plstackapi.git diff --git a/planetstack/planetstack/config.py b/planetstack/planetstack/config.py index b9abd3a..f7d9c9e 100644 --- a/planetstack/planetstack/config.py +++ b/planetstack/planetstack/config.py @@ -12,6 +12,8 @@ default_config = \ """ """ +DEFAULT_CONFIG_FN = '/opt/planetstack/plstackapi_config' + def isbool(v): return v.lower() in ("true", "false") @@ -20,7 +22,10 @@ def str2bool(v): class Config: - def __init__(self, config_file='/opt/planetstack/plstackapi_config'): + def __init__(self, config_file=None): + if (config_file==None): + config_file = self.get_config_fn() + self._files = [] self.config_path = os.path.dirname(config_file) self.config = ConfigParser.ConfigParser() @@ -29,6 +34,19 @@ class Config: self.create(self.filename) self.load(self.filename) + def get_config_fn(self): + # Look for "-C " to get the + # name of the config file. Using a real OptionParser here is + # problematic as it will throw 'no such option' errors for options + # that it does not understand. + + last = None + for arg in sys.argv: + if (last=="-C"): + return arg + last = arg + + return DEFAULT_CONFIG_FN def _header(self): header = """