transactions.utils

Provides basic transaction utilities.

Functions

simple_automation.transactions.utils.remote_sha512sum(context: simple_automation.context.Context, path: str)

Fetch the sha512sum of a remote file.

Parameters
  • context (Context) – The host execution context

  • path (str) – The path to the remote file.

Returns

The hexlified sha512sum of the path on the remote host, or None if an error occurred.

Return type

str

simple_automation.transactions.utils.remote_stat(context, path)

Runs stat on the given remote path.

Parameters
  • context (Context) – The host execution context

  • path (str) – The path to run stat on.

Returns

A tuple of (file_type, str_octal_mode, owner, group), where file_type is one of [“file”, “directory”, “link”, “other”]

Return type

(str, str, str, str)

simple_automation.transactions.utils.remote_upload(context: simple_automation.context.Context, get_content, title: str, name: str, dst: str, mode=None, owner=None, group=None)

Calls get_content and saves the resulting string as a file on the remote host at dst. No arguments will be templated, this is task of the calling function. Optionally accepts file mode, owner and group, if not given, context defaults are used.

Parameters
  • context (Context) – The host execution context

  • get_content (Callable[[],str]) – A function that is called to get the content that should be uploaded.

  • title (str) – The title for the generated transaction

  • name (str) – The name for the generated transaction

  • dst (str) – The remote destination for the uplaoded file

  • mode (int, optional) – The new file mode. Defaults the current context file creation mode.

  • owner (str, optional) – The new file owner. Defaults the current context owner.

  • group (str, optional) – The new file group. Defaults the current context group.

Returns

The completed transaction

Return type

CompletedTransaction

simple_automation.transactions.utils.resolve_mode_owner_group(context: simple_automation.context.Context, mode, owner, group, fallback_mode)

Canonicalize mode, owner and group. If any of them is None, the respective variable will be replaced with the context default.

Parameters
  • context (Context) – The host execution context

  • mode (int) – The mode to canonicalize. May be None.

  • owner (str) – User id or name for the owner. User will be verified as existing on the remote.

  • group (str) – Group id or name for the group. Group will be verified as existing on the remote.

  • fallback_mode (int) – The fallback_mode to canonicalize in case mode = None. Usually set to either context.file_mode or context.dir_mode.

Returns

A tuple of (resolved_mode, resolved_owner, resolved_group)

Return type

(str, str, str)

simple_automation.transactions.utils.template_str(context: simple_automation.context.Context, content: str)str

Renders the given string template.

Parameters
  • context (Context) – The context providing the templating dictionary

  • content (str) – The string to template

Returns

The templated string

Return type

str