~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to build_juju.py

  • Committer: Aaron Bentley
  • Date: 2014-02-24 17:18:29 UTC
  • mto: This revision was merged to the branch mainline in revision 252.
  • Revision ID: aaron.bentley@canonical.com-20140224171829-sz644yhoygu7m9dm
Use tags to identify and shut down instances.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
"""Build and package juju for an non-debian OS."""
3
 
 
4
 
from __future__ import print_function
5
 
 
6
 
from argparse import ArgumentParser
7
 
import os
8
 
import sys
9
 
import traceback
10
 
 
11
 
from candidate import run_command
12
 
from jujuci import (
13
 
    add_artifacts,
14
 
    add_credential_args,
15
 
    get_artifacts,
16
 
    get_credentials,
17
 
    BUILD_REVISION,
18
 
    setup_workspace,
19
 
)
20
 
 
21
 
 
22
 
DEFAULT_JUJU_RELEASE_TOOLS = os.path.realpath(
23
 
    os.path.join(__file__, '..', '..', 'juju-release-tools'))
24
 
 
25
 
 
26
 
def get_script(juju_release_tools=None):
27
 
    """Return the full path to the crossbuild script.
28
 
 
29
 
    The juju-release-tools dir is assumed to be a sibling of the juju-ci-tools
30
 
    directory.
31
 
    """
32
 
    if not juju_release_tools:
33
 
        juju_release_tools = DEFAULT_JUJU_RELEASE_TOOLS
34
 
    script = os.path.join(juju_release_tools, 'crossbuild.py')
35
 
    return script
36
 
 
37
 
 
38
 
def build_juju(credentials, product, workspace_dir, build,
39
 
               juju_release_tools=None, dry_run=False, verbose=False):
40
 
    """Build the juju product from a Juju CI build-revision in a workspace.
41
 
 
42
 
    The product is passed to juju-release-tools/crossbuild.py. The options
43
 
    include osx-client, win-client, win-agent.
44
 
 
45
 
    The tarfile from the build-revision build number is downloaded and passed
46
 
    to crossbuild.py.
47
 
    """
48
 
    setup_workspace(workspace_dir, dry_run=dry_run, verbose=verbose)
49
 
    artifacts = get_artifacts(
50
 
        credentials, BUILD_REVISION, build, 'juju-core_*.tar.gz',
51
 
        workspace_dir, archive=False, dry_run=dry_run, verbose=verbose)
52
 
    tar_artifact = artifacts[0]
53
 
    crossbuild = get_script(juju_release_tools)
54
 
    command = [
55
 
        crossbuild, product, '-b', '~/crossbuild', tar_artifact.file_name]
56
 
    run_command(command, dry_run=dry_run, verbose=verbose)
57
 
    globs = [
58
 
        'juju-setup-*.exe', 'juju-*-win2012-amd64.tgz', 'juju-*-osx.tar.gz',
59
 
        'juju-*-centos7-amd64.tgz', 'juju-*-centos7.tar.gz']
60
 
    add_artifacts(workspace_dir, globs, dry_run=dry_run, verbose=verbose)
61
 
 
62
 
 
63
 
def parse_args(args=None):
64
 
    """Return the argument parser for this program."""
65
 
    parser = ArgumentParser("Build and package juju for an non-debian OS.")
66
 
    parser.add_argument(
67
 
        '-d', '--dry-run', action='store_true', default=False,
68
 
        help='Do not make changes.')
69
 
    parser.add_argument(
70
 
        '-v', '--verbose', action='store_true', default=False,
71
 
        help='Increase verbosity.')
72
 
    parser.add_argument(
73
 
        '-b', '--build', default='lastSuccessfulBuild',
74
 
        help="The specific revision-build number to get the tarball from")
75
 
    parser.add_argument(
76
 
        '-t', '--juju-release-tools',
77
 
        help='The path to the juju-release-tools dir, default: %s' %
78
 
              DEFAULT_JUJU_RELEASE_TOOLS)
79
 
    parser.add_argument(
80
 
        'product', choices=['win-client', 'win-agent', 'osx-client', 'centos'],
81
 
        help='the kind of juju to make and package.')
82
 
    parser.add_argument(
83
 
        'workspace',  help='The path to the workspace to build in.')
84
 
    add_credential_args(parser)
85
 
    parsed = parser.parse_args(args)
86
 
    return parsed, get_credentials(parsed)
87
 
 
88
 
 
89
 
def main(argv):
90
 
    """Build and package juju for an non-debian OS."""
91
 
    args, credentials = parse_args(argv)
92
 
    try:
93
 
        build_juju(
94
 
            credentials, args.product, args.workspace, args.build,
95
 
            juju_release_tools=args.juju_release_tools,
96
 
            dry_run=args.dry_run, verbose=args.verbose)
97
 
    except Exception as e:
98
 
        print(e)
99
 
        print(getattr(e, 'output', ''))
100
 
        if args.verbose:
101
 
            traceback.print_tb(sys.exc_info()[2])
102
 
        return 2
103
 
    if args.verbose:
104
 
        print("Done.")
105
 
    return 0
106
 
 
107
 
 
108
 
if __name__ == '__main__':
109
 
    sys.exit(main(sys.argv[1:]))