-
Notifications
You must be signed in to change notification settings - Fork 0
/
_run.py
79 lines (60 loc) · 2.81 KB
/
_run.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
from argparse import ArgumentParser
from pathlib import Path
from src import MinimalRechner as mr
eingabe_pfad = None
ausgabe_ordner = None
#eingabe_pfad = "files/in/ihk_beispiel.in" # gib einen relativen Pfad zur Eingabedatei an
#ausgabe_ordner = "files/out/" # gib einen relativen Pfad zum Ausgabeordner an
parser = ArgumentParser()
def parse_arguments():
parser.add_argument('-i',
'--input',
help='Waehle eine Eingabedatei aus. Dateien werden relativ zu dieser Datei (_run.py) aufgerufen.',
required=False)
parser.add_argument("-o",
"--out",
help="Spezifiziere einen Ausgabeordner. Der Name der Ausgabedatei wird von der Eingabedatei abgeleitet.",
required=False)
parser.add_argument("-t",
"--test",
help="Fuehre alle Tests im Ordner tests/ aus.",
required=False,
action="store_true")
parser.add_argument("-b",
"--batch",
help="Erzeuge Ausgaben zu allen Dateien im angegebenen Ordner. Der Ordner wird relativ zu dieser Datei (_run.py) aufgerufen.",
required=False)
args = parser.parse_args()
if eingabe_pfad == None and (args.test == False and args.input == None and args.batch == None):
parser.error("Keine Eingabedatei angegeben!")
return args
def fuehre_tests_aus():
try:
import pytest
print("Fuehre Tests aus...")
pytest.main(["tests/"])
except ImportError:
print("pytest nicht gefunden. Bitte installiere pytest mit pip install pytest.\nDas Programm kann auch ohne pytest ausgefuehrt werden. Lassen Sie dafuer den Parameter -t weg und spezifizieren Sie eine Eingabedatei mit dem Parameter -i.")
args = vars(parse_arguments())
if args["input"] != None:
eingabe_pfad = args["input"]
if args["out"] != None:
ausgabe_ordner = args["out"]
if args["test"] == True:
fuehre_tests_aus()
else:
if args["batch"] != None:
import os
eingabe_pfad = args["batch"]
root_path = Path(__file__).parent.resolve()
pfad = root_path.joinpath(eingabe_pfad)
for file in os.listdir(pfad):
if os.path.isfile(os.path.join(pfad,file)):
m = mr.MinimalRechner(pfad=f"../{eingabe_pfad}/{file}")
m.berechneMinimalloesung(ausgabeOrdner=f"../{eingabe_pfad}/out/")
else:
if eingabe_pfad == None:
raise ValueError("Keine Eingabedatei angegeben!")
m = mr.MinimalRechner(pfad=f"../{eingabe_pfad}")
out_path = f"../{ausgabe_ordner}" if ausgabe_ordner else None
m.berechneMinimalloesung(ausgabeOrdner=out_path)