closer, need to add url validation, remove empty dicts and/or keep defaults
This commit is contained in:
parent
7fb8da5108
commit
885d120e1e
6 changed files with 37 additions and 25 deletions
|
|
@ -224,4 +224,4 @@ class PluginMapping:
|
|||
if plugin_type.plugin_options_type == plugin_options.__class__:
|
||||
return name
|
||||
|
||||
raise ValueError("Plugin name does not exist")
|
||||
raise ValueError("Plugin name does not exist")
|
||||
|
|
|
|||
|
|
@ -194,11 +194,15 @@ class Preset(_PresetShell):
|
|||
self.plugins: PresetPlugins = self._validate_and_get_plugins()
|
||||
self.overrides = self._validate_key(key="overrides", validator=Overrides, default={})
|
||||
|
||||
self.validated_dict = VariableValidation(
|
||||
downloader_options=self.downloader_options,
|
||||
output_options=self.output_options,
|
||||
plugins=self.plugins,
|
||||
).initialize_preset_overrides(overrides=self.overrides).ensure_proper_usage()
|
||||
self.validated_dict = (
|
||||
VariableValidation(
|
||||
downloader_options=self.downloader_options,
|
||||
output_options=self.output_options,
|
||||
plugins=self.plugins,
|
||||
)
|
||||
.initialize_preset_overrides(overrides=self.overrides)
|
||||
.ensure_proper_usage()
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
|
|
|
|||
|
|
@ -199,17 +199,16 @@ class VariableValidation:
|
|||
for plugin_options in PluginMapping.order_options_by(
|
||||
self.plugins.zipped(), PluginOperation.MODIFY_ENTRY
|
||||
):
|
||||
plugin_key = PluginMapping.name_of(plugin_options)
|
||||
self._add_variables(PluginOperation.MODIFY_ENTRY, options=plugin_options)
|
||||
|
||||
# Validate that any formatter in the plugin options can resolve
|
||||
resolved_subscription[plugin_key] = validate_formatters(
|
||||
resolved_subscription |= validate_formatters(
|
||||
script=self.script,
|
||||
unresolved_variables=self.unresolved_variables,
|
||||
validator=plugin_options,
|
||||
)
|
||||
|
||||
resolved_subscription["output_options"] = validate_formatters(
|
||||
resolved_subscription |= validate_formatters(
|
||||
script=self.script,
|
||||
unresolved_variables=self.unresolved_variables,
|
||||
validator=self.output_options,
|
||||
|
|
|
|||
|
|
@ -240,15 +240,13 @@ def _validate_formatter(
|
|||
)
|
||||
try:
|
||||
out = mock_script.resolve_once(
|
||||
{
|
||||
"tmp_var": formatter_validator.format_string
|
||||
},
|
||||
{"tmp_var": formatter_validator.format_string},
|
||||
unresolvable=unresolvable,
|
||||
update=True,
|
||||
)
|
||||
|
||||
if is_static_formatter:
|
||||
return out['tmp_var'].native
|
||||
return out["tmp_var"].native
|
||||
return formatter_validator.format_string
|
||||
except RuntimeException as exc:
|
||||
if isinstance(exc, ScriptVariableNotResolved) and is_static_formatter:
|
||||
|
|
@ -270,35 +268,37 @@ def validate_formatters(
|
|||
"""
|
||||
resolved_dict: Dict = {}
|
||||
if isinstance(validator, DictValidator):
|
||||
resolved_dict[validator._name] = {}
|
||||
resolved_dict[validator._leaf_name] = {}
|
||||
# pylint: disable=protected-access
|
||||
# Usage of protected variables in other validators is fine. The reason to keep
|
||||
# them protected is for readability when using them in subscriptions.
|
||||
for key, validator_value in validator._validator_dict.items():
|
||||
resolved_dict[validator._name][key] = validate_formatters(
|
||||
resolved_dict[validator._leaf_name][key] = validate_formatters(
|
||||
script=script,
|
||||
unresolved_variables=unresolved_variables,
|
||||
validator=validator_value,
|
||||
)
|
||||
# pylint: enable=protected-access
|
||||
elif isinstance(validator, ListValidator):
|
||||
resolved_dict[validator._name] = []
|
||||
resolved_dict[validator._leaf_name] = []
|
||||
for list_value in validator.list:
|
||||
resolved_dict[validator._name].append(validate_formatters(
|
||||
script=script,
|
||||
unresolved_variables=unresolved_variables,
|
||||
validator=list_value,
|
||||
))
|
||||
resolved_dict[validator._leaf_name].append(
|
||||
validate_formatters(
|
||||
script=script,
|
||||
unresolved_variables=unresolved_variables,
|
||||
validator=list_value,
|
||||
)
|
||||
)
|
||||
elif isinstance(validator, (StringFormatterValidator, OverridesStringFormatterValidator)):
|
||||
resolved_dict[validator._name] = _validate_formatter(
|
||||
resolved_dict[validator._leaf_name] = _validate_formatter(
|
||||
mock_script=script,
|
||||
unresolved_variables=unresolved_variables,
|
||||
formatter_validator=validator,
|
||||
)
|
||||
elif isinstance(validator, (DictFormatterValidator, OverridesDictFormatterValidator)):
|
||||
resolved_dict[validator._name] = {}
|
||||
resolved_dict[validator._leaf_name] = {}
|
||||
for key, validator_value in validator.dict.items():
|
||||
resolved_dict[validator._name][key] = _validate_formatter(
|
||||
resolved_dict[validator._leaf_name][key] = _validate_formatter(
|
||||
mock_script=script,
|
||||
unresolved_variables=unresolved_variables,
|
||||
formatter_validator=validator_value,
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ class DictValidator(Validator):
|
|||
value=self._dict.get(key, default),
|
||||
)
|
||||
|
||||
self.__validator_dict[validator_name] = validator_instance
|
||||
self.__validator_dict[key] = validator_instance
|
||||
return validator_instance
|
||||
|
||||
@final
|
||||
|
|
|
|||
|
|
@ -546,3 +546,12 @@ def test_default_docker_config_and_subscriptions(docker_default_subscription_pat
|
|||
config=default_config, subscription_path=docker_default_subscription_path
|
||||
)
|
||||
assert len(default_subs) == 1
|
||||
|
||||
|
||||
def test_tv_show_resolved_yaml(config_file: ConfigFile, tv_show_subscriptions_path: Path):
|
||||
subs = Subscription.from_file_path(
|
||||
config=config_file, subscription_path=tv_show_subscriptions_path
|
||||
)
|
||||
|
||||
assert len(subs) == 8
|
||||
assert subs[0].resolved_yaml() == {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue