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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
from __future__ import print_function

from argparse import ArgumentParser
import os

from jenkins import Jenkins
from utility import (
    find_candidates,
    get_auth_token,
    get_candidates_path,
    )


def get_args():
    parser = ArgumentParser()
    parser.add_argument(
        'root_dir', help='Directory containing releases and candidates dir')
    return parser.parse_args()


def get_releases(root):
    release_path = os.path.join(root, 'old-juju')
    for entry in os.listdir(release_path):
        if not os.path.isdir(os.path.join(release_path, entry)):
            continue
        yield entry


def calculate_jobs(root):
    releases = list(get_releases(root))
    candidates_path = get_candidates_path(root)
    for candidate_path in find_candidates(root):
        parent, candidate = os.path.split(candidate_path)
        if parent != candidates_path:
            raise ValueError('Wrong path')
        for release in releases:
            if release == candidate:
                continue
            yield {
                'old_version': release,
                'candidate': candidate,
                'new_to_old': 'true'
            }
            yield {
                'old_version': release,
                'candidate': candidate,
                'new_to_old': 'false'
            }


def build_jobs(root, jobs):
    jenkins = Jenkins('http://localhost:8080')
    token = get_auth_token(root, 'compatibility-control')
    for job in jobs:
        jenkins.build_job('compatibility-control', job, token=token)


def main():
    args = get_args()
    build_jobs(args.root_dir, calculate_jobs(args.root_dir))


if __name__ == '__main__':
    main()