2025-04-07 02:19:25 -04:00
|
|
|
import io
|
|
|
|
import pathlib
|
|
|
|
import os
|
|
|
|
import re
|
2025-08-29 19:20:28 -04:00
|
|
|
import tomlkit.toml_file
|
2025-04-07 02:19:25 -04:00
|
|
|
|
2025-05-17 11:50:59 -04:00
|
|
|
from cliff.command import Command
|
2025-04-07 02:19:25 -04:00
|
|
|
|
2025-04-28 18:31:36 -04:00
|
|
|
|
2025-05-17 11:50:59 -04:00
|
|
|
class Base(Command):
|
2025-06-14 22:40:05 -04:00
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super().get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
2025-08-01 02:05:05 -04:00
|
|
|
"--doom", default=pathlib.Path.home().joinpath("doom"))
|
|
|
|
parser.add_argument("--config-name", default="config.toml")
|
2025-06-14 22:40:05 -04:00
|
|
|
return parser
|
2025-04-28 18:31:36 -04:00
|
|
|
|
2025-06-14 22:40:05 -04:00
|
|
|
def init_base(self, parsed_args):
|
|
|
|
self._doom = pathlib.Path(parsed_args.doom)
|
|
|
|
self._config_name = parsed_args.config_name
|
|
|
|
self._config = tomlkit.toml_file.TOMLFile(
|
|
|
|
self.doom.joinpath(self.config_name)).read()
|
2025-07-23 18:26:45 -04:00
|
|
|
|
2025-06-14 22:40:05 -04:00
|
|
|
self._dsda = self._config.get("dsda")
|
|
|
|
if self.dsda is None:
|
|
|
|
raise Exception(
|
|
|
|
"required key 'dsda' not set in config "
|
|
|
|
+ f"{self.doom.joinpath(self.config_name)}.")
|
|
|
|
for d in ("iwads", "pwads", "demos", "fabricate"):
|
2025-07-04 11:50:10 -04:00
|
|
|
self._init_attr([d], d, fn=self.doom.joinpath)
|
2025-07-03 18:04:19 -04:00
|
|
|
|
2025-07-23 18:26:45 -04:00
|
|
|
def finalize(self):
|
2025-07-04 11:50:10 -04:00
|
|
|
self._init_attr(["thumbnail", "height"], 720)
|
|
|
|
self._init_attr(["thumbnail", "width"], 1280)
|
|
|
|
self._init_attr(["thumbnail", "font"], None)
|
|
|
|
self._init_attr(["thumbnail", "text_fill"], "white")
|
|
|
|
self._init_attr(["thumbnail", "text_stroke"], "red")
|
|
|
|
self._init_attr(
|
|
|
|
["fetch", "mirror"],
|
|
|
|
"https://youfailit.net/pub/idgames"
|
|
|
|
)
|
2025-06-14 22:40:05 -04:00
|
|
|
|
|
|
|
def run(self, parsed_args):
|
|
|
|
self.init_base(parsed_args)
|
2025-07-30 19:45:51 -04:00
|
|
|
self.finalize()
|
2025-06-14 22:40:05 -04:00
|
|
|
self.take_action(parsed_args)
|
|
|
|
|
2025-07-03 18:04:19 -04:00
|
|
|
def _init_attr(self, what, default, fn=lambda x: x):
|
2025-07-04 11:50:10 -04:00
|
|
|
propname = "_".join(what)
|
|
|
|
val = self._config
|
|
|
|
for w in what:
|
|
|
|
val = val[w]
|
|
|
|
if val is None:
|
|
|
|
val = default
|
|
|
|
break
|
|
|
|
|
|
|
|
setattr(self, f"_{propname}", fn(val))
|
2025-06-14 22:40:05 -04:00
|
|
|
setattr(
|
2025-07-04 11:50:10 -04:00
|
|
|
type(self), propname,
|
|
|
|
property(lambda self: getattr(self, f"_{propname}"))
|
|
|
|
)
|
2025-06-14 22:40:05 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def doom(self):
|
|
|
|
return self._doom
|
|
|
|
|
|
|
|
@property
|
|
|
|
def config_name(self):
|
|
|
|
return self._config_name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def dsda(self):
|
|
|
|
return self._doom.joinpath(self._dsda)
|