From 240b3b6d55b717d4675da88156d759e8aa3fed28 Mon Sep 17 00:00:00 2001 From: "Josh.5" Date: Sat, 10 Sep 2022 19:34:37 +1200 Subject: [PATCH] Tidy up plugin --- description.md | 16 ++++++++++------ plugin.py | 26 +++++++++++++++----------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/description.md b/description.md index e58806d..dcd5978 100644 --- a/description.md +++ b/description.md @@ -19,6 +19,10 @@ The following template replacements are available to your command or args. If you write one of these variables in your args, it will be substituted with the specified data from the current task. :::note +Variable substitutions are not applied to the script, only a script's args. +::: + +:::tip In some cases, you may need to place single quotes around these variables as it may contain characters that shell may otherwise attempt to parse. ::: @@ -28,7 +32,7 @@ Will be replaced with the ID of the library config that was used to process this Eg. ``` - --library={library_id} + --library='{library_id}' ``` ###### {final_cache_path} @@ -37,7 +41,7 @@ Will be replaced with the path to the final output file in the Unmanic cache dir Eg. ``` - --processed-cache-file={final_cache_path} + --processed-cache-file='{final_cache_path}' ``` ###### {output_files} @@ -48,7 +52,7 @@ Only available when **Run the command for each output f Eg. ``` - --files={output_files} + --files='{output_files}' ``` ###### {output_file_path} @@ -59,7 +63,7 @@ Only available when **Run the command for each output f Eg. ``` - --output={output_file_path} + --output='{output_file_path}' ``` ###### {source_file_path} @@ -68,7 +72,7 @@ Will be replaced with the full path to the original source file for this task. Eg. ``` - --sourcefile={source_file_path} + --sourcefile='{source_file_path}' ``` ###### {source_file_size} @@ -77,7 +81,7 @@ Will be replaced with the size in bytes of the original source file for this tas Eg. ``` - --originalsize={source_file_size} + --originalsize='{source_file_size}' ``` --- diff --git a/plugin.py b/plugin.py index fcfd77d..6f981cd 100644 --- a/plugin.py +++ b/plugin.py @@ -185,7 +185,7 @@ def get_executable_venv_python(script_dependencies, temp_working_directory, depe """ Build a VENV for python Install all required dependencies - Return the updated VENV python executable + Return the updated VENV python executable path :param script_dependencies: :param temp_working_directory: @@ -216,6 +216,15 @@ def get_executable_venv_python(script_dependencies, temp_working_directory, depe def get_executable_node(script_dependencies, temp_working_directory, dependency_cache_directory): + """ + Install all required dependencies + Return the node executable path + + :param script_dependencies: + :param temp_working_directory: + :param dependency_cache_directory: + :return: + """ node_executable = shutil.which('node') npm_executable = shutil.which('npm') @@ -236,14 +245,14 @@ def get_executable_node(script_dependencies, temp_working_directory, dependency_ return node_executable -def get_temp_directory(final_cache_path): +def get_temp_directory(cache_file_path): """ Create and return the path to a temp directory in the cache path - :param final_cache_path: + :param cache_file_path: :return: """ - output_directory = os.path.join(os.path.dirname(final_cache_path), 'postprocessor_script') + output_directory = os.path.join(os.path.dirname(cache_file_path), 'postprocessor_script') if not os.path.isdir(output_directory): os.makedirs(output_directory) return output_directory @@ -274,8 +283,7 @@ def build_script(settings, data): """ input_type = settings.get_setting('input_type') script = settings.get_setting('script') - final_cache_path = data.get('final_cache_path') - temp_working_directory = get_temp_directory(final_cache_path) + temp_working_directory = get_temp_directory(data.get('final_cache_path')) script_dependencies = settings.get_setting('script_dependencies') # We can cache the dependency installation to avoid re-downloading them each time. Fetch the cache directory here @@ -322,7 +330,7 @@ def on_postprocessor_task_results(data): :return: """ - # Configure settings object (maintain compatibility with v1 plugins) + # Configure settings object settings = Settings(library_id=data.get('library_id')) if settings.get_setting('only_on_task_processing_success'): @@ -333,10 +341,6 @@ def on_postprocessor_task_results(data): cmd = settings.get_setting('cmd') if settings.get_setting('input_type') != 'command': - # Install any dependencies - - # install_dependencies(settings.get_setting('input_type'), settings.get_setting('script_dependencies'), - # data.get('final_cache_path'), dependency_cache_directory) # Generate command to be executed cmd = build_script(settings, data) args = settings.get_setting('args')