diff options
author | Wayne Warren <waynr+launchpad@sdf.org> | 2015-12-31 14:59:16 -0800 |
---|---|---|
committer | Darragh Bailey <dbailey@hpe.com> | 2016-07-22 17:33:53 +0100 |
commit | c569dc02d31e4d4bc58430f4dad290f3de96d182 (patch) | |
tree | 60129c526d094ab82f1c41bfdc4b33963642e053 /jenkins_jobs/builder.py | |
parent | 0da11b51c5e586d1b104e91f6917c129777f0555 (diff) | |
download | python-jenkins-job-builder-c569dc02d31e4d4bc58430f4dad290f3de96d182.tar.gz python-jenkins-job-builder-c569dc02d31e4d4bc58430f4dad290f3de96d182.tar.xz python-jenkins-job-builder-c569dc02d31e4d4bc58430f4dad290f3de96d182.zip |
Move load_files method to YamlParser from Builder.
This is the first step in removing jenkins_modules.parser.YamlParser
references from jenkins_jobs.builder.Builder entirely, necessary
because load_files is actually a YamlParser behavior, not a Builder
behavior.
Change-Id: I1cad99b4cdb44af25ba398837f7f328cfcbd5bbb
Diffstat (limited to 'jenkins_jobs/builder.py')
-rw-r--r-- | jenkins_jobs/builder.py | 60 |
1 files changed, 7 insertions, 53 deletions
diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index e263c13e..582a5fd6 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -242,57 +242,6 @@ class Builder(object): self._plugins_list = self.jenkins.get_plugins_info() return self._plugins_list - def load_files(self, fn): - self.parser = YamlParser(self.jjb_config, self.plugins_list) - - # handle deprecated behavior, and check that it's not a file like - # object as these may implement the '__iter__' attribute. - if not hasattr(fn, '__iter__') or hasattr(fn, 'read'): - logger.warning( - 'Passing single elements for the `fn` argument in ' - 'Builder.load_files is deprecated. Please update your code ' - 'to use a list as support for automatic conversion will be ' - 'removed in a future version.') - fn = [fn] - - files_to_process = [] - for path in fn: - if not hasattr(path, 'read') and os.path.isdir(path): - files_to_process.extend([os.path.join(path, f) - for f in os.listdir(path) - if (f.endswith('.yml') - or f.endswith('.yaml'))]) - else: - files_to_process.append(path) - - # symlinks used to allow loading of sub-dirs can result in duplicate - # definitions of macros and templates when loading all from top-level - unique_files = [] - for f in files_to_process: - if hasattr(f, 'read'): - unique_files.append(f) - continue - rpf = os.path.realpath(f) - if rpf not in unique_files: - unique_files.append(rpf) - else: - logger.warning("File '%s' already added as '%s', ignoring " - "reference to avoid duplicating yaml " - "definitions." % (f, rpf)) - - for in_file in unique_files: - # use of ask-for-permissions instead of ask-for-forgiveness - # performs better when low use cases. - if hasattr(in_file, 'name'): - fname = in_file.name - else: - fname = in_file - logger.debug("Parsing YAML file {0}".format(fname)) - if hasattr(in_file, 'read'): - self.parser.parse_fp(in_file) - else: - self.parser.parse(in_file) - def delete_old_managed(self, keep=None): jobs = self.jenkins.get_jobs() deleted_jobs = 0 @@ -313,8 +262,10 @@ class Builder(object): return deleted_jobs def delete_job(self, jobs_glob, fn=None): + self.parser = YamlParser(self.jjb_config, self.plugins_list) + if fn: - self.load_files(fn) + self.parser.load_files(fn) self.parser.expandYaml([jobs_glob]) jobs = [j['name'] for j in self.parser.jobs] else: @@ -348,7 +299,10 @@ class Builder(object): def update_jobs(self, input_fn, jobs_glob=None, output=None, n_workers=None): orig = time.time() - self.load_files(input_fn) + + self.parser = YamlParser(self.jjb_config, self.plugins_list) + self.parser.load_files(input_fn) + self.parser.expandYaml(jobs_glob) self.parser.generateXML() step = time.time() |