Read values out of a config file instead of hardcoding them. Further streamline common tasks in a new base config class.
This commit is contained in:
parent
606f27185c
commit
057ac98843
11 changed files with 83 additions and 69 deletions
|
|
@ -2,17 +2,9 @@ import io
|
|||
import pathlib
|
||||
import os
|
||||
import re
|
||||
import tomlkit
|
||||
|
||||
DOOM=pathlib.Path.home().joinpath("doom")
|
||||
DSDA_DIR=DOOM.joinpath("dsda-doom")
|
||||
DSDA_VER='0.28.3'
|
||||
DSDA=DSDA_DIR.joinpath('dsda-doom-{}-Linux.appimage'.format(DSDA_VER))
|
||||
IWADS=DOOM.joinpath("iwads")
|
||||
PWADS=DOOM.joinpath("pwads")
|
||||
DEMOS=DOOM.joinpath("demos")
|
||||
OUTPUT=DOOM.joinpath("fabricate")
|
||||
|
||||
DEFAULT_IWAD=IWADS.joinpath("DOOM2.WAD")
|
||||
from cliff.command import Command
|
||||
|
||||
THUMB_WIDTH=1280
|
||||
THUMB_HEIGHT=720
|
||||
|
|
@ -22,21 +14,47 @@ TEXT_STROKE_COLOR="srgb(176,0,0)"
|
|||
|
||||
MIRROR="https://youfailit.net/pub/idgames" # NYC
|
||||
|
||||
def Complevel(wad):
|
||||
complevel = PwadPath(wad).joinpath("complevel")
|
||||
if not complevel.exists():
|
||||
raise Exception("No complevel set in PWAD dir {}.".format(pwadpath))
|
||||
|
||||
with io.open(complevel) as f:
|
||||
return f.read().strip()
|
||||
class Base(Command):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super().get_parser(prog_name)
|
||||
parser.add_argument('--doom', default=pathlib.Path.home().joinpath("doom"))
|
||||
parser.add_argument('--config-name', default='config.toml')
|
||||
return parser
|
||||
|
||||
def IwadPath(wad):
|
||||
iwad = DEFAULT_IWAD
|
||||
iwadpath = PwadPath(wad).joinpath("iwad")
|
||||
if iwadpath.exists():
|
||||
with io.open(iwadpath) as f:
|
||||
iwad = IWADS.joinpath(f.read().strip() + ".WAD")
|
||||
return iwad
|
||||
def run(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()
|
||||
self._dsda = self._config.get("dsda")
|
||||
if self.dsda is None:
|
||||
raise Exception(f"required key 'dsda' not set in config {self.doom.joinpath(self.config_name)}.")
|
||||
for d in ("iwads", "pwads", "demos", "fabricate"):
|
||||
self._init_path(d)
|
||||
|
||||
self.take_action(parsed_args)
|
||||
|
||||
def _init_path(self, what):
|
||||
setattr(self, f"_{what}", self.doom.joinpath(self._config.get(what, what)))
|
||||
setattr(type(self), what, property(lambda self: getattr(self, f"_{what}")))
|
||||
|
||||
@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)
|
||||
|
||||
def iwad_path(self, wad):
|
||||
iwad = self.iwads.joinpath(self._config.get("default_iwad"))
|
||||
iwadpath = self.pwads.joinpath("iwad")
|
||||
if iwadpath.exists():
|
||||
with io.open(iwadpath) as f:
|
||||
iwad = self.iwads.joinpath(f.read().strip() + ".WAD")
|
||||
return iwad
|
||||
|
||||
def PwadPath(wad):
|
||||
return PWADS.joinpath(wad)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue