-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathgenerate-list.py
52 lines (45 loc) · 2.47 KB
/
generate-list.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
import sys
import os
from typing import List
# python genenrate-list.py contest_name
contest = sys.argv[1]
problems: List[str] = [p for p in os.listdir(f"./{contest}")]
# Rename file
for problem in problems:
# input directory
for path, subdirs, fileNames in os.walk(f"./{contest}/{problem}/in"):
for fileName in fileNames:
fileNameWithoutExtension = fileName.split('.')[0]
# sometimes we have 2 files with same prefix but different extension
if not os.path.exists(f"{path}/{fileNameWithoutExtension}"):
os.rename(f"{path}/{fileName}", f"{path}/{fileNameWithoutExtension}")
# output directory
for path, subdirs, fileNames in os.walk(f"./{contest}/{problem}/out"):
for fileName in fileNames:
fileNameWithoutExtension = fileName.split('.')[0]
# sometimes we have 2 files with same prefix but different extension
if not os.path.exists(f"{path}/{fileNameWithoutExtension}"):
os.rename(f"{path}/{fileName}", f"{path}/{fileNameWithoutExtension}")
# Generate list.txt file
for problem in problems:
# if (os.path.exists(f"./{folder}/{problem}/list.txt")):
# os.remove(f"./{folder}/{problem}/list.txt")
if not os.path.exists(f"./{contest}/{problem}/list.txt"):
for path, subdirs, inFiles in os.walk(f"./{contest}/{problem}/in"):
f = open(f"./{contest}/{problem}/list.txt", "a+")
for inFile in sorted(inFiles):
outFile = inFile
if (inFile.endswith('.in')):
outFile = inFile[:-2] + "out"
# missing output files will raise an error (check abc350.C on dropbox)
# create if not exists
if not os.path.exists(f"./{contest}/{problem}/out/{outFile}"):
with open(f"./{contest}/{problem}/out/{outFile}", 'w') as outf:
outf.write("Sorry, this output file is not provided.")
# file_name,input_file_size_in_bytes,output_file_size_in_bytes
if os.path.exists(f"./{contest}/{problem}/in/{inFile}") and os.path.exists(f"./{contest}/{problem}/out/{outFile}"):
inputSz = os.path.getsize(f"./{contest}/{problem}/in/{inFile}")
outputSz = os.path.getsize(f"./{contest}/{problem}/out/{outFile}")
commonName = inFile.split(".")[0]
f.write(f"{commonName},{inputSz},{outputSz}\n")
f.close()