cleaning things up by refactoring and combining files
This commit is contained in:
26
src/ctf/config.py
Normal file
26
src/ctf/config.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# src/ctf/config.py
|
||||
# {{{ imports
|
||||
import toml
|
||||
from pathlib import Path
|
||||
from platformdirs import user_config_dir
|
||||
# }}}
|
||||
|
||||
# {{{ load_config
|
||||
def load_config(config = f"{user_config_dir()}/ctf-config.toml") -> dict:
|
||||
p = Path(config)
|
||||
if p.exists():
|
||||
return toml.load(p)
|
||||
return {}
|
||||
# }}}
|
||||
|
||||
# {{{ write_config
|
||||
def write_config(data: dict, config = f"{user_config_dir()}/ctf"):
|
||||
with open(config, "w") as f:
|
||||
toml.dump(data, f)
|
||||
# }}}
|
||||
|
||||
# {{{ exports
|
||||
config_data = load_config("/home/venus/code/ctf/config.toml")
|
||||
competition = config_data.get("Competition", {})
|
||||
enviroment = config_data.get("Enviroment", {})
|
||||
# }}}
|
||||
Reference in New Issue
Block a user