summaryrefslogtreecommitdiff
path: root/gitlab/config.py
diff options
context:
space:
mode:
authorMax Wittig <max.wittig@siemens.com>2018-11-04 16:52:32 +0100
committerGauvain Pocentek <gauvainpocentek@gmail.com>2018-11-04 16:52:32 +0100
commit6ad9da04496f040ae7d95701422434bc935a5a80 (patch)
tree55020c49fbf3c8519efff6a45b6a4f2cfa93e496 /gitlab/config.py
parent742243f4f43042d4b561e3875dc38e560bb71624 (diff)
downloadgitlab-6ad9da04496f040ae7d95701422434bc935a5a80.tar.gz
fix(cli): exit on config parse error, instead of crashing
* Exit and hint user about possible errors * test: adjust test cases to config missing error
Diffstat (limited to 'gitlab/config.py')
-rw-r--r--gitlab/config.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/gitlab/config.py b/gitlab/config.py
index 9f4c11d..1c76594 100644
--- a/gitlab/config.py
+++ b/gitlab/config.py
@@ -37,10 +37,27 @@ class GitlabDataError(ConfigError):
pass
+class GitlabConfigMissingError(ConfigError):
+ pass
+
+
class GitlabConfigParser(object):
def __init__(self, gitlab_id=None, config_files=None):
self.gitlab_id = gitlab_id
_files = config_files or _DEFAULT_FILES
+ file_exist = False
+ for file in _files:
+ if os.path.exists(file):
+ file_exist = True
+ if not file_exist:
+ raise GitlabConfigMissingError(
+ "Config file not found. \nPlease create one in "
+ "one of the following locations: {} \nor "
+ "specify a config file using the '-c' parameter.".format(
+ ", ".join(_DEFAULT_FILES)
+ )
+ )
+
self._config = configparser.ConfigParser()
self._config.read(_files)