~nskaggs/juju-ci-tools/add-assess-terms

1091.4.1 by James Tunnicliffe
Merged upstream
1
#!/usr/bin/python
2
from argparse import ArgumentParser
3
import os
4
from tempfile import NamedTemporaryFile
5
import yaml
6
7
from utility import run_command
8
9
from schedule_hetero_control import get_candidate_info
10
from utility import (
11
    ensure_dir,
12
    find_candidates,
13
    get_candidates_path,
14
)
15
16
17
def get_revisions(root_dir):
18
    revisions = []
19
    ensure_dir(get_candidates_path(root_dir))
20
    for candidate in find_candidates(root_dir):
21
        _, rev = get_candidate_info(candidate)
22
        revisions.append(rev)
23
    return revisions
24
25
26
def create_workspace_yaml(juju_home, script_path, stream, rev=None):
27
    rev = '-c {}'.format(" ".join(rev)) if rev else ''
28
    yl = {
29
        "install": {
30
            "cloud-city": [os.path.join(juju_home, 'ec2rc')]},
31
        "command": [
32
            "python",
33
            script_path,
34
            "cloud-city", "-r", "-v", rev]
35
    }
36
    yaml.safe_dump(yl, stream)
37
38
39
def parse_args(args=None):
40
    parser = ArgumentParser(
41
        "Run download_juju script on the OS X and Windows machines.")
42
    parser.add_argument('-o', '--osx-host',
43
                        default='jenkins@osx-slave.vapour.ws',
44
                        help="OS X machine's username and hostname.")
45
    parser.add_argument('-w', '--win-host',
46
                        default='Administrator@win-slave.vapour.ws',
47
                        help="Windows' username and hostname.")
48
    parser.add_argument('-j', '--juju-home',
49
                        default=os.environ.get('JUJU_HOME'),
50
                        help="Juju home directory (cloud-city dir).")
51
    parsed_args = parser.parse_args(args)
52
    if parsed_args.juju_home is None:
53
        parser.error(
54
            'Invalid JUJU_HOME value: either set $JUJU_HOME env variable or '
55
            'use --juju-home option to set the value.')
56
57
    return parsed_args
58
59
60
def main(argv=None):
61
    args = parse_args(argv)
62
    juju_home = args.juju_home
63
    win_host = args.win_host
1370.1.7 by Aaron Bentley
Fix windows path to four slashes, to match previous value.
64
    win_path = (
65
        'C:\\\\Users\\\\Administrator\\\\juju-ci-tools\\\\download_juju.py')
1091.4.1 by James Tunnicliffe
Merged upstream
66
    osx_path = '$HOME/juju-ci-tools/download_juju.py'
67
    osx_host = args.osx_host
68
    rev = get_revisions(os.environ['HOME'])
69
    with NamedTemporaryFile() as temp_file:
70
        for path, host in [[win_path, win_host], [osx_path, osx_host]]:
71
            create_workspace_yaml(juju_home, path, temp_file, rev)
72
            run_command(['workspace-run', temp_file.name, host])
73
74
75
if __name__ == '__main__':
76
    main()