user's can't set/unset is_admin, is_active and is_readonly values in Login Details...
[plstackapi.git] / planetstack / planetstack / config.py
index b9abd3a..f7d9c9e 100644 (file)
@@ -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 <something>" 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 = """