Merge "Modularize to enable easier testing"

This commit is contained in:
Jenkins 2014-05-05 23:09:29 +00:00 committed by Gerrit Code Review
commit c79955426e
1 changed files with 13 additions and 9 deletions

View File

@ -21,6 +21,8 @@ import platform
import sys import sys
import cStringIO import cStringIO
from jenkins_jobs.builder import Builder
from jenkins_jobs.errors import JenkinsJobsException
DEFAULT_CONF = """ DEFAULT_CONF = """
[job_builder] [job_builder]
@ -47,8 +49,6 @@ def main(argv=None):
if argv is None: if argv is None:
argv = sys.argv[1:] argv = sys.argv[1:]
import jenkins_jobs.builder
import jenkins_jobs.errors
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
subparser = parser.add_subparsers(help='update, test or delete job', subparser = parser.add_subparsers(help='update, test or delete job',
dest='command') dest='command')
@ -109,10 +109,14 @@ def main(argv=None):
conffp = open(conf, 'r') conffp = open(conf, 'r')
config.readfp(conffp) config.readfp(conffp)
else: else:
raise jenkins_jobs.errors.JenkinsJobsException( raise JenkinsJobsException(
"A valid configuration file is required when not run as a test" "A valid configuration file is required when not run as a test"
"\n{0} is not a valid .ini file".format(conf)) "\n{0} is not a valid .ini file".format(conf))
execute(options, config, logger)
def execute(options, config, logger):
logger.debug("Config: {0}".format(config)) logger.debug("Config: {0}".format(config))
# check the ignore_cache setting: first from command line, # check the ignore_cache setting: first from command line,
@ -139,12 +143,12 @@ def main(argv=None):
except (TypeError, ConfigParser.NoOptionError): except (TypeError, ConfigParser.NoOptionError):
password = None password = None
builder = jenkins_jobs.builder.Builder(config.get('jenkins', 'url'), builder = Builder(config.get('jenkins', 'url'),
user, user,
password, password,
config, config,
ignore_cache=ignore_cache, ignore_cache=ignore_cache,
flush_cache=options.flush_cache) flush_cache=options.flush_cache)
if hasattr(options, 'path') and options.path == sys.stdin: if hasattr(options, 'path') and options.path == sys.stdin:
logger.debug("Input file is stdin") logger.debug("Input file is stdin")