diff --git a/scripts/prepare-shared-repos b/scripts/prepare-shared-repos index 02c18db..4f7b6d2 100755 --- a/scripts/prepare-shared-repos +++ b/scripts/prepare-shared-repos @@ -26,20 +26,7 @@ ourconfig = utils.loadconfig(__file__) with open(repojson) as f: repos = json.load(f) -stash = ourconfig["REPO_STASH_DIR"] +stashdir = 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) - + utils.fetchgitrepo(shared, repo, repos[repo], stashdir) diff --git a/scripts/shared-repo-unpack b/scripts/shared-repo-unpack index 2528193..b75f163 100755 --- a/scripts/shared-repo-unpack +++ b/scripts/shared-repo-unpack @@ -5,6 +5,7 @@ # 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 # import json @@ -28,8 +29,9 @@ ourconfig = utils.loadconfig(__file__) with open(repojson) as f: repos = json.load(f) -if shared: - "cp shared targetdir" -else: - "prepare-shared-repos repojson targetdir" - +# FIXME: Need to filter repo list to the list of repos we need from ourconfig +for repo in sorted(repos.keys()): + if shared: + subprocess.check_call(["rsync", "-a", "%s/%s" % (shared, repo), "%s/%s" % (targetdir, repo)]) + else: + utils.fetchgitrepo(targetdir, repo, repos[repo], stashdir) diff --git a/scripts/utils.py b/scripts/utils.py index e7e3807..660beed 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -85,6 +85,22 @@ def loadconfig(f): def runcmd(cmd): return subprocess.check_output(cmd, stderr=subprocess.STDOUT) + +def fetchgitrepo(clonedir, repo, params, stashdir): + sharedrepo = "%s/%s" % (clonedir, repo) + branch = params["branch"] + revision = params["revision"] + if os.path.exists(stash + "/" + repo): + subprocess.check_call(["git", "clone", "file://%s/%s" % (stashdir, repo), "%s/%s" % (clonedir, repo)]) + subprocess.check_call(["git", "remote", "rm", "origin"], cwd=sharedrepo) + subprocess.check_call(["git", "remote", "add", "origin", params["url"]], cwd=sharedrepo) + subprocess.check_call(["git", "fetch", "origin", "-t"], cwd=sharedrepo) + else: + subprocess.check_call(["git", "clone", params["url"], sharedrepo]) + + subprocess.check_call(["git", "checkout", branch], cwd=sharedrepo) + subprocess.check_call(["git", "reset", revision, "--hard"], cwd=sharedrepo) + def printheader(msg): print("") print("====================================================================================================")