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:
Mikhail S Medvedev 2015-09-22 11:00:56 -05:00
parent bde64a6a1f
commit 0683170484
1 changed files with 13 additions and 3 deletions

View File

@ -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():