-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
87 lines (73 loc) · 2.14 KB
/
__init__.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
79
80
81
82
83
84
85
86
87
from argparse import ArgumentParser
from typing import Optional, List
from pathlib import Path
from .gui import main as gui_main
from src.simpletkgrid import Config
from src.simpletkgrid.config import DEFAULTSECT
from .define import (
__version__,
APPNAME,
APPNAME_FULL,
DEFAULT_WORKDIR,
DEFAULT_CONFIG,
messages,
)
__all__ = (
"__version__",
"main",
)
def main(args: Optional[List[str]] = None) -> None:
parser = ArgumentParser()
parser_mode = parser.add_mutually_exclusive_group()
parser_mode.add_argument(
"--background",
action="store_true",
help=messages.option.background)
parser.add_argument(
"--workdir", "-w",
required=False, default=".",
help=messages.option.workdir)
parser.add_argument(
"--configfile",
required=False, default=f"{APPNAME}.ini",
help=messages.option.configfile)
parser.add_argument(
"--config-section",
required=False, default=DEFAULTSECT,
help=messages.option.configsection)
parser.add_argument(
"--version", "-V",
action='version',
version=APPNAME_FULL)
args = parser.parse_args(args)
if args.workdir is None:
workdirpath = Path(DEFAULT_WORKDIR)
else:
workdirpath = Path(args.workdir)
configfilepath = Path(args.configfile)
if not configfilepath.is_absolute():
configfilepath = workdirpath / args.configfile
config_section: str = args.config_section
background_mode: bool = args.background
# Load configuration file
kwargs_config = dict(
section=config_section,
notfound_ok=True,
default=DEFAULT_CONFIG,
cast=False,
strict_cast=False,
strict_key=True,
)
if configfilepath.is_file():
config = Config(configfilepath, **kwargs_config)
else:
config = Config(DEFAULT_CONFIG, **kwargs_config)
config.save(configfilepath)
if args.workdir is not None:
config["workdir"] = args.workdir
config.cast()
if background_mode:
pass
else:
return gui_main(config=config, args=args)
return None