initial config

master
JoYo 2021-12-07 17:00:56 -05:00
parent 30cfbd2157
commit c937dae3b4
5 changed files with 73 additions and 2 deletions

View File

@ -3,6 +3,7 @@ ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
python3-pip \
python3-yaml \
&& apt-get clean
COPY ./banana/ /app/banana/

3
banana/__main__.py Normal file
View File

@ -0,0 +1,3 @@
from . import scripts
scripts.periodical_script()

27
banana/config.py Normal file
View File

@ -0,0 +1,27 @@
import yaml
from pathlib import Path
def new(path: Path):
config = {
"addons": [None],
"eso": {"path": None},
}
with path.open("w") as file_open:
config = yaml.dump(config, file_open, default_flow_style=False)
def load(path: Path) -> dict:
with path.open("r") as file_open:
config = yaml.load(file_open)
return config
def valid(config: dict) -> bool:
assert config.get("addons")
assert config.get("eso")
if not "path" in config.get("eso"):
raise AssertionError()

View File

@ -0,0 +1,39 @@
from argparse import ArgumentParser
import logging
import requests
from pathlib import Path
from . import config
def periodical_script():
parser = ArgumentParser(description="Secret sharing script.")
parser.add_argument("-v", "--verbose", action="count", help="verbose logging")
parser.add_argument(
"-c", "--config", default="banana.yaml", help="configuration file path"
)
args = parser.parse_args()
if args.verbose:
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(filename)s:%(lineno)d %(message)s",
)
else:
logging.basicConfig(
level=logging.INFO,
format="%(message)s",
)
logging.info(args)
config_path = Path(args.config)
config_path.touch(exist_ok=True)
config_current = config.load(config_path)
try:
config.valid(config_current)
except (AssertionError, AttributeError) as error:
logging.debug(error)
config.new(config_path)
config_current = config.load(config_path)

View File

@ -6,14 +6,15 @@ build-backend = "poetry.masonry.api"
authors = ["py <py@py>"]
description = ""
license = "MIT"
name = "banana"
name = "eso-banana"
version = "0.0.1"
[[tool.poetry.packages]]
include = "banana"
[tool.poetry.scripts]
banana-script = "banana:scripts.periodical_script"
eso-banana-script = "banana:scripts.periodical_script"
[tool.poetry.dependencies]
requests = ""
PyYAML = ""