Skip to content

Commit

Permalink
Added basic configuration set up.
Browse files Browse the repository at this point in the history
  • Loading branch information
dayeya committed Apr 12, 2024
1 parent 33706b1 commit 9bf2a40
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

from app.user import User
from app.db_handling import DB
from app_config import get_configuration_from_section
from app_config import get_section


INI_FILE = Path("app.ini")


def get_proxy_configuration():
config = get_configuration_from_section("PROXY", INI_FILE)
def get_proxy_configuration() -> tuple:
config = get_section(section_name="PROXY", file=INI_FILE)
if not config.getboolean(option="proxy_enabled"):
return "127.0.0.1", 50000
return config["ip"], config["port"]
Expand Down
2 changes: 1 addition & 1 deletion app_config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .ini import set_global_parser, get_configuration_from_section
from .ini import set_global_parser, get_configuration_from_section, get_section
10 changes: 2 additions & 8 deletions app_config/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from configparser import SectionProxy
from typing import Iterable

global PARSER
PARSER: parser.ConfigParser = None

ROOT_DIR = plib.Path(__file__).parent


Expand All @@ -22,20 +20,16 @@ def chain_path(file: plib.Path) -> plib.Path:


def set_global_parser() -> None:
"""
Sets the global parser.
Returns: None
"""
global PARSER

if not PARSER:
PARSER = parser.ConfigParser()


def get_configuration_from_section(section_name: str, file: plib.Path, keys: Iterable=None):
def get_configuration(section_name: str, file: plib.Path, keys: Iterable=None):
try:
section = get_section(section_name, file=file)
return section if not keys else [section[item] for item in keys]
return section if not keys else [section.get(item) for item in keys]
except KeyError as _e:
raise ValueNotFound(f"Some values of {keys} don't exit in the specified file object or {section_name}.")

Expand Down

0 comments on commit 9bf2a40

Please sign in to comment.