~ubuntu-branches/ubuntu/utopic/jenkins-job-builder/utopic

« back to all changes in this revision

Viewing changes to jenkins_jobs/cmd.py

  • Committer: Package Import Robot
  • Author(s): Paul Belanger
  • Date: 2013-07-28 10:32:09 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130728103209-6q9hrv6oljkp0qng
Tags: 0.5.0-1
* New upstream release (Closes: #718126)
* debian/patches: Merged upstream
  - 0001-Documentation-fixes-to-make-Sphinx-happy.patch
  - 0002-Remove-setuptools-git-from-setup.py.patch
* debian/patches: Add upstream fixes for packaging
  - 0001-Fixing-documentation.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
 
2
# Copyright (C) 2012 OpenStack Foundation
 
3
#
 
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
 
7
#
 
8
# http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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
 
14
# under the License.
2
15
 
3
 
import jenkins_jobs.builder
4
16
import argparse
5
17
import ConfigParser
6
18
import logging
15
27
 
16
28
 
17
29
def main():
 
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',
20
34
                                      dest='command')
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):
53
67
            conf = localconf
54
68
 
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)
60
 
    else:
 
74
    elif options.command == 'test':
 
75
        logger.debug("Not reading config for test output generation")
61
76
        config = {}
 
77
    else:
 
78
        raise jenkins_jobs.errors.JenkinsJobsException(
 
79
            "A valid configuration file is required when not run as a test")
 
80
 
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)
84
103
 
85
104
if __name__ == '__main__':
 
105
    sys.path.insert(0, '.')
86
106
    main()