aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/shared-repo-unpack
blob: fb88bf2ea4ad940b165f04775f0103f1eca4faef (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
#!/usr/bin/env python3
#
# Unpack a shared directory of repos to the autobuilder working directory
#

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

import utils


parser = utils.ArgParser(description='Unpacks a shared directory of repos to the autobuilder working directory.')

parser.add_argument('repojson',
                    help="The json file containing the repositories to use")
parser.add_argument('abworkdir',
                    help="The autobuilder working directory")
parser.add_argument('target',
                    help="The target to filter the repos to")
parser.add_argument('-p', '--publish-dir',
                    action='store',
                    help="Where to publish artefacts to (optional)")
parser.add_argument('-t', '--transfer-to',
                    action='store',
                    help="The shared directory where the repos are to be transferred")

args = parser.parse_args()

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

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

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

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

targetsubdir = args.abworkdir + "/repos"

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

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