Adding logger (updated following suggestions from jeblair)
Change-Id: I8a48cb9dc2c6ea136ce072482467bee292a425f3 Reviewed-on: https://review.openstack.org/12788 Reviewed-by: Monty Taylor <mordred@inaugust.com> Approved: James E. Blair <corvus@inaugust.com> Reviewed-by: James E. Blair <corvus@inaugust.com> Tested-by: Jenkins
This commit is contained in:
parent
0a00226c0d
commit
26c6287538
14
jenkins-jobs
14
jenkins-jobs
@ -3,6 +3,7 @@
|
||||
import jenkins_jobs.builder
|
||||
import argparse
|
||||
import ConfigParser
|
||||
import logging
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
@ -18,27 +19,38 @@ def main():
|
||||
parser_delete = subparser.add_parser('delete')
|
||||
parser_delete.add_argument('name', help='name of job')
|
||||
parser.add_argument('--conf', dest='conf', help='Configuration file')
|
||||
parser.add_argument('-l', '--log_level', dest='log_level', default='info',
|
||||
help="Log level (default '%default')")
|
||||
options = parser.parse_args()
|
||||
|
||||
options.log_level = getattr(logging, options.log_level.upper(),
|
||||
logging.INFO)
|
||||
logging.basicConfig(level=options.log_level)
|
||||
logger = logging.getLogger()
|
||||
|
||||
if options.conf:
|
||||
conf = options.conf
|
||||
else:
|
||||
conf = '/etc/jenkins_jobs/jenkins_jobs.ini'
|
||||
|
||||
if not options.command == 'test':
|
||||
logger.debug("Reading config from {0}".format(conf))
|
||||
conffp = open(conf, 'r')
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.readfp(conffp)
|
||||
else:
|
||||
config = {}
|
||||
|
||||
logger.debug("Config: {0}".format(config))
|
||||
builder = jenkins_jobs.builder.Builder(config.get('jenkins','url'),
|
||||
config.get('jenkins','user'),
|
||||
config.get('jenkins','password'))
|
||||
|
||||
if options.command == 'delete':
|
||||
logger.info("Deleting job {0}".format(options.name))
|
||||
builder.delete_job(options.name)
|
||||
elif options.command == 'update':
|
||||
logger.info("Updating jobs in {0} ({1})".format(options.path,
|
||||
options.name))
|
||||
builder.update_job(options.path, options.name)
|
||||
elif options.command == 'test':
|
||||
builder.update_job(options.path, options.name,
|
||||
|
@ -23,7 +23,9 @@ from xml.dom import minidom
|
||||
import jenkins
|
||||
import re
|
||||
import pkg_resources
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class YamlParser(object):
|
||||
def __init__(self):
|
||||
@ -73,9 +75,11 @@ class YamlParser(object):
|
||||
changed = True
|
||||
|
||||
for job in self.data.get('job', {}).values():
|
||||
logger.debug("XMLifying job '{0}'".format(job['name']))
|
||||
job = self.applyDefaults(job)
|
||||
self.getXMLForJob(job)
|
||||
for project in self.data.get('project', {}).values():
|
||||
logger.debug("XMLifying project '{0}'".format(project['name']))
|
||||
for jobname in project.get('jobs', []):
|
||||
job = self.getJob(jobname)
|
||||
if job:
|
||||
@ -218,8 +222,10 @@ class Jenkins(object):
|
||||
|
||||
def update_job(self, job_name, xml):
|
||||
if self.is_job(job_name):
|
||||
logger.info("Reconfiguring jenkins job {0}".format(job_name))
|
||||
self.jenkins.reconfig_job(job_name, xml)
|
||||
else:
|
||||
logger.info("Creating jenkins job {0}".format(job_name))
|
||||
self.jenkins.create_job(job_name, xml)
|
||||
|
||||
def is_job(self, job_name):
|
||||
@ -251,6 +257,7 @@ class Builder(object):
|
||||
files_to_process = [fn]
|
||||
parser = YamlParser()
|
||||
for in_file in files_to_process:
|
||||
logger.debug("Parsing YAML file {0}".format(in_file))
|
||||
parser.parse(in_file)
|
||||
parser.generateXML()
|
||||
|
||||
@ -263,6 +270,7 @@ class Builder(object):
|
||||
print job.output()
|
||||
continue
|
||||
fn = os.path.join(output_dir, job.name)
|
||||
logger.debug("Writing XML to '{0}'".format(fn))
|
||||
f = open(fn, 'w')
|
||||
f.write(job.output())
|
||||
f.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user