Add initial repo handling scripts

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2018-01-22 15:20:37 +00:00
parent 45b14f6c80
commit 6bf85dbbdc
2 changed files with 80 additions and 0 deletions

45
scripts/prepare-shared-repos Executable file
View File

@ -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)

35
scripts/shared-repo-unpack Executable file
View File

@ -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"