~ubuntu-branches/ubuntu/trusty/python-jenkinsapi/trusty-proposed

« back to all changes in this revision

Viewing changes to jenkinsapi/command_line/jenkins_invoke.py

  • Committer: Package Import Robot
  • Author(s): Al Stone
  • Date: 2014-01-06 18:12:26 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140106181226-j4n5l4idgxghlvwg
Tags: 0.2.16-1
* Update to latest upstream.
* Closes: #725589 -- FTBS due to unexpected upstream changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
jenkinsapi class for invoking Jenkins
 
3
"""
 
4
 
1
5
import os
2
6
import sys
3
7
import logging
6
10
 
7
11
log = logging.getLogger(__name__)
8
12
 
9
 
class jenkins_invoke(object):
 
13
 
 
14
class JenkinsInvoke(object):
 
15
    """
 
16
    JenkinsInvoke object implements class to call from command line
 
17
    """
 
18
 
10
19
    @classmethod
11
20
    def mkparser(cls):
12
21
        parser = optparse.OptionParser()
13
 
        DEFAULT_BASEURL=os.environ.get( "JENKINS_URL", "http://localhost/jenkins" )
14
 
        parser.help_text = "Execute a number of jenkins jobs on the server of your choice. Optionally block until the jobs are complete."
 
22
        DEFAULT_BASEURL = os.environ.get("JENKINS_URL", "http://localhost/jenkins")
 
23
        parser.help_text = "Execute a number of jenkins jobs on the server of your choice." + \
 
24
            " Optionally block until the jobs are complete."
15
25
        parser.add_option("-J", "--jenkinsbase", dest="baseurl",
16
26
                          help="Base URL for the Jenkins server, default is %s" % DEFAULT_BASEURL,
17
27
                          type="str", default=DEFAULT_BASEURL)
18
28
        parser.add_option('--username', '-u', dest='username',
19
 
                        help="Username for jenkins authentification", type='str', default=None)
 
29
                          help="Username for jenkins authentification", type='str', default=None)
20
30
        parser.add_option('--password', '-p', dest='password',
21
 
                        help="password for jenkins user auth", type='str', default=None)
 
31
                          help="password for jenkins user auth", type='str', default=None)
22
32
        parser.add_option("-b", "--block", dest="block", action="store_true", default=False,
23
33
                          help="Block until each of the jobs is complete.")
24
 
        parser.add_option("-t", "--token", dest="token",help="Optional security token.",
 
34
        parser.add_option("-t", "--token", dest="token", help="Optional security token.",
25
35
                          default=None)
26
36
        return parser
27
37
 
31
41
        options, args = parser.parse_args()
32
42
        try:
33
43
            assert len(args) > 0, "Need to specify at least one job name"
34
 
        except AssertionError, e:
35
 
            log.critical(e[0])
 
44
        except AssertionError as err:
 
45
            log.critical(err[0])
36
46
            parser.print_help()
37
47
            sys.exit(1)
38
48
        invoker = cls(options, args)
58
68
        job.invoke(securitytoken=token, block=block)
59
69
 
60
70
 
61
 
def main(  ):
 
71
def main():
62
72
    logging.basicConfig()
63
73
    logging.getLogger("").setLevel(logging.INFO)
64
 
    jenkins_invoke.main()
 
 
b'\\ No newline at end of file'
 
74
    JenkinsInvoke.main()