Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 47: enable custom batch templates #48

Merged
merged 6 commits into from
Sep 29, 2022
Merged

Fix issue 47: enable custom batch templates #48

merged 6 commits into from
Sep 29, 2022

Conversation

dennisvang
Copy link
Owner

@dennisvang dennisvang commented Sep 29, 2022

fixes #47

In addition to the existing install function override, this PR adds the ability for users to supply a custom batch template (for windows), by passing a batch_template argument to Client.download_and_install_update().

The default template WIN_BATCH_TEMPLATE can be used as an example (see here).

The following default variables are available for use in the custom template, but they can also be omitted:

  • {log_lines} inserts lines that cause batch file output to be logged to file
  • {src_dir} inserts path to source directory
  • {dst_dir} inserts path to destination directory
  • {robocopy_options} inserts robocopy options (default or custom)
  • {delete_self} inserts a line that causes the batch file to delete itself (should only be used at end of file)

The user can also introduce custom template variables, e.g. {my_variable}, or they can pass a pre-filled template without any variables.

If custom template variables are used, they must be passed into Client.download_and_install_update() using the batch_template_extra_kwargs argument.

Usage example (note this template doesn't do anything useful):

custom_template = """
echo {custom_content}> "{custom_file_path}"
{delete_self}
"""
custom_template_variables = dict(
    custom_content='some content',
    custom_file_path=r'some\file\path',
)

...

client.download_and_install_update(
    ..., 
    batch_template=custom_template, 
    batch_template_extra_kwargs=custom_template_variables, 
    ...,
)

...

Also see example in tests.

rename WIN_MOVE_FILES_BAT to WIN_BATCH_TEMPLATE

and add some comments to clarify win install function
implement batch_template arguments for _install_update_win

and rename batch template variables for clarity
implement WIN_BATCH_DELETE_SELF and prefix/suffix variables
add test for custom batch template on windows
amend docstring for _install_update_win
update docstring for _install_update_win again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow custom batch-file templates
1 participant