37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import dcc.doom_base
|
|
import omg
|
|
import tomlkit.toml_file
|
|
|
|
|
|
class Configure(dcc.doom_base.Wad):
|
|
def get_parser(self, prog_name):
|
|
parser = super().get_parser(prog_name)
|
|
parser.add_argument("--complevel", "--cl")
|
|
parser.add_argument("--iwad")
|
|
return parser
|
|
|
|
def take_action(self, parsed_args):
|
|
new_config = self.pwad_path.joinpath(self.config_name)
|
|
if new_config.exists():
|
|
raise Exception(f"Config {new_config} already exists.")
|
|
|
|
complevel = parsed_args.complevel
|
|
if complevel is None:
|
|
for w in self.load_order():
|
|
try:
|
|
wad = omg.WadIO(w)
|
|
complevel = wad.read("COMPLVL").decode("ascii").strip()
|
|
except Exception as e:
|
|
print(
|
|
f"Wad {w} likely has no lump COMPLVL (exception {e})")
|
|
if complevel is None:
|
|
complevel = input("Complevel? ")
|
|
|
|
|
|
doc = tomlkit.document()
|
|
doc.add("complevel", complevel)
|
|
if parsed_args.iwad is not None:
|
|
doc.add("iwad", parsed_args.iwad)
|
|
|
|
f = tomlkit.toml_file.TOMLFile(new_config)
|
|
f.write(doc)
|