-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathoo_repo_tool
executable file
·73 lines (63 loc) · 2.52 KB
/
oo_repo_tool
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
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
import os
import github # Install pygithub
import git # Install gitpython
from argparse import ArgumentParser
import subprocess
import sys
parser = ArgumentParser(
description="""Helper script to mark finite element assignments.""")
parser.add_argument(
"--update", action="store_true", help="Update all student repositories.")
parser.add_argument(
"--push-masters", action="store_true",
help="Push the master branch of all student repos to the instructor repo.")
parser.add_argument("--checkout", type=str, action="store", metavar=("REPO"),
help="checkout finite-element/fe-%d-REPO." % 0)
parser.add_argument("--test", action="store_true", help="Execute tests")
parser.add_argument("-x", action="store_true", help="Stop on first test fail")
parser.add_argument("--week", type=str, action="store", required=True,
help="Week whose repositories should be cloned.")
args = parser.parse_args()
repo = git.Repo(".")
if args.update:
g = github.Github(os.environ["GITHUB_OAUTH"])
org = g.get_organization("Imperial-MATH50009")
count = 0
for r in org.get_repos():
if r.name.startswith("exercises-week-%s" % args.week):
count += 1
uname = r.name[10:]
print("Looking for remote %s" % uname)
try:
remote = repo.remote(uname)
print("Found")
except ValueError:
print("Not found. Creating")
remote = repo.create_remote(uname, r.ssh_url)
print("Fetching")
remote.fetch()
print(f"{count} repos found.")
if args.push_masters:
g = github.Github(os.environ["GITHUB_OAUTH"])
org = g.get_organization("finite-element")
remote = repo.remote(instructor)
for r in org.get_repos():
if r.name.startswith("fe-%d" % year):
uname = r.name[8:]
print("Pushing master for remote %s" % uname)
remote.push("remotes/{0}/master:refs/heads/{0}-master".format(uname))
if args.checkout:
user = args.checkout
print("Checking out head for %s" % user)
head = repo.create_head(user, commit="/%s/implementation" % user)
repo.head.reference = head
repo.head.reset(working_tree=True)
print("success")
if args.test:
os.environ["PYTHONPATH"] = repo.working_tree_dir
test_args = ["-x"] if args.x else []
try:
subprocess.check_output(["py.test"] + test_args)
except subprocess.CalledProcessError as e:
sys.stdout.write(e.output.decode("utf8"))