-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload.py
67 lines (47 loc) · 2.1 KB
/
upload.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
import os, os.path, glob
class ExistsError(Exception):
pass
def check_and_save_submitids(local_path, submitids_path, problems):
submitids = []
errors = []
for problem in problems:
path_list = glob.glob( local_path[:-1] + f'uloha-{problem}/*')
pdf_list = [path for path in path_list if 'pdf' in path[-4:].lower()]
for pdf in pdf_list:
idpozice = pdf.find("__")+2
submitid = pdf[idpozice:idpozice+5]
try:
submitids.append(int(submitid))
except:
errors.append(pdf)
if len(errors) > 0:
for error in errors:
print(error)
raise ValueError(f"Nonvalid submitid(s) found")
#else
print("All submitids ok")
#pokud uz neexistuje
if os.path.exists(submitids_path):
raise ExistsError(f"{submitids_path} already exists. Move to prevent overwrite.")
with open(submitids_path, "w") as f:
for submitid in submitids:
print(f"{submitid},", file = f, end=" ")
print(f"{len(submitids)} submitids saved at {submitids_path}")
def upload(local_path, remote_path, username, temp_path = "./temp", server_name = "fykos.cz"):
"""odkud kam kdo uploaduje"""
if not os.path.exists(temp_path):
os.makedirs(temp_path)
command = f"scp -r {local_path} {username}@{server_name}:{remote_path}"
os.system(command)
if __name__ == "__main__":
problems = ['1', '2', '3', '4', '5', 'P', 'E', 'S']
rocnik = int(input('napis cislo rocniku: '))
serie = int(input('napis cislo serie: '))
username = input('napis login na server: ')
print()
#do upload dat slozky uloha-U
local_path = os.path.join(os.path.dirname(__file__), "corrected", f"rocnik{rocnik}", f"serie{serie}", "upload_me", "*")
remote_path = f"/data/docker/fksdb/upload/corrected/fykos/rocnik{rocnik}/serie{serie}"
submitids_path = os.path.join(os.path.dirname(__file__), "corrected", f"rocnik{rocnik}", f"serie{serie}", "submitids.txt")
check_and_save_submitids(local_path, submitids_path, problems)
upload(local_path, remote_path, username)