diff --git a/dcc/config.py b/dcc/config.py index 3b47181..6d1c4b3 100644 --- a/dcc/config.py +++ b/dcc/config.py @@ -57,11 +57,3 @@ class Base(Command): @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(wad).joinpath("iwad") - if iwadpath.exists(): - with io.open(iwadpath) as f: - iwad = self.iwads.joinpath(f.read().strip() + ".WAD") - return iwad diff --git a/dcc/configure.py b/dcc/configure.py new file mode 100644 index 0000000..c5b2304 --- /dev/null +++ b/dcc/configure.py @@ -0,0 +1,24 @@ +import dcc.config +import tomlkit +from tomlkit.toml_file import TOMLFile + +class Configure(dcc.config.Base): + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + parser.add_argument("wad") + parser.add_argument("complevel") + parser.add_argument("--iwad") + return parser + + def take_action(self, parsed_args): + new_config = self.pwads.joinpath(parsed_args.wad).joinpath(self.config_name) + if new_config.exists(): + raise Exception("Config %s already exists.".format(new_config)) + + doc = tomlkit.document() + doc.add("complevel", parsed_args.complevel) + if parsed_args.iwad is not None: + doc.add("iwad", parsed_args.iwad) + + f = TOMLFile(new_config) + f.write(doc) diff --git a/dcc/doom_base.py b/dcc/doom_base.py index 48d411a..3833bd8 100644 --- a/dcc/doom_base.py +++ b/dcc/doom_base.py @@ -29,6 +29,14 @@ class Wad(dcc.config.Base): def wad(self): return self._wad + def iwad_path(self): + iwad = self.iwads.joinpath(self._config.get("iwad")) + iwadpath = self.pwads.joinpath(self.wad).joinpath("iwad") + if iwadpath.exists(): + with io.open(iwadpath) as f: + iwad = self.iwads.joinpath(f.read().strip() + ".WAD") + return iwad + class WadMap(Wad): def get_parser(self, prog_name): @@ -53,7 +61,7 @@ class WadMap(Wad): return "" if self._name is None else "_" + self._name def dsda_preamble(self): - args = ["-iwad", self.iwad_path(self.wad)] + args = ["-iwad", self.iwad_path()] pwadpath = self.pwads.joinpath(self.wad) wads = sorted(pwadpath.glob('*.wad', case_sensitive=False)) diff --git a/dcc/eureka.py b/dcc/eureka.py index d147879..1e49500 100644 --- a/dcc/eureka.py +++ b/dcc/eureka.py @@ -10,7 +10,7 @@ class Eureka(dcc.doom_base.WadMap): return parser def take_action(self, parsed_args): - iwad = self.iwad_path(parsed_args.wad) + iwad = self.iwad_path() pwadpath = self.pwads.joinpath(parsed_args.wad) if parsed_args.main is not None: mw = pwadpath.joinpath(parsed_args.main)