-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraderInfoGenerator.py
48 lines (44 loc) · 1.57 KB
/
GraderInfoGenerator.py
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
import os
import json
import re
from collections import defaultdict
from pathlib import Path
exclude = ['grader-info.json']
source_sets = [
{'dir': 'src/main/java', 'set': 'solution'},
{'dir': 'src/test/java', 'set': 'solution'},
{'dir': 'src/grader/java', 'set': 'grader'},
{'dir': 'src/main/resources', 'set': 'solution'},
{'dir': 'src/test/resources', 'set': 'solution'},
{'dir': 'src/grader/resources', 'set': 'grader'}
]
def main():
info_json = None
sets = defaultdict(lambda: [])
for source_set in source_sets:
d = Path(source_set['dir'])
for root, dirs, files in os.walk(d):
root = Path(root)
for file in files:
if file in exclude:
info_json = d.joinpath(file)
file = root.joinpath(file)
sets[source_set['set']].append(str(file.relative_to(d)))
name = re.search(r'rootProject.name = "(?P<name>.+?)"', open('settings.gradle.kts', 'r').read())['name']
assignment_id = re.search(r'assignmentId\s+=\s+"(?P<id>.+?)"', open('build.gradle.kts', 'r').read())['id']
r = {
"name": name,
"assignmentIds": [assignment_id],
"sourceSets":
[{
"name": k,
"files": v
} for k, v in sets.items()]
}
if info_json is not None:
open(info_json, 'w').write(json.dumps(r))
print(f'Successfully wrote information into file {info_json}.')
else:
print(f'Failed to write information into file: file not found.')
if __name__ == '__main__':
main()