summaryrefslogtreecommitdiffstats
path: root/jenkins_jobs/parser.py
diff options
context:
space:
mode:
authorWayne Warren <waynr+launchpad@sdf.org>2015-12-27 23:07:23 -0800
committerDarragh Bailey <dbailey@hpe.com>2016-07-22 17:33:25 +0100
commit4f04de1f9ad706971f12508dacee5332df0a3a11 (patch)
treedfb50e17bd98a7cd2887b9d1c3e8c228fc47283e /jenkins_jobs/parser.py
parentb6e9080a8922e1f290c1ae760397dabf2cb0bbff (diff)
downloadpython-jenkins-job-builder-4f04de1f9ad706971f12508dacee5332df0a3a11.tar.gz
python-jenkins-job-builder-4f04de1f9ad706971f12508dacee5332df0a3a11.tar.xz
python-jenkins-job-builder-4f04de1f9ad706971f12508dacee5332df0a3a11.zip
Use JJBConfig in YamlParser.
This commit sees JJBConfig start to take the form it ought to have, namely using attributes to represent different logical sections of configuration that target specific subsystems of JJB. It also moves ConfigParser data retrieval from jenkins_jobs.modules.helpers.get_value_from_yaml_or_config_file() to jenkins_jobs.config.JJBConfig.get_module_config() TODO: Add JJBConfig tests to validate the behavior of JJBConfig in specific circumstances. Change-Id: I053d165559f5325a2f40b239117a86e6d0f3ef37
Diffstat (limited to 'jenkins_jobs/parser.py')
-rw-r--r--jenkins_jobs/parser.py40
1 files changed, 12 insertions, 28 deletions
diff --git a/jenkins_jobs/parser.py b/jenkins_jobs/parser.py
index 4d5cf246..8a1949d1 100644
--- a/jenkins_jobs/parser.py
+++ b/jenkins_jobs/parser.py
@@ -70,27 +70,17 @@ def combination_matches(combination, match_combinations):
class YamlParser(object):
- def __init__(self, config=None, plugins_info=None):
+ def __init__(self, jjb_config=None, plugins_info=None):
self.data = {}
self.jobs = []
self.xml_jobs = []
- self.config = config
- self.registry = ModuleRegistry(self.config, plugins_info)
- self.path = ["."]
- if self.config:
- if config.has_section('job_builder') and \
- config.has_option('job_builder', 'include_path'):
- self.path = config.get('job_builder',
- 'include_path').split(':')
- self.keep_desc = self.get_keep_desc()
-
- def get_keep_desc(self):
- keep_desc = False
- if self.config and self.config.has_section('job_builder') and \
- self.config.has_option('job_builder', 'keep_descriptions'):
- keep_desc = self.config.getboolean('job_builder',
- 'keep_descriptions')
- return keep_desc
+
+ self.jjb_config = jjb_config
+ self.keep_desc = jjb_config.yamlparser['keep_descriptions']
+ self.path = jjb_config.yamlparser['include_path']
+
+ self.registry = ModuleRegistry(jjb_config.config_parser,
+ plugins_info)
def parse_fp(self, fp):
# wrap provided file streams to ensure correct encoding used
@@ -129,8 +119,7 @@ class YamlParser(object):
def _handle_dups(self, message):
- if not (self.config and self.config.has_section('job_builder') and
- self.config.getboolean('job_builder', 'allow_duplicates')):
+ if not self.jjb_config.yamlparser['allow_duplicates']:
logger.error(message)
raise JenkinsJobsException(message)
else:
@@ -311,19 +300,14 @@ class YamlParser(object):
logger.debug('Excluding combination %s', str(params))
continue
- allow_empty_variables = self.config \
- and self.config.has_section('job_builder') \
- and self.config.has_option(
- 'job_builder', 'allow_empty_variables') \
- and self.config.getboolean(
- 'job_builder', 'allow_empty_variables')
-
for key in template.keys():
if key not in params:
params[key] = template[key]
params['template-name'] = template_name
- expanded = deep_format(template, params, allow_empty_variables)
+ expanded = deep_format(
+ template, params,
+ self.jjb_config.yamlparser['allow_empty_variables'])
job_name = expanded.get('name')
if jobs_glob and not matches(job_name, jobs_glob):