From 6bf85dbbdc33562f9c4eae324ea630deed1f2458 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Mon, 22 Jan 2018 15:20:37 +0000 Subject: [PATCH] Add initial repo handling scripts Signed-off-by: Richard Purdie --- scripts/prepare-shared-repos | 45 ++++++++++++++++++++++++++++++++++++ scripts/shared-repo-unpack | 35 ++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100755 scripts/prepare-shared-repos create mode 100755 scripts/shared-repo-unpack diff --git a/scripts/prepare-shared-repos b/scripts/prepare-shared-repos new file mode 100755 index 0000000..02c18db --- /dev/null +++ b/scripts/prepare-shared-repos @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# +# Iterate over a set of repositories in a json file and setup a shared directory containing them +# +# Called with $1 - The json file containing the repositories to use +# $2 - The shared directory where the repos are to be transferred +# + +import json +import os +import sys +import subprocess +import errno + +import utils + +if len(sys.argv) != 3: + print("Incorrect number of parameters, please call as %s repo.json") + sys.exit(1) + +repojson = sys.argv[1] +shared = sys.argv[2] + +ourconfig = utils.loadconfig(__file__) + +with open(repojson) as f: + repos = json.load(f) + +stash = ourconfig["REPO_STASH_DIR"] + +for repo in sorted(repos.keys()): + sharedrepo = "%s/%s" % (shared, repo) + branch = repos[repo][1] + revision = repos[repo][2] + if os.path.exists(stash + "/" + repo): + subprocess.check_call(["git", "clone", "file://%s/%s" % (stash, repo), "%s/%s" % (shared, repo)]) + subprocess.check_call(["git", "remote", "rm", "origin"], cwd=sharedrepo) + subprocess.check_call(["git", "remote", "add", "origin", repos[repo][0]], cwd=sharedrepo) + subprocess.check_call(["git", "fetch", "origin", "-t"], cwd=sharedrepo) + else: + subprocess.check_call(["git", "clone", repos[repo][0], sharedrepo]) + + subprocess.check_call(["git", "checkout", branch], cwd=sharedrepo) + subprocess.check_call(["git", "reset", revision, "--hard"], cwd=sharedrepo) + diff --git a/scripts/shared-repo-unpack b/scripts/shared-repo-unpack new file mode 100755 index 0000000..2528193 --- /dev/null +++ b/scripts/shared-repo-unpack @@ -0,0 +1,35 @@ +#!/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 +# + +import json +import os +import sys +import subprocess +import errno + +import utils + +if len(sys.argv) != 4: + print("Incorrect number of parameters, please call as %s repo.json") + sys.exit(1) + +repojson = sys.argv[1] +shared = sys.argv[2] +targetdir = sys.argv[3] + +ourconfig = utils.loadconfig(__file__) + +with open(repojson) as f: + repos = json.load(f) + +if shared: + "cp shared targetdir" +else: + "prepare-shared-repos repojson targetdir" +