aboutsummaryrefslogtreecommitdiff
path: root/utils/new-publish/publish
blob: b18e35168e103e7ebb2935e73fa4cb3c56c24b1b (plain)
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
66
67
68
69
70
71
#!/usr/bin/env python
import sys
import os
import glob
import optparse

import publib


REMOTE_HOST = "android-build.linaro.org"
COPY_USER_NAME = "publish-copy"
TRIGGER_USER_NAME = "publish-trigger"
UPLOAD_DIR = "/uploads"
COPY_KEY_FILE = "/var/run/lava/publish-copy"
TRIGGER_KEY_FILE = "/var/run/lava/publish-trigger"

def log(msg):
    print msg
    sys.stdout.flush()

if __name__ == "__main__":
    optparser = optparse.OptionParser(usage="%prog <job/build> <pattern>...")
    optparser.add_option("-t", "--type", help="Build type")
    optparser.add_option("-p", "--strip", metavar="NUM", type=int, default=0,
                         help="Strip leading components from dest file names.")
    optparser.add_option("-s", "--staging", action="store_true", help="Publish to staging")
    optparser.add_option("--identity-copy", metavar="KEY", default=COPY_KEY_FILE, help="SSH key file")
    optparser.add_option("--identity-trigger", metavar="KEY", default=TRIGGER_KEY_FILE, help="SSH key file")
    optparser.add_option("-n", "--dry-run", action="store_true", help="Don't actually publish files, log commands")
    optparser.add_option("--host", help="Override destination publishing host, for debugging")
    options, args = optparser.parse_args(sys.argv[1:])
    if len(args) < 2:
        optparser.error("Wrong number of arguments")

    build_id = args[0]
    patterns = args[1:]

    publib.validate_build_id(build_id)

    # Support Jenkins syntax, with comma as separator
    if len(patterns) == 1 and "," in patterns[0]:
        patterns = patterns[0].split(",")

    for p in patterns:
        if "**" in p:
            print "** in glob patterns is not supported"
            sys.exit(1)

    file_list = publib.get_file_list(patterns)
    print "File list:", file_list
    dir_list = publib.make_dir_struct(file_list, UPLOAD_DIR, build_id, options.strip)
    print "Dir list:", dir_list
    log("Creating dir structure on intermediate server")
    publib.create_dir_struct(dir_list, REMOTE_HOST, COPY_USER_NAME, options.identity_copy)
    log("Done creating dir structure on intermediate server")
    upload_script = publib.make_upload_script(file_list, UPLOAD_DIR, build_id, options.strip)
    log("Uploading files to intermediate server")
    publib.upload_files(upload_script, REMOTE_HOST, COPY_USER_NAME, options.identity_copy, options)
    log("Done uploading files to intermediate server")

    log("Triggering propagation of files to downloads server")
    rc = os.system("ssh -i %s %s@%s propagate.py %s %s %s" % (options.identity_trigger,
        TRIGGER_USER_NAME, REMOTE_HOST,
        "-s" if options.staging else "",
        "--host=%s" % options.host if options.host else "",
        build_id))
    if rc != 0:
        log("Publishing failed")
        sys.exit(1)

    log("Publishing successful")