aboutsummaryrefslogtreecommitdiff
path: root/utils/new-publish/publish
blob: aa2dfcfa2eda7b629a1923f65ce876e97c4b2248 (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
#!/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"

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("--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")
    options, args = optparser.parse_args(sys.argv[1:])
    if len(args) < 2:
        optparser.error("Wrong number of arguments")
    if options.dest_dir is None:
        optparser.error("--dest-dir is required option")

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

    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
    publib.create_dir_struct(dir_list, REMOTE_HOST, COPY_USER_NAME, options.identity_copy)
    upload_script = publib.make_upload_script(file_list, UPLOAD_DIR, build_id, options.strip)
    publib.upload_files(upload_script, REMOTE_HOST, COPY_USER_NAME, options.identity_copy, options)

    rc = os.system("ssh -i %s %s@%s propagate.py %s" % (options.identity_trigger, TRIGGER_USER_NAME, REMOTE_HOST, build_id))
    if rc != 0:
        print "Publishing failed"
        sys.exit(1)