aiida.transports.plugins package#

Plugins for the transport.

Submodules#

Local transport

class aiida.transports.plugins.local.LocalTransport(*args, **kwargs)[源代码]#

基类:Transport

Support copy and command execution on the same host on which AiiDA is running via direct file copy and execution commands.

Note that the environment variables are copied from the submitting process, so you might need to clean it with a prepend_text. For example, the AiiDA daemon sets a PYTHONPATH, so you might want to add unset PYTHONPATH if you plan on running calculations that use Python.

DEFAULT_MINIMUM_JOB_POLL_INTERVAL = 0.1#
_DEFAULT_SAFE_OPEN_INTERVAL = 0.0#
__abstractmethods__ = frozenset({})#
__init__(*args, **kwargs)[源代码]#

__init__ method of the Transport base class.

参数:
  • safe_interval – (optional, default self._DEFAULT_SAFE_OPEN_INTERVAL) Minimum time interval in seconds between opening new connections.

  • use_login_shell – (optional, default True) if False, do not use a login shell when executing command

__module__ = 'aiida.transports.plugins.local'#
__str__()[源代码]#

Return a description as a string.

_abc_impl = <_abc._abc_data object>#
_exec_command_internal(command, **kwargs)[源代码]#

Executes the specified command in bash login shell.

Before the command is executed, changes directory to the current working directory as returned by self.getcwd().

For executing commands and waiting for them to finish, use exec_command_wait. Otherwise, to end the process, use the proc.wait() method.

The subprocess is set to have a different process group than the main process, so that it is shielded from signals sent to the parent.

参数:

command – the command to execute. The command is assumed to be already escaped using aiida.common.escaping.escape_for_bash().

返回:

a tuple with (stdin, stdout, stderr, proc), where stdin, stdout and stderr behave as file-like objects, proc is the process object as returned by the subprocess.Popen() class.

_local_listdir(path, pattern=None)[源代码]#

Act on the local folder, for the rest, same as listdir.

static _os_path_split_asunder(path)[源代码]#

Used by makedirs, Takes path (a str) and returns a list deconcatenating the path.

_valid_auth_options: list = []#
chdir(path)[源代码]#

Changes directory to path, emulated internally. :param path: path to cd into :raise OSError: if the directory does not have read attributes.

chmod(path, mode)[源代码]#

Changes permission bits of object at path :param path: path to modify :param mode: permission bits

抛出:

IOError – if path does not exist.

chown(path, uid, gid)[源代码]#

Change the owner (uid) and group (gid) of a file. As with python’s os.chown function, you must pass both arguments, so if you only want to change one, use stat first to retrieve the current owner and group.

参数:
  • path (str) – path to the file to change the owner and group of

  • uid (int) – new owner’s uid

  • gid (int) – new group id

close()[源代码]#

Closes the local transport channel

抛出:

aiida.common.InvalidOperation – if the channel is already open

copy(remotesource, remotedestination, dereference=False, recursive=True)[源代码]#

Copies a file or a folder from ‘remote’ remotesource to ‘remote’ remotedestination. Automatically redirects to copyfile or copytree.

参数:
  • remotesource – path to local file

  • remotedestination – path to remote file

  • dereference – follow symbolic links. Default = False

  • recursive (bool) – if True copy directories recursively, otherwise only copy the specified file(s)

抛出:
  • ValueError – if ‘remote’ remotesource or remotedestinationis not valid

  • OSError – if remotesource does not exist

copyfile(remotesource, remotedestination, dereference=False)[源代码]#

Copies a file from ‘remote’ remotesource to ‘remote’ remotedestination.

参数:
  • remotesource – path to local file

  • remotedestination – path to remote file

  • dereference (bool) – if True copy the contents of any symlinks found, otherwise copy the symlinks themselves

抛出:
  • ValueError – if ‘remote’ remotesource or remotedestination is not valid

  • OSError – if remotesource does not exist

copytree(remotesource, remotedestination, dereference=False)[源代码]#

Copies a folder from ‘remote’ remotesource to ‘remote’ remotedestination.

参数:
  • remotesource – path to local file

  • remotedestination – path to remote file

  • dereference – follow symbolic links. Default = False

抛出:
  • ValueError – if ‘remote’ remotesource or remotedestination is not valid

  • OSError – if remotesource does not exist

property curdir#

Returns the _internal_dir, if the channel is open. If possible, use getcwd() instead!

exec_command_wait_bytes(command, stdin=None, **kwargs)[源代码]#

Executes the specified command and waits for it to finish.

参数:

command – the command to execute

返回:

a tuple with (return_value, stdout, stderr) where stdout and stderr are both bytes and the return_value is an int.

get(remotepath, localpath, *args, **kwargs)[源代码]#

Copies a folder or a file recursively from ‘remote’ remotepath to ‘local’ localpath. Automatically redirects to getfile or gettree.

参数:
  • remotepath – path to local file

  • localpath – absolute path to remote file

  • dereference – follow symbolic links default = True

  • overwrite – if True overwrites localpath default = False

抛出:
  • IOError – if ‘remote’ remotepath is not valid

  • ValueError – if ‘local’ localpath is not valid

get_attribute(path)[源代码]#

Returns an object FileAttribute, as specified in aiida.transports. :param path: the path of the given file.

getcwd()[源代码]#

Returns the current working directory, emulated by the transport

getfile(remotepath, localpath, *args, **kwargs)[源代码]#

Copies a file recursively from ‘remote’ remotepath to ‘local’ localpath.

参数:
  • remotepath – path to local file

  • localpath – absolute path to remote file

  • overwrite – if True overwrites localpath. Default = False

:raise IOError if ‘remote’ remotepath is not valid or not found :raise ValueError: if ‘local’ localpath is not valid :raise OSError: if unintentionally overwriting

gettree(remotepath, localpath, *args, **kwargs)[源代码]#

Copies a folder recursively from ‘remote’ remotepath to ‘local’ localpath.

参数:
  • remotepath – path to local file

  • localpath – absolute path to remote file

  • dereference – follow symbolic links. Default = True

  • overwrite – if True overwrites localpath. Default = False

抛出:
  • IOError – if ‘remote’ remotepath is not valid

  • ValueError – if ‘local’ localpath is not valid

  • OSError – if unintentionally overwriting

gotocomputer_command(remotedir)[源代码]#

Return a string to be run using os.system in order to connect via the transport to the remote directory.

Expected behaviors:

  • A new bash session is opened

  • A reasonable error message is produced if the folder does not exist

参数:

remotedir (str) – the full path of the remote directory

isdir(path)[源代码]#

Checks if ‘path’ is a directory. :return: a boolean

isfile(path)[源代码]#

Checks if object at path is a file. Returns a boolean.

listdir(path='.', pattern=None)[源代码]#
返回:

a list containing the names of the entries in the directory.

参数:
  • path – default =’.’

  • pattern – if set, returns the list of files matching pattern. Unix only. (Use to emulate ls * for example)

makedirs(path, ignore_existing=False)[源代码]#

Super-mkdir; create a leaf directory and all intermediate ones. Works like mkdir, except that any intermediate path segment (not just the rightmost) will be created if it does not exist.

参数:
  • path – directory to create

  • ignore_existing – if set to true, it doesn’t give any error if the leaf directory does already exist

抛出:

OSError – If the directory already exists and is not ignore_existing

mkdir(path, ignore_existing=False)[源代码]#

Create a folder (directory) named path.

参数:
  • path – name of the folder to create

  • ignore_existing – if True, does not give any error if the directory already exists

抛出:

OSError – If the directory already exists.

normalize(path='.')[源代码]#

Normalizes path, eliminating double slashes, etc.. :param path: path to normalize

open()[源代码]#

Opens a local transport channel

抛出:

aiida.common.InvalidOperation – if the channel is already open

path_exists(path)[源代码]#

Check if path exists

put(localpath, remotepath, *args, **kwargs)[源代码]#

Copies a file or a folder from localpath to remotepath. Automatically redirects to putfile or puttree.

参数:
  • localpath – absolute path to local file

  • remotepath – path to remote file

  • dereference – if True follows symbolic links. Default = True

  • overwrite – if True overwrites remotepath. Default = False

抛出:
putfile(localpath, remotepath, *args, **kwargs)[源代码]#

Copies a file from localpath to remotepath. Automatically redirects to putfile or puttree.

参数:
  • localpath – absolute path to local file

  • remotepath – path to remote file

  • overwrite – if True overwrites remotepath Default = False

抛出:
  • IOError – if remotepath is not valid

  • ValueError – if localpath is not valid

  • OSError – if localpath does not exist

puttree(localpath, remotepath, *args, **kwargs)[源代码]#

Copies a folder recursively from localpath to remotepath. Automatically redirects to putfile or puttree.

参数:
  • localpath – absolute path to local file

  • remotepath – path to remote file

  • dereference – follow symbolic links. Default = True

  • overwrite – if True overwrites remotepath. Default = False

抛出:
  • IOError – if remotepath is not valid

  • ValueError – if localpath is not valid

  • OSError – if localpath does not exist

remove(path)[源代码]#

Removes a file at position path.

rename(oldpath, newpath)[源代码]#

Rename a file or folder from oldpath to newpath.

参数:
  • oldpath (str) – existing name of the file or folder

  • newpath (str) – new name for the file or folder

抛出:
  • IOError – if src/dst is not found

  • ValueError – if src/dst is not a valid string

rmdir(path)[源代码]#

Removes a folder at location path. :param path: path to remove

rmtree(path)[源代码]#

Remove tree as rm -r would do

参数:

path – a string to path

Create a symbolic link between the remote source and the remote remotedestination

参数:
  • remotesource – remote source. Can contain a pattern.

  • remotedestination – remote destination

Plugin for transport over SSH (and SFTP for file transfer).

class aiida.transports.plugins.ssh.SshTransport(*args, **kwargs)[源代码]#

基类:Transport

Support connection, command execution and data transfer to remote computers via SSH+SFTP.

_MAX_EXEC_COMMAND_LOG_SIZE = None#
__abstractmethods__ = frozenset({})#
__init__(*args, **kwargs)[源代码]#

Initialize the SshTransport class.

参数:
  • machine – the machine to connect to

  • load_system_host_keys – (optional, default False) if False, do not load the system host keys

  • key_policy – (optional, default = paramiko.RejectPolicy()) the policy to use for unknown keys

Other parameters valid for the ssh connect function (see the self._valid_connect_params list) are passed to the connect function (as port, username, password, …); taken from the accepted paramiko.SSHClient.connect() params.

__module__ = 'aiida.transports.plugins.ssh'#
__str__()[源代码]#

Return a useful string.

_abc_impl = <_abc._abc_data object>#
_close_proxies()[源代码]#

Close all proxy connections (proxy_jump and proxy_command)

_exec_command_internal(command, combine_stderr=False, bufsize=-1)[源代码]#

Executes the specified command in bash login shell.

Before the command is executed, changes directory to the current working directory as returned by self.getcwd().

For executing commands and waiting for them to finish, use exec_command_wait.

参数:
  • command – the command to execute. The command is assumed to be already escaped using aiida.common.escaping.escape_for_bash().

  • combine_stderr – (default False) if True, combine stdout and stderr on the same buffer (i.e., stdout). Note: If combine_stderr is True, stderr will always be empty.

  • bufsize – same meaning of the one used by paramiko.

返回:

a tuple with (stdin, stdout, stderr, channel), where stdin, stdout and stderr behave as file-like objects, plus the methods provided by paramiko, and channel is a paramiko.Channel object.

_exec_cp(cp_exe, cp_flags, src, dst)[源代码]#

Execute the cp command on the remote machine.

classmethod _get_allow_agent_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_compress_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_gss_auth_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_gss_deleg_creds_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_gss_host_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_gss_kex_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_key_filename_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_key_policy_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_load_system_host_keys_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_look_for_keys_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_port_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_proxy_command_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

classmethod _get_proxy_jump_suggestion_string(_)[源代码]#

Return an empty suggestion since Paramiko does not parse ProxyJump from the SSH config.

classmethod _get_timeout_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

Provide 60s as a default timeout for connections.

classmethod _get_username_suggestion_string(computer)[源代码]#

Return a suggestion for the specific field.

static _local_listdir(path, pattern=None)[源代码]#

Acts on the local folder, for the rest, same as listdir

static _os_path_split_asunder(path)[源代码]#

Used by makedirs. Takes path (a str) and returns a list deconcatenating the path

Wrap SFTP symlink call without breaking API

参数:
  • source – source of link

  • dest – link to create

_valid_auth_options: list = [('username', {'help': 'Login user name on the remote machine.', 'non_interactive_default': True, 'prompt': 'User name'}), ('port', {'non_interactive_default': True, 'option': <aiida.cmdline.params.options.overridable.OverridableOption object>, 'prompt': 'Port number'}), ('look_for_keys', {'default': True, 'help': 'Automatically look for private keys in the ~/.ssh folder.', 'non_interactive_default': True, 'prompt': 'Look for keys', 'switch': True}), ('key_filename', {'help': 'Absolute path to your private SSH key. Leave empty to use the path set in the SSH config.', 'non_interactive_default': True, 'prompt': 'SSH key file', 'type': ABSOLUTEPATHEMPTY}), ('timeout', {'help': 'Time in seconds to wait for connection before giving up. Leave empty to use default value.', 'non_interactive_default': True, 'prompt': 'Connection timeout in s', 'type': <class 'int'>}), ('allow_agent', {'default': False, 'help': 'Switch to allow or disallow using an SSH agent.', 'non_interactive_default': True, 'prompt': 'Allow ssh agent', 'switch': True}), ('proxy_jump', {'help': 'SSH proxy jump for tunneling through other SSH hosts. Use a comma-separated list of hosts of the form [user@]host[:port]. If user or port are not specified for a host, the user & port values from the target host are used. This option must be provided explicitly and is not parsed from the SSH config file when left empty.', 'non_interactive_default': True, 'prompt': 'SSH proxy jump'}), ('proxy_command', {'help': 'SSH proxy command for tunneling through a proxy server. For tunneling through another SSH host, consider using the "SSH proxy jump" option instead! Leave empty to parse the proxy command from the SSH config file.', 'non_interactive_default': True, 'prompt': 'SSH proxy command'}), ('compress', {'default': True, 'help': 'Turn file transfer compression on or off.', 'non_interactive_default': True, 'prompt': 'Compress file transfers', 'switch': True}), ('gss_auth', {'default': False, 'help': 'Enable when using GSS kerberos token to connect.', 'non_interactive_default': True, 'prompt': 'GSS auth', 'type': <class 'bool'>}), ('gss_kex', {'default': False, 'help': 'GSS kex for kerberos, if not configured in SSH config file.', 'non_interactive_default': True, 'prompt': 'GSS kex', 'type': <class 'bool'>}), ('gss_deleg_creds', {'default': False, 'help': 'GSS deleg_creds for kerberos, if not configured in SSH config file.', 'non_interactive_default': True, 'prompt': 'GSS deleg_creds', 'type': <class 'bool'>}), ('gss_host', {'help': 'GSS host for kerberos, if not configured in SSH config file.', 'non_interactive_default': True, 'prompt': 'GSS host'}), ('load_system_host_keys', {'default': True, 'help': 'Load system host keys from default SSH location.', 'non_interactive_default': True, 'prompt': 'Load system host keys', 'switch': True}), ('key_policy', {'default': 'RejectPolicy', 'help': 'SSH key policy if host is not known.', 'non_interactive_default': True, 'prompt': 'Key policy', 'type': Choice(['RejectPolicy', 'WarningPolicy', 'AutoAddPolicy'])})]#
_valid_connect_options = [('username', {'help': 'Login user name on the remote machine.', 'non_interactive_default': True, 'prompt': 'User name'}), ('port', {'non_interactive_default': True, 'option': <aiida.cmdline.params.options.overridable.OverridableOption object>, 'prompt': 'Port number'}), ('look_for_keys', {'default': True, 'help': 'Automatically look for private keys in the ~/.ssh folder.', 'non_interactive_default': True, 'prompt': 'Look for keys', 'switch': True}), ('key_filename', {'help': 'Absolute path to your private SSH key. Leave empty to use the path set in the SSH config.', 'non_interactive_default': True, 'prompt': 'SSH key file', 'type': ABSOLUTEPATHEMPTY}), ('timeout', {'help': 'Time in seconds to wait for connection before giving up. Leave empty to use default value.', 'non_interactive_default': True, 'prompt': 'Connection timeout in s', 'type': <class 'int'>}), ('allow_agent', {'default': False, 'help': 'Switch to allow or disallow using an SSH agent.', 'non_interactive_default': True, 'prompt': 'Allow ssh agent', 'switch': True}), ('proxy_jump', {'help': 'SSH proxy jump for tunneling through other SSH hosts. Use a comma-separated list of hosts of the form [user@]host[:port]. If user or port are not specified for a host, the user & port values from the target host are used. This option must be provided explicitly and is not parsed from the SSH config file when left empty.', 'non_interactive_default': True, 'prompt': 'SSH proxy jump'}), ('proxy_command', {'help': 'SSH proxy command for tunneling through a proxy server. For tunneling through another SSH host, consider using the "SSH proxy jump" option instead! Leave empty to parse the proxy command from the SSH config file.', 'non_interactive_default': True, 'prompt': 'SSH proxy command'}), ('compress', {'default': True, 'help': 'Turn file transfer compression on or off.', 'non_interactive_default': True, 'prompt': 'Compress file transfers', 'switch': True}), ('gss_auth', {'default': False, 'help': 'Enable when using GSS kerberos token to connect.', 'non_interactive_default': True, 'prompt': 'GSS auth', 'type': <class 'bool'>}), ('gss_kex', {'default': False, 'help': 'GSS kex for kerberos, if not configured in SSH config file.', 'non_interactive_default': True, 'prompt': 'GSS kex', 'type': <class 'bool'>}), ('gss_deleg_creds', {'default': False, 'help': 'GSS deleg_creds for kerberos, if not configured in SSH config file.', 'non_interactive_default': True, 'prompt': 'GSS deleg_creds', 'type': <class 'bool'>}), ('gss_host', {'help': 'GSS host for kerberos, if not configured in SSH config file.', 'non_interactive_default': True, 'prompt': 'GSS host'})]#
_valid_connect_params = ['username', 'port', 'look_for_keys', 'key_filename', 'timeout', 'allow_agent', 'proxy_jump', 'proxy_command', 'compress', 'gss_auth', 'gss_kex', 'gss_deleg_creds', 'gss_host']#
chdir(path)[源代码]#

Change directory of the SFTP session. Emulated internally by paramiko.

Differently from paramiko, if you pass None to chdir, nothing happens and the cwd is unchanged.

chmod(path, mode)[源代码]#

Change permissions to path

参数:
  • path – path to file

  • mode – new permission bits (integer)

chown(path, uid, gid)[源代码]#

Change owner permissions of a file.

For now, this is not implemented for the SSH transport.

close()[源代码]#

Close the SFTP channel, and the SSHClient.

Todo:

correctly manage exceptions

抛出:

aiida.common.InvalidOperation – if the channel is already open

copy(remotesource, remotedestination, dereference=False, recursive=True)[源代码]#

Copy a file or a directory from remote source to remote destination. Flags used: -r: recursive copy; -f: force, makes the command non interactive; -L follows symbolic links

参数:
  • remotesource – file to copy from

  • remotedestination – file to copy to

  • dereference – if True, copy content instead of copying the symlinks only Default = False.

  • recursive (bool) – if True copy directories recursively, otherwise only copy the specified file(s)

抛出:

IOError – if the cp execution failed.

备注

setting dereference equal to True could cause infinite loops.

copyfile(remotesource, remotedestination, dereference=False)[源代码]#

Copy a file from remote source to remote destination (On the same remote machine)

参数:
  • remotesource (str) – path of the remote source directory / file

  • remotedestination (str) – path of the remote destination directory / file

  • dereference (bool) – if True copy the contents of any symlinks found, otherwise copy the symlinks themselves

抛出:

IOError – if one of src or dst does not exist

copytree(remotesource, remotedestination, dereference=False)[源代码]#

Copy a folder from remote source to remote destination (On the same remote machine)

参数:
  • remotesource (str) – path of the remote source directory / file

  • remotedestination (str) – path of the remote destination directory / file

  • dereference (bool) – if True copy the contents of any symlinks found, otherwise copy the symlinks themselves

抛出:

IOError – if one of src or dst does not exist

exec_command_wait_bytes(command, stdin=None, combine_stderr=False, bufsize=-1)[源代码]#

Executes the specified command and waits for it to finish.

参数:
  • command – the command to execute

  • stdin – (optional,default=None) can be a string or a file-like object.

  • combine_stderr – (optional, default=False) see docstring of self._exec_command_internal()

  • bufsize – same meaning of paramiko.

返回:

a tuple with (return_value, stdout, stderr) where stdout and stderr are both bytes and the return_value is an int.

get(remotepath, localpath, callback=None, dereference=True, overwrite=True, ignore_nonexisting=False)[源代码]#

Get a file or folder from remote to local. Redirects to getfile or gettree.

参数:
  • remotepath – a remote path

  • localpath – an (absolute) local path

  • dereference – follow symbolic links. Default = True (default behaviour in paramiko). False is not implemented.

  • overwrite – if True overwrites files and folders. Default = False

抛出:
get_attribute(path)[源代码]#

Returns the object Fileattribute, specified in aiida.transports Receives in input the path of a given file.

getcwd()[源代码]#

Return the current working directory for this SFTP session, as emulated by paramiko. If no directory has been set with chdir, this method will return None. But in __enter__ this is set explicitly, so this should never happen within this class.

getfile(remotepath, localpath, callback=None, dereference=True, overwrite=True)[源代码]#

Get a file from remote to local.

参数:
  • remotepath – a remote path

  • localpath – an (absolute) local path

  • overwrite – if True overwrites files and folders. Default = False

抛出:
gettree(remotepath, localpath, callback=None, dereference=True, overwrite=True)[源代码]#

Get a folder recursively from remote to local.

参数:
  • remotepath – a remote path

  • localpath – an (absolute) local path

  • dereference – follow symbolic links. Default = True (default behaviour in paramiko). False is not implemented.

  • overwrite – if True overwrites files and folders. Default = False

抛出:
  • ValueError – if local path is invalid

  • IOError – if the remotepath is not found

  • OSError – if unintentionally overwriting

gotocomputer_command(remotedir)[源代码]#

Specific gotocomputer string to connect to a given remote computer via ssh and directly go to the calculation folder.

isdir(path)[源代码]#

Return True if the given path is a directory, False otherwise. Return False also if the path does not exist.

isfile(path)[源代码]#

Return True if the given path is a file, False otherwise. Return False also if the path does not exist.

listdir(path='.', pattern=None)[源代码]#

Get the list of files at path.

参数:
  • path – default = ‘.’

  • pattern – returns the list of files matching pattern. Unix only. (Use to emulate ls * for example)

lstat(path)[源代码]#

Retrieve information about a file on the remote system, without following symbolic links (shortcuts). This otherwise behaves exactly the same as stat.

参数:

path (str) – the filename to stat

返回:

a paramiko.sftp_attr.SFTPAttributes object containing attributes about the given file.

makedirs(path, ignore_existing=False)[源代码]#

Super-mkdir; create a leaf directory and all intermediate ones. Works like mkdir, except that any intermediate path segment (not just the rightmost) will be created if it does not exist.

NOTE: since os.path.split uses the separators as the host system (that could be windows), I assume the remote computer is Linux-based and use ‘/’ as separators!

参数:
  • path – directory to create (string)

  • ignore_existing – if set to true, it doesn’t give any error if the leaf directory does already exist (bool)

抛出:

OSError – If the directory already exists.

mkdir(path, ignore_existing=False)[源代码]#

Create a folder (directory) named path.

参数:
  • path – name of the folder to create

  • ignore_existing – if True, does not give any error if the directory already exists

抛出:

OSError – If the directory already exists.

normalize(path='.')[源代码]#

Returns the normalized path (removing double slashes, etc…)

open()[源代码]#

Open a SSHClient to the machine possibly using the parameters given in the __init__.

Also opens a sftp channel, ready to be used. The current working directory is set explicitly, so it is not None.

抛出:

aiida.common.InvalidOperation – if the channel is already open

path_exists(path)[源代码]#

Check if path exists

put(localpath, remotepath, callback=None, dereference=True, overwrite=True, ignore_nonexisting=False)[源代码]#

Put a file or a folder from local to remote. Redirects to putfile or puttree.

参数:
  • localpath – an (absolute) local path

  • remotepath – a remote path

  • dereference – follow symbolic links (boolean). Default = True (default behaviour in paramiko). False is not implemented.

  • overwrite – if True overwrites files and folders (boolean). Default = False.

抛出:
  • ValueError – if local path is invalid

  • OSError – if the localpath does not exist

putfile(localpath, remotepath, callback=None, dereference=True, overwrite=True)[源代码]#

Put a file from local to remote.

参数:
  • localpath – an (absolute) local path

  • remotepath – a remote path

  • overwrite – if True overwrites files and folders (boolean). Default = True.

抛出:
  • ValueError – if local path is invalid

  • OSError – if the localpath does not exist, or unintentionally overwriting

puttree(localpath, remotepath, callback=None, dereference=True, overwrite=True)[源代码]#

Put a folder recursively from local to remote.

By default, overwrite.

参数:
  • localpath – an (absolute) local path

  • remotepath – a remote path

  • dereference – follow symbolic links (boolean) Default = True (default behaviour in paramiko). False is not implemented.

  • overwrite – if True overwrites files and folders (boolean). Default = True

抛出:
  • ValueError – if local path is invalid

  • OSError – if the localpath does not exist, or trying to overwrite

  • IOError – if remotepath is invalid

备注

setting dereference equal to True could cause infinite loops. see os.walk() documentation

remove(path)[源代码]#

Remove a single file at ‘path’

rename(oldpath, newpath)[源代码]#

Rename a file or folder from oldpath to newpath.

参数:
  • oldpath (str) – existing name of the file or folder

  • newpath (str) – new name for the file or folder

抛出:
  • IOError – if oldpath/newpath is not found

  • ValueError – if sroldpathc/newpath is not a valid string

rmdir(path)[源代码]#

Remove the folder named ‘path’ if empty.

rmtree(path)[源代码]#

Remove a file or a directory at path, recursively Flags used: -r: recursive copy; -f: force, makes the command non interactive;

参数:

path – remote path to delete

抛出:

IOError – if the rm execution failed.

property sftp#
property sshclient#
stat(path)[源代码]#

Retrieve information about a file on the remote system. The return value is an object whose attributes correspond to the attributes of Python’s stat structure as returned by os.stat, except that it contains fewer fields. The fields supported are: st_mode, st_size, st_uid, st_gid, st_atime, and st_mtime.

参数:

path (str) – the filename to stat

返回:

a paramiko.sftp_attr.SFTPAttributes object containing attributes about the given file.

Create a symbolic link between the remote source and the remote destination.

参数:
  • remotesource – remote source. Can contain a pattern.

  • remotedestination – remote destination

aiida.transports.plugins.ssh.convert_to_bool(string)[源代码]#

Convert a string passed in the CLI to a valid bool.

返回:

the parsed bool value.

抛出:

ValueError – If the value is not parsable as a bool

aiida.transports.plugins.ssh.parse_sshconfig(computername)[源代码]#

Return the ssh configuration for a given computer name.

This parses the .ssh/config file in the home directory and returns the part of configuration of the given computer name.

参数:

computername – the computer name for which we want the configuration.