aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2010-07-10 20:10:21 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2010-07-10 20:10:21 -0300
commitc8e6ad41d974d9005d03ae205ae2bbd3e4c500af (patch)
tree94590f12ef5de1f87103ba48032fb534d4b9d08b /g_octave
parentfixed the url of the db_mirror (diff)
downloadg-octave-c8e6ad41d974d9005d03ae205ae2bbd3e4c500af.tar.gz
g-octave-c8e6ad41d974d9005d03ae205ae2bbd3e4c500af.tar.bz2
g-octave-c8e6ad41d974d9005d03ae205ae2bbd3e4c500af.zip
added support to the override of configuration values using environment
variables (starting with GOCTAVE_)
Diffstat (limited to 'g_octave')
-rw-r--r--g_octave/config.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/g_octave/config.py b/g_octave/config.py
index 6f4919a..8e1445f 100644
--- a/g_octave/config.py
+++ b/g_octave/config.py
@@ -31,10 +31,11 @@ class Config(object):
'pkg_cache': '',
'log_level': '',
'log_file': '/var/log/g-octave.log',
+ 'package_manager': 'emerge',
}
_section_name = 'main'
-
+ _env_namespace = 'GOCTAVE_'
def __init__(self, fetch_phase=False, config_file=None, create_dirs=True):
@@ -56,8 +57,8 @@ class Config(object):
self._config.read(self._config_file)
- _db = self._config.get(self._section_name, 'db')
- _overlay = self._config.get(self._section_name, 'overlay')
+ _db = self._getattr('db')
+ _overlay = self._getattr('overlay')
for dir in [_db, _overlay]:
if not os.path.exists(dir) and create_dirs:
@@ -82,10 +83,21 @@ class Config(object):
def __getattr__(self, attr):
if attr in self._defaults:
- return self._config.get(self._section_name, attr)
+ return self._getattr(attr)
elif attr in self._info:
return self._info[attr]
elif attr == 'cache' and 'files' in self._cache:
return self._cache['files']
else:
raise ConfigException('Invalid option: %s' % attr)
+
+
+ def _getattr(self, attr):
+ from_env = os.environ.get(self._env_namespace + attr.upper(), None)
+ if from_env is None:
+ return self._config.get(self._section_name, attr)
+ return from_env
+
+
+ def overlay_bootstrap(self):
+ pass