aboutsummaryrefslogtreecommitdiff
path: root/utils/new-publish/propagate.py
blob: d9b43981ee027ade68bdec8cfa19e47e56049ebb (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
#!/usr/bin/env python
"""This script propagates build artifacts from build master host
to actual publishing location (snapshots)."""
import sys
import os
import optparse

import publish


REMOTE_HOST = "android-build.linaro.org"
PUBLISH_USER_NAME = "linaro-android-build-publish"
TRIGGER_USER_NAME = "linaro-android-build-publish-trigger"
PUBLISH_KEY_FILE = "/home/ubuntu/snapshots-sync2/linaro-android-build-publish"
TRIGGER_KEY_FILE = "/home/ubuntu/snapshots-sync2/linaro-android-build-publish-trigger"
LOCAL_UPLOAD_DIR = "/mnt/publish/uploads"
REMOTE_UPLOAD_DIR = "/uploads"


if __name__ == "__main__":
    optparser = optparse.OptionParser(usage="%prog")
    optparser.add_option("--identity-publish", metavar="KEY", default=PUBLISH_KEY_FILE, help="Publish SSH key file")
    optparser.add_option("--identity-trigger", metavar="KEY", default=TRIGGER_KEY_FILE, help="Trigger 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) != 1:
        optparser.error("Wrong number of arguments")

    file_list = []
    for root, dirs, files in os.walk(os.path.join(LOCAL_UPLOAD_DIR, args[0])):
        file_list.extend([os.path.join(root, f) for f in files])
    print file_list
    strip = len(LOCAL_UPLOAD_DIR.strip("/").split("/"))
    dir_list = publish.make_dir_struct(file_list, strip=strip)
    print dir_list
    if not options.dry_run:
        publish.create_dir_struct(dir_list, REMOTE_HOST, PUBLISH_USER_NAME,
                                  options.identity_publish)
    upload_script = publish.make_upload_script(file_list, strip=strip)
    publish.upload_files(upload_script, REMOTE_HOST, PUBLISH_USER_NAME,
                         options.identity_publish, options)