aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/shared-repo-unpack
blob: 209aa83658f6ba281e88d79cf899bf5aa875ac79 (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
#!/usr/bin/env python3
#
# Unpack a shared directory of repos to the autobuilder working directory
#
# Called with $1 - The json file containing the repositories to use
#             $2 - The shared directory where the repos are to be transferred from (can be 'None')
#             $3 - The autobuilder working directory
#             $4 - The target to filter the repos to
#             $5 - Directory to publish artefacts to
#

import json
import os
import sys
import subprocess
import errno
import time
import random

import utils

if len(sys.argv) != 6:
    print("Incorrect number of parameters, please call as %s repo.json <shared-sources-dir> <autobuilder-workdir> <target> <publish-dir>" % sys.argv[0])
    sys.exit(1)

repojson = sys.argv[1]
shared = sys.argv[2]
targetdir = sys.argv[3]
target = sys.argv[4]
publish = None
if sys.argv[5] != "None":
    publish = sys.argv[5]


scriptsdir = os.path.dirname(os.path.realpath(__file__))
ourconfig = utils.loadconfig()

stashdir = utils.getconfig("REPO_STASH_DIR", ourconfig)

needrepos = utils.getconfigvar("NEEDREPOS", ourconfig, target, None)

with open(repojson) as f:
    repos = json.load(f)

targetsubdir = targetdir + "/repos"

for repo in sorted(repos.keys()):
    if repo not in needrepos:
        continue
    targetrepodir = "%s/%s" % (targetsubdir, repo)
    if shared != "None":
        utils.printheader("Copying in repo %s" % repo)
        utils.mkdir(targetrepodir)
        subprocess.check_call(["rsync", "-a", "%s/%s" % (shared, repo), targetsubdir])
    else:
        utils.printheader("Fetching repo %s" % repo)
        utils.fetchgitrepo(targetsubdir, repo, repos[repo], stashdir)
        if publish:
            utils.publishrepo(shared, repo, publish)

subprocess.check_call([scriptsdir + "/layer-config", targetdir, target])