From d8ebe8cb91ae3eaa9f74e5e8f552edd28bfaea47 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 31 Dec 2013 00:56:41 -0800 Subject: [PATCH] support command line option to specify config file name --- planetstack/planetstack/config.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/planetstack/planetstack/config.py b/planetstack/planetstack/config.py index b9abd3a..86e3bbd 100644 --- a/planetstack/planetstack/config.py +++ b/planetstack/planetstack/config.py @@ -7,11 +7,14 @@ import tempfile import codecs from StringIO import StringIO from util.xml import Xml +from optparse import OptionParser default_config = \ """ """ +DEFAULT_CONFIG_FN = '/opt/planetstack/plstackapi_config' + def isbool(v): return v.lower() in ("true", "false") @@ -20,7 +23,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 +35,16 @@ class Config: self.create(self.filename) self.load(self.filename) + def get_config_fn(self): + parser = OptionParser(usage="%s [options]" % sys.argv[0], + description="The planetstack observer") + + parser.add_option("-C", "--config-file", dest="config_fn", + help="name of observer config file", metavar="FILENAME", default=DEFAULT_CONFIG_FN) + + (options, args) = parser.parse_args(sys.argv[1:]) + + return options.config_fn def _header(self): header = """ -- 2.43.0