yfrake.config.utils.get_default_config_path()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
# ==================================================================================== #
2
#    utils.py - This file is part of the YFrake package.                               #
3
# ------------------------------------------------------------------------------------ #
4
#                                                                                      #
5
#    MIT License                                                                       #
6
#                                                                                      #
7
#    Copyright (c) 2022 Mattias Aabmets                                                #
8
#                                                                                      #
9
#    Permission is hereby granted, free of charge, to any person obtaining a copy      #
10
#    of this software and associated documentation files (the "Software"), to deal     #
11
#    in the Software without restriction, including without limitation the rights      #
12
#    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell         #
13
#    copies of the Software, and to permit persons to whom the Software is             #
14
#    furnished to do so, subject to the following conditions:                          #
15
#                                                                                      #
16
#    The above copyright notice and this permission notice shall be included in all    #
17
#    copies or substantial portions of the Software.                                   #
18
#                                                                                      #
19
#    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR        #
20
#    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,          #
21
#    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE       #
22
#    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER            #
23
#    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,     #
24
#    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE     #
25
#    SOFTWARE.                                                                         #
26
#                                                                                      #
27
# ==================================================================================== #
28
from . import config_file_name
29
from argparse import ArgumentParser
30
from pathlib import Path
31
import shutil
32
import os
33
34
35
# ==================================================================================== #
36
def get_runtime_args() -> dict:  # pragma: no cover
37
    default = get_default_config_path()
38
    parser = ArgumentParser()
39
    parser.add_argument('--run-server', action='store_true', default=False)
40
    parser.add_argument('--config-file', type=str, default=str(default))
41
    ns = parser.parse_args()
42
    return dict(
43
        run_server=ns.run_server,
44
        config_file=ns.config_file
45
    )
46
47
48
# ------------------------------------------------------------------------------------ #
49
def get_default_config_path() -> Path:
50
    return Path(__file__).with_name(config_file_name).resolve()
51
52
53
# ------------------------------------------------------------------------------------ #
54
def get_cwd_config_path() -> Path:
55
    return Path(os.getcwd()).joinpath(config_file_name).resolve()
56
57
58
# ------------------------------------------------------------------------------------ #
59
def copy_default_config_to(dest: Path) -> None:
60
    default_config = get_default_config_path()
61
    shutil.copy(default_config, dest)
62