better error checking in commands

This commit is contained in:
bobokun 2022-12-07 09:16:26 -05:00
parent fa61c00504
commit 0003ffd554
No known key found for this signature in database
GPG key ID: B73932169607D927
2 changed files with 24 additions and 18 deletions

View file

@ -18,6 +18,19 @@ from modules.webhooks import Webhooks
logger = util.logger logger = util.logger
COMMANDS = [
"cross_seed",
"recheck",
"cat_update",
"tag_update",
"rem_unregistered",
"tag_tracker_error",
"rem_orphaned",
"tag_nohardlinks",
"skip_cleanup",
"dry_run",
]
class Config: class Config:
def __init__(self, default_dir, args): def __init__(self, default_dir, args):
@ -47,24 +60,16 @@ class Config:
if "commands" in self.data: if "commands" in self.data:
if self.data["commands"] is not None: if self.data["commands"] is not None:
logger.info(f"Commands found in {config_file}, ignoring env variables and using config commands instead.") logger.info(f"Commands found in {config_file}, ignoring env variables and using config commands instead.")
self.commands = self.data.pop("commands") self.commands = {}
if "dry_run" not in self.commands: for command in COMMANDS:
self.commands["dry_run"] = args["dry_run"] if "dry_run" in args else False self.commands[command] = self.util.check_for_attribute(
# Add default any missing commands as False self.data,
for v in [ command,
"cross_seed", parent="commands",
"recheck", var_type="bool",
"cat_update", default=False,
"tag_update", save=True,
"rem_unregistered", )
"tag_tracker_error",
"rem_orphaned",
"tag_nohardlinks",
"skip_cleanup",
]:
if v not in self.commands:
self.commands[v] = False
logger.debug(f" --cross-seed (QBT_CROSS_SEED): {self.commands['cross_seed']}") logger.debug(f" --cross-seed (QBT_CROSS_SEED): {self.commands['cross_seed']}")
logger.debug(f" --recheck (QBT_RECHECK): {self.commands['recheck']}") logger.debug(f" --recheck (QBT_RECHECK): {self.commands['recheck']}")
logger.debug(f" --cat-update (QBT_CAT_UPDATE): {self.commands['cat_update']}") logger.debug(f" --cat-update (QBT_CAT_UPDATE): {self.commands['cat_update']}")

View file

@ -118,6 +118,7 @@ class check:
return data[attribute] return data[attribute]
else: else:
message = f"{text} must be either true or false" message = f"{text} must be either true or false"
throw = True
elif var_type == "int": elif var_type == "int":
if isinstance(data[attribute], int) and data[attribute] >= min_int: if isinstance(data[attribute], int) and data[attribute] >= min_int:
return data[attribute] return data[attribute]