1
1
#!/usr/bin/env python
2
# Copyright (C) 2012 OpenStack Foundation
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
3
import jenkins_jobs.builder
30
import jenkins_jobs.builder
31
import jenkins_jobs.errors
18
32
parser = argparse.ArgumentParser()
19
33
subparser = parser.add_subparsers(help='update, test or delete job',
21
35
parser_update = subparser.add_parser('update')
22
36
parser_update.add_argument('path', help='Path to YAML file or directory')
23
parser_update.add_argument('name', help='name of job', nargs='?')
37
parser_update.add_argument('names', help='name(s) of job(s)', nargs='*')
24
38
parser_test = subparser.add_parser('test')
25
39
parser_test.add_argument('path', help='Path to YAML file or directory')
26
40
parser_test.add_argument('-o', dest='output_dir',
27
41
help='Path to output XML')
28
parser_test.add_argument('name', help='name of job', nargs='?')
42
parser_test.add_argument('name', help='name(s) of job(s)', nargs='*')
29
43
parser_delete = subparser.add_parser('delete')
30
44
parser_delete.add_argument('name', help='name of job', nargs='+')
31
45
subparser.add_parser('delete-all',
52
66
if os.path.isfile(localconf):
55
if not options.command == 'test':
69
if os.path.isfile(conf):
56
70
logger.debug("Reading config from {0}".format(conf))
57
71
conffp = open(conf, 'r')
58
72
config = ConfigParser.ConfigParser()
59
73
config.readfp(conffp)
74
elif options.command == 'test':
75
logger.debug("Not reading config for test output generation")
78
raise jenkins_jobs.errors.JenkinsJobsException(
79
"A valid configuration file is required when not run as a test")
62
81
logger.debug("Config: {0}".format(config))
63
82
builder = jenkins_jobs.builder.Builder(config.get('jenkins', 'url'),
64
83
config.get('jenkins', 'user'),
76
95
builder.delete_all_jobs()
77
96
elif options.command == 'update':
78
97
logger.info("Updating jobs in {0} ({1})".format(
79
options.path, options.name))
80
builder.update_job(options.path, options.name)
98
options.path, options.names))
99
builder.update_job(options.path, options.names)
81
100
elif options.command == 'test':
82
101
builder.update_job(options.path, options.name,
83
102
output_dir=options.output_dir)
85
104
if __name__ == '__main__':
105
sys.path.insert(0, '.')