SSHPath

class hep_rfm.SSHPath(path)[source]

Bases: hep_rfm.protocols.RemotePath

Represent a path to be handled using SSH.

Parameters:path (str) – path to save, pointing to a file.

Attributes Summary

pid

Methods Summary

copy(target) Copy the source file to the target using this protocol.
join_path(prefix, path) Policy to merge a prefix and a path in this protocol.
mkdirs() Make directories to the file path within this protocol.
specify_server([server_spec]) Process the given path and return a modified version of it adding the correct user name.
split_path() Split the remote path in the server specifications and path in the server.
with_modifiers([modifiers]) Return an instance of this class after applying modifications.

Attributes Documentation

pid = 'ssh'

Methods Documentation

copy(target)[source]

Copy the source file to the target using this protocol. The target must be accessible.

Parameters:
Raises:

CopyFileError – if a problem appears while copying the file.

static join_path(prefix, path)[source]

Policy to merge a prefix and a path in this protocol.

Parameters:
  • prefix (str) – prefix to add to the current path.
  • path (str) – path to the file in the remote.
Returns:

result of joining the prefix and the path for this protocol.

Return type:

str

mkdirs()[source]

Make directories to the file path within this protocol.

Raises:MakeDirsError – if an error occurs while creating directories.
specify_server(server_spec=None)[source]

Process the given path and return a modified version of it adding the correct user name. The user name for each host must be specified in server_spec.

Parameters:
  • path (str) – path to a file.
  • server_spec (dict) – specification of user for each SSH server. Must be specified as a dictionary, where the keys are the hosts and the values are the user names.
Returns:

modified version of “path”.

Return type:

str

Raises:

RuntimeError – if there is no way to determine the user name for the given path.

split_path()[source]

Split the remote path in the server specifications and path in the server.

Returns:server specifications and path in the server.
Return type:str, str
with_modifiers(modifiers=None)[source]

Return an instance of this class after applying modifications. The input dictionary “modifiers” might contain information about the user-name for the host in the stored path. The allowed keys for this dictionary are: - “ssh_hosts”: list containing the hosts accessible from the place where the operation is being done. If the path stored in this class has a host that coincides with any of those here specified, it will return a hep_rfm.LocalPath instance. - “ssh_usernames”: dictionary containing the user-name to use for each host (although only one will be appliable for a given hep_rfm.SSHPath instance). In case the path has already one user-name defined, it will be overwritten.

Parameters:modifiers (dict) – information to modify the path of this class.
Returns:modified instance if a modification is applied. Otherwise same instance.
Return type:ProtocolPath