-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdgs-copy.py
executable file
·89 lines (63 loc) · 2.85 KB
/
dgs-copy.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
import os
import argparse
from typing import Tuple
VERSION = "4.0"
DATE = "2024-11-23"
def fire(query):
print(query)
return os.system(query)
def problem_count(seminar: str, volume: int) -> Tuple[str, int]:
sr = seminar
if seminar == 'FKS':
if volume < 38:
(sr, count) = ('FKS-old', 7)
else:
(sr, count) = ('FKS', 8)
elif seminar == 'FX':
count = 6
else:
raise ValueError(f"Unsupported combination {seminar}/{volume}")
return sr, count
COPY_EXTENSIONS = ['jpg', 'svg', 'png', 'kmz', 'py']
def main():
parser = argparse.ArgumentParser(description="Copy a DeGeŠ round to www-archiv")
parser.add_argument('seminar', choices=['FKS', 'KMS', 'KSP', 'UFO', 'PRASK', 'FX', 'Suši'])
parser.add_argument('volume', type=int)
parser.add_argument('part', type=int, choices=[1, 2])
parser.add_argument('round', choices=['1', '2', '3', 'outdoor'])
parser.add_argument('-d', '--dry-run', action='store_true')
args = parser.parse_args()
# SuŠi hack
issue = 100 if args.round == 'outdoor' else int(args.round)
# FKS hack: volumes <= 37 are now marked as "FKS-old"
seminar_remote, count = problem_count(args.seminar, args.volume)
path_fragment_local = f"{args.seminar}/{args.volume:02d}/{args.part}/{issue}"
path_fragment_remote = f"{seminar_remote}/{args.volume}/{args.part}/{issue}"
# delete the temporary directory if present
os.system("rm -rf tasks")
# copy HTML files
for local, remote in (('problem', 'zadania'), ('solution', 'vzoraky')):
for problem in range(1, count + 1):
pfl = f"{path_fragment_local}/{problem:02d}"
fire(f"mkdir -p tasks/{path_fragment_remote}/{remote}/html && "
f"ln -s $(pwd)/output/seminar/{pfl}/{local}.html "
f"tasks/{path_fragment_remote}/{remote}/html/prikl{problem}.html")
# copy pdf files
fire(f"ln -s $(pwd)/output/seminar/{path_fragment_local}/problems.pdf "
f"tasks/{path_fragment_remote}/zadania/zadania.pdf")
fire(f"ln -s $(pwd)/output/seminar/{path_fragment_local}/solutions.pdf "
f"tasks/{path_fragment_remote}/vzoraky/vzoraky.pdf")
# copy pictures
copy_wildcard = ' -o '.join([f"-name '*.{x}'" for x in COPY_EXTENSIONS])
# stupid hack to make it work with trojstenweb
fire(rf"mkdir -p tasks/{path_fragment_remote}/obrazky/ && "
rf"find output/seminar/{path_fragment_local}/ \( {copy_wildcard} \) "
rf"-exec ln -s $(pwd)/'{{}}' tasks/{path_fragment_remote}/obrazky/ \;")
# rsync everything to server
if not args.dry_run:
fire(f"rsync --recursive --compress --verbose --partial --progress --copy-links --chmod=775 "
f"tasks trojstenweb@ksp:/var/www/trojstenweb/")
# delete the temporary structure
fire("rm -rf tasks")
main()