materials_commons.cli.globus module

class materials_commons.cli.globus.GlobusOperations(local_endpoint_id=None, transfer_client=None, verbose=True)[source]

Bases: object

Used to perform Globus operations

local_endpoint_id: str or None

ID of local endpoint. If None provided, will attempt to get from local Globus connect personal, or user config file. If not found, will exit with message.

transfer_client: globus_sdk.TransferClient or None

Globus TransferClient instance. If None provided, will attempt to construct from user config or will prompt user to login to obtain a refresh token which will then be saved into the user’s config file.

verbose: bool (optional, default=True)

Print messages detailing individual steps.

create_all_directories_on_path(path, endpoint_id, endpoint_path)[source]

Create all directories on path at upload endpoint

Parameters
  • path – str, Relative path inside project to a directory (excludes project directory)

  • endpoint_id – str, Endpoint ID

  • endpoint_path – str, Path to project directory on endpoint. Will create all directories on endpoint for endpoint_path/path

download_v0(proj, paths, download, working_dir, recursive=False, label=None, localtree=None, remotetree=None, force=False)[source]

Download files and directories from project

Parameters
  • proj – Project

  • paths – list of str, Materials Commons paths (absolute path, not including project name directory)

  • download – mcapi.GlobusDownload, Globus download request

  • working_dir (str) – Current working directory, used for finding relative paths and printing messages.

  • recursive – bool, If True, download directories recursively

  • label – str, Globus transfer label to make finding tasks simpler

  • force – bool, If True force download even if local file exists

Returns

None or task_id – str, transfer task id. Returns nothing to transfer.

upload_v0(proj, paths, upload, working_dir, recursive=False, label=None, localtree=None, remotetree=None)[source]

Upload files and directories to project

Parameters
  • proj – Project

  • paths – list of str, Materials Commons paths (include project directory)

  • upload – mcapi.GlobusUpload, Globus upload request

  • working_dir (str) – Current working directory, used for finding relative paths and printing messages.

  • recursive – bool, If True, upload directories recursively

  • label – str, Globus transfer label to make finding tasks simpler

Returns

None or task_id – str, transfer task id. Returns nothing to transfer.

materials_commons.cli.globus.check_transfer_types(source_type, target_type, recursive, verbose, printpath)[source]

Check if source and target types are valid

Parameters
  • source_type – ‘file’, ‘directory’, or None

  • target_type – ‘file’, ‘directory’, or None

  • recursive (bool) – If True, upload directories recursively

  • verbose (bool) – If True, print error messages

  • printpath (str) – If verbose==True, print error messages referring using this path.

Returns

True if transfer may proceed, False if transfer may not proceed

materials_commons.cli.globus.get_local_endpoint_id()[source]

Get the local endpoint id

Checks for a local Globus connect personal, if not found checks user config for globus.endpoint_id.

local_endpoint_id: str or None if not found

materials_commons.cli.globus.get_local_endpoint_id_or_exit()[source]

Get the local endpoint id

materials_commons.cli.globus.get_transfer_rt_or_login()[source]

Get the Globus transfer refresh token, prompting for login if necessary

If not yet configured, will prompt user to login and enter a code used to obtain the refresh token. Once obtained the token will be saved into the user’s config file so future login is unnecessary.

transfer_rt: str, Globus transfer refresh token for authentication

materials_commons.cli.globus.make_transfer_client(transfer_rt)[source]

Make a Globus TransferClient

transfer_rt: str

Globus transfer authentication refresh token. Can be obtained from user’s globus configuration via Config().globus.transfer_rt, and will be None if not configured. To obtain from configuration or prompt user to login, use get_transfer_rt_or_login.

transfer_client: globus_sdk.TransferClient