28 lines
609 B
Python
28 lines
609 B
Python
# src/ctf/utils.py
|
|
# basic utilities
|
|
|
|
import tomllib
|
|
import json
|
|
import toml
|
|
from pathlib import Path
|
|
from platformdirs import user_config_dir
|
|
# Parse config file
|
|
|
|
|
|
def load_config(config = f"{user_config_dir()}/ctf-config.toml") -> dict:
|
|
p = Path(config)
|
|
if p.exists():
|
|
return toml.load(p)
|
|
return{}
|
|
|
|
def write_config(data: dict, config = f"{user_config_dir()}/ctf"):
|
|
with open(config, "w") as f:
|
|
toml.dump(data, f)
|
|
|
|
|
|
config = load_config("/home/venus/code/ctf/config.toml")
|
|
competition = config["Competition"]
|
|
enviroment = config["Enviroment"]
|
|
# base_dir = config["ctf_dir"]
|
|
|