Helper

class jetstream.helper.Helper(api)
Parameters

api – A JetStream API interface, as constructed from api(). This may also be None if using methods that do not require an API connection.

Method Summary

getFileMappings

Builds a file mapping from a list of paths.

getFilteredManifestFiles

Applies the supplied filter to all manifests from the connected API, and returns a list of manifests, each with a list of file mappings that satisfy the filter.

getTransferFlags

Returns the transferFlags appropriate for the desired read/write behavior.

sendFiles

Starts a file transfer and returns a TransferObject.

Method Documentation

static Helper.getFileMappings(fileList, relative_to=None)

Builds a file mapping from a list of paths.

The createManifest() command requires a file mapping which provides one or more source paths, with a target path specified for each. In the case where you are satisfied to replicate the source structure at the destination, the mapping is trivially a 1:1 association. This helper method builds a file mapping of this type.

This method does not require an API connection.

Parameters
  • fileList (tuple, list) – A sequence of file names or paths.

  • relative_to (str) – (optional) If specified, transforms all target paths to be relative to this path. Since the source paths must be absolute paths, this allows the file mapping to maintain a relative directory structure, but without replicating the full directory tree at the receiver.

Returns

A dictionary that maps each source file name/path to an equivalent path at the receiver.

Return type

dict

Helper.getFilteredManifestFiles(predicate)

Applies the supplied filter to all manifests from the connected API, and returns a list of manifests, each with a list of file mappings that satisfy the filter.

This method requires an API connection.

Parameters

predicate – A callable that accepts a File Mapping Structure, and returns True if the file’s manifest should be included in the results.

Returns

Returns a list of Manifest Structure items. Each manifest will supplemented with a fileMappings key which contains a list of File Mapping Structure items for all files matching the specified filter.

Return type

list

static Helper.getTransferFlags(readEnabled=True, writeEnabled=True)

Returns the transferFlags appropriate for the desired read/write behavior.

The createTransfer() command requires a transferFlags value to specify whether reads and/or writes are enabled for the transfer.

This method creates the transferFlags value for you.

This method does not require an API connection.

Parameters
  • readEnabled (bool) – If True, enable reads in the transfer flags.

  • writeEnabled (bool) – If True, enable writes in the transfer flags.

Returns

Returns a value appropriate for the transferFlags parameter

Return type

int

Helper.sendFiles(destinationId, sourcePath, destinationPath=None, userName=None, password=None)

Starts a file transfer and returns a TransferObject.

This starts a file transfer for the specified path, to the specified destination. A new manifest is created for the path, and a new transfer is started for this manifest.

A TransferObject is returned, with which the transfer’s progress can be monitored.

This method requires an API connection.

Parameters
  • destinationId (str, dict) – The destination ID, as returned from createDestination(). Also allowed is the full dict from createDestination(). The destination ID is extracted from the destinationId key.

  • sourcePath – The path to the source file or directory. This file/directory will be copied to the destination.

  • destinationPath – (optional) Specifies a directory that will be created as the parent for all files in the transfer. The manifest paths are respected, and added below this destination path.

  • userName – (optional) User name to authenticate the transfer. The transfer is authenticated by the receiving server.

  • password – (optional) Password to authenticate the transfer. The transfer is authenticated by the receiving server.

Tip

Use getpass.getuser() to auto-fill the userName parameter.

Use getpass.getpass() to prompt for the password parameter interactively.

Returns

TransferObject

Return type

obj