resolve filter
This commit is contained in:
parent
7f61058d0e
commit
3929954433
2 changed files with 51 additions and 2 deletions
|
|
@ -13,9 +13,7 @@ from ytdl_sub.config.plugin.preset_plugins import PresetPlugins
|
|||
from ytdl_sub.config.preset_options import OutputOptions
|
||||
from ytdl_sub.config.validators.options import OptionsValidator
|
||||
from ytdl_sub.downloaders.url.validators import MultiUrlValidator
|
||||
from ytdl_sub.entries.script.variable_definitions import VARIABLE_SCRIPTS
|
||||
from ytdl_sub.entries.variables.override_variables import SubscriptionVariables
|
||||
from ytdl_sub.script.parser import parse
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.utils.scriptable import BASE_SCRIPT
|
||||
from ytdl_sub.validators.string_formatter_validators import to_variable_dependency_format_string
|
||||
|
|
@ -78,7 +76,9 @@ def _override_variables(overrides: Overrides) -> Set[str]:
|
|||
def _entry_variables() -> Dict[str, str]:
|
||||
return {
|
||||
name: to_variable_dependency_format_string(
|
||||
# pylint: disable=protected-access
|
||||
script=BASE_SCRIPT, parsed_format_string=BASE_SCRIPT._variables[name]
|
||||
# pylint: enable=protected-access
|
||||
)
|
||||
for name in BASE_SCRIPT.variable_names
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,6 +248,48 @@ class Script:
|
|||
for variable_name, resolved in resolved_variables.items():
|
||||
self._variables[variable_name] = SyntaxTree(ast=[resolved])
|
||||
|
||||
def _recursive_get_unresolved_output_filter_variables(
|
||||
self, current_var: SyntaxTree, subset_to_resolve: Set[str], unresolvable: Set[Variable]
|
||||
) -> Set[str]:
|
||||
for var_dep in current_var.variables:
|
||||
if var_dep in unresolvable:
|
||||
raise ScriptVariableNotResolved(
|
||||
f"Output filter variable contains the variable {var_dep} "
|
||||
f"which is set as unresolvable"
|
||||
)
|
||||
subset_to_resolve.add(var_dep.name)
|
||||
subset_to_resolve |= self._recursive_get_unresolved_output_filter_variables(
|
||||
current_var=self._variables[var_dep.name],
|
||||
subset_to_resolve=subset_to_resolve,
|
||||
unresolvable=unresolvable,
|
||||
)
|
||||
|
||||
return subset_to_resolve
|
||||
|
||||
def _get_unresolved_output_filter(
|
||||
self,
|
||||
unresolved: Dict[Variable, SyntaxTree],
|
||||
output_filter: Set[str],
|
||||
unresolvable: Set[Variable],
|
||||
) -> Dict[Variable, SyntaxTree]:
|
||||
subset_to_resolve: Set[str] = set()
|
||||
|
||||
for output_filter_variable in output_filter:
|
||||
subset_to_resolve.add(output_filter_variable)
|
||||
|
||||
if output_filter_variable not in self._variables:
|
||||
raise ScriptVariableNotResolved(
|
||||
"Tried to specify an output filter variable that does not exist"
|
||||
)
|
||||
|
||||
subset_to_resolve |= self._recursive_get_unresolved_output_filter_variables(
|
||||
current_var=self._variables[output_filter_variable],
|
||||
subset_to_resolve=subset_to_resolve,
|
||||
unresolvable=unresolvable,
|
||||
)
|
||||
|
||||
return {var: syntax for var, syntax in unresolved.items() if var.name in subset_to_resolve}
|
||||
|
||||
def _resolve(
|
||||
self,
|
||||
pre_resolved: Optional[Dict[str, Resolvable]] = None,
|
||||
|
|
@ -288,6 +330,13 @@ class Script:
|
|||
if Variable(name) not in unresolved_filter
|
||||
}
|
||||
|
||||
if output_filter:
|
||||
unresolved = self._get_unresolved_output_filter(
|
||||
unresolved=unresolved,
|
||||
output_filter=output_filter,
|
||||
unresolvable=unresolvable,
|
||||
)
|
||||
|
||||
while unresolved:
|
||||
unresolved_count: int = len(unresolved)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue