Allow global ciwatch conf file
We want to be able to store the configuration in /etc, as opposed to source directory. Try to load configuration from source dir first, and fallback to /etc/ciwatch/ci-watch.conf. Wrap everything into a function and add exception if no configuration is found. We want to move away from having globals. Original Change-Id: I91f2adc6e90b6252c5839a5ef8dde0fe7cd137f8 Change-Id: Ic939caeff538e290418cff2a6438d63a024994b0
This commit is contained in:
parent
bde64a6a1f
commit
0683170484
@ -16,9 +16,19 @@ import os
|
||||
|
||||
from iniparse import INIConfig
|
||||
|
||||
_fdir = os.path.dirname(os.path.realpath(__file__))
|
||||
_conf_dir = os.path.dirname(_fdir)
|
||||
cfg = INIConfig(open(_conf_dir + '/ci-watch.conf'))
|
||||
|
||||
def get_config():
|
||||
this_file = os.path.dirname(os.path.realpath(__file__))
|
||||
this_dir = os.path.dirname(this_file)
|
||||
conf_files = [os.path.join(this_dir, 'ci-watch.conf'),
|
||||
'/etc/ciwatch/ci-watch.conf']
|
||||
# Read first existing conf file, ignore the rest
|
||||
for conf_file in conf_files:
|
||||
if os.path.exists(conf_file):
|
||||
return INIConfig(open(conf_file))
|
||||
raise Exception('Could not read configuration from %s' % conf_files)
|
||||
|
||||
cfg = get_config()
|
||||
|
||||
|
||||
def get_projects():
|
||||
|
Loading…
x
Reference in New Issue
Block a user