Skip to content

Commit

Permalink
Tidy up plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh5 committed Sep 10, 2022
1 parent 6b48ec6 commit 240b3b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
16 changes: 10 additions & 6 deletions description.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
:::

Expand All @@ -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}'
```

###### <span style="color:green">{final_cache_path}</span>
Expand All @@ -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}'
```

###### <span style="color:green">{output_files}</span>
Expand All @@ -48,7 +52,7 @@ Only available when **<span style="color:blue">Run the command for each output f

Eg.
```
--files={output_files}
--files='{output_files}'
```

###### <span style="color:green">{output_file_path}</span>
Expand All @@ -59,7 +63,7 @@ Only available when **<span style="color:blue">Run the command for each output f

Eg.
```
--output={output_file_path}
--output='{output_file_path}'
```

###### <span style="color:green">{source_file_path}</span>
Expand All @@ -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}'
```

###### <span style="color:green">{source_file_size}</span>
Expand All @@ -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}'
```

---
Expand Down
26 changes: 15 additions & 11 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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')

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand All @@ -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')
Expand Down

0 comments on commit 240b3b6

Please sign in to comment.