master > master: code - refactored
This commit is contained in:
parent
3941348420
commit
0faca1e6bb
@ -8,7 +8,7 @@
|
|||||||
import functools;
|
import functools;
|
||||||
|
|
||||||
from code.core.log import *;
|
from code.core.log import *;
|
||||||
from code.display.display import *;
|
from code.setup.display import *;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# CLASSES
|
# CLASSES
|
||||||
|
23
code/main.py
23
code/main.py
@ -12,14 +12,14 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
|||||||
|
|
||||||
from code.core.log import *;
|
from code.core.log import *;
|
||||||
from code.core.config import *;
|
from code.core.config import *;
|
||||||
from code.display.display import *;
|
from code.setup.display import *;
|
||||||
|
from code.setup.cli import *;
|
||||||
from code.algorithms.exports import *;
|
from code.algorithms.exports import *;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# GLOBAL VARIABLES/CONSTANTS
|
# GLOBAL VARIABLES/CONSTANTS
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
parser: argparse.ArgumentParser;
|
|
||||||
PATH_TO_CONFIG: str = 'code/config.yml';
|
PATH_TO_CONFIG: str = 'code/config.yml';
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -33,7 +33,7 @@ def enter(quiet: bool, debug: bool, mode: str, path: Any, **_):
|
|||||||
if mode == 'all':
|
if mode == 'all':
|
||||||
LoopThroughCases(path=configpath);
|
LoopThroughCases(path=configpath);
|
||||||
else:
|
else:
|
||||||
parser.print_help();
|
DisplayHelpMessage();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -74,22 +74,9 @@ def LoopThroughCases(path: str):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.tracebacklimit = 0;
|
sys.tracebacklimit = 0;
|
||||||
cli_args = sys.argv[1:];
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
prog='code/main.py',
|
|
||||||
description=dedent('''
|
|
||||||
\033[93;1mBeschreibung:\033[0m
|
|
||||||
\033[93;2mEin Programm, das verschiedene Algorithmen aus dem Kurs AlgoDat I testet.\033[0m
|
|
||||||
'''),
|
|
||||||
formatter_class=argparse.RawTextHelpFormatter,
|
|
||||||
);
|
|
||||||
parser.add_argument('mode', nargs=1, choices=['all'], help='all = Führt alle Testfälle in der config.yml Datei durch.');
|
|
||||||
parser.add_argument('--path', nargs=1, type=str, help='Pfad zur alternativen Configdatei.');
|
|
||||||
parser.add_argument('--debug', action='store_true', help='Debugging Messages stummschalten.')
|
|
||||||
parser.add_argument('-q', '--quiet', action='store_true', help='Alle console-messages bis auf Errors stummschalten.')
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args(cli_args);
|
args = GetArgumentsFromCli(sys.argv[1:]);
|
||||||
except:
|
except:
|
||||||
parser.print_help();
|
DisplayHelpMessage();
|
||||||
exit(1);
|
exit(1);
|
||||||
enter(quiet=args.quiet, debug=args.debug, mode=args.mode[0], path=args.path);
|
enter(quiet=args.quiet, debug=args.debug, mode=args.mode[0], path=args.path);
|
||||||
|
41
code/setup/cli.py
Normal file
41
code/setup/cli.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# IMPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
from code.local.typing import *;
|
||||||
|
|
||||||
|
from code.core.log import *;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# GLOBAL VARIABLES
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
parser = None;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# METHODS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
def GetArgumentParser() -> argparse.ArgumentParser:
|
||||||
|
global parser;
|
||||||
|
if not isinstance(parser, argparse.ArgumentParser):
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='code/main.py',
|
||||||
|
description=dedent('''
|
||||||
|
\033[93;1mBeschreibung:\033[0m
|
||||||
|
\033[93;2mEin Programm, das verschiedene Algorithmen aus dem Kurs AlgoDat I testet.\033[0m
|
||||||
|
'''),
|
||||||
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
|
);
|
||||||
|
parser.add_argument('mode', nargs=1, choices=['all'], help='all = Führt alle Testfälle in der config.yml Datei durch.');
|
||||||
|
parser.add_argument('--path', nargs=1, type=str, help='Pfad zur alternativen Configdatei.');
|
||||||
|
parser.add_argument('--debug', action='store_true', help='Debugging Messages stummschalten.')
|
||||||
|
parser.add_argument('-q', '--quiet', action='store_true', help='Alle console-messages bis auf Errors stummschalten.')
|
||||||
|
return parser;
|
||||||
|
|
||||||
|
def GetArgumentsFromCli(cli_args: List[str]) -> argparse.Namespace:
|
||||||
|
parser = GetArgumentParser();
|
||||||
|
return parser.parse_args(cli_args);
|
@ -8,6 +8,16 @@
|
|||||||
from code.local.typing import *;
|
from code.local.typing import *;
|
||||||
|
|
||||||
from code.core.log import *;
|
from code.core.log import *;
|
||||||
|
from code.setup.cli import GetArgumentParser;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# METHODS display help
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
def DisplayHelpMessage():
|
||||||
|
parser = GetArgumentParser();
|
||||||
|
parser.print_help();
|
||||||
|
return;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# METHODS display case
|
# METHODS display case
|
Loading…
x
Reference in New Issue
Block a user