-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (36 loc) · 1.48 KB
/
main.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
import argparse
import logging
import os
from pathlib import Path
from InRetEnsys import ModelBuilder
from InRetEnsys.common.log import InRetEnsysLogger
parser = argparse.ArgumentParser(
prog = 'main.py',
description='InRetEnsys Backend.',
epilog = 'In.RET - Institut für regenerative Energietechnik'
)
parser.add_argument('file', help="Filepath of the configuration.")
parser.add_argument('-wdir', '--workingdirectory', help="Path to the workingdirectory to use.", default=None)
parser.add_argument('-olp', '--only_lp_file', action='store_true', help="If choosen, only the lp-file is stored.", default=False, required=False)
args = parser.parse_args()
configfile = args.file
if args.workingdirectory is not None:
workdir = args.workingdirectory
else:
workdir = os.getcwd()
dumpdir = os.path.join(workdir, "dumps")
logdir = os.path.join(workdir, "logs")
tmpfilename: str = os.path.basename(configfile)
if tmpfilename.find(".json") > 0:
dumpfile = os.path.join(dumpdir, tmpfilename.replace(".json", ".dump"))
logfile = os.path.join(logdir, tmpfilename.replace(".json", ".log"))
else:
raise Exception("Fileformat is not valid!")
if not os.path.exists(logfile):
os.makedirs(os.path.dirname(logfile))
Path(logfile).touch()
InRetEnsysLogger(name="logger", filename=logfile, level=logging.DEBUG)
if args.only_lp_file:
ModelBuilder(configfile, dumpfile, workdir, logdir, dumpdir, True)
else:
ModelBuilder(configfile, dumpfile, workdir, logdir, dumpdir)