-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_handin.py
More file actions
35 lines (27 loc) · 1.02 KB
/
create_handin.py
File metadata and controls
35 lines (27 loc) · 1.02 KB
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
from pathlib import Path
from shutil import rmtree, copy, make_archive
import re
project_dir = Path(__file__).parent
handin_dir = project_dir.joinpath('handin')
code_dir_str = 'src'
def should_include(relative_path: Path):
relative_str = str(relative_path.as_posix())
if not re.fullmatch(r'.*\.py', relative_str):
return False
if not re.fullmatch(f'{code_dir_str}/.*', relative_str):
return False
if re.fullmatch(f'{code_dir_str}/solution/.*', relative_str):
return False
return True
def create_handin():
rmtree(str(handin_dir), ignore_errors=True)
handin_dir.mkdir()
for file in (f for f in project_dir.rglob('*') if f.is_file()):
rel2project = file.relative_to(project_dir)
if should_include(rel2project):
newpath = handin_dir.joinpath(rel2project)
newpath.parent.mkdir(parents=True, exist_ok=True)
copy(str(file), str(newpath))
make_archive(handin_dir, 'zip', handin_dir)
if __name__ == '__main__':
create_handin()