FileClient¶
- class atomate2.utils.file_client.FileClient(key_filename='~/.ssh/id_rsa', config_filename='~/.ssh/config')[source]¶
Bases:
object
Tool for performing operations on files.
The client is agnostic of whether file operations are happening locally or via SSH. All operations have a
host
parameter that specifies which remote host the operation should be performed on.Note
To use abbreviated host names without user information, the FileClient requires the appropriate configuration to be defined in the ssh config file.
- Parameters:
- connect(host)[source]¶
Connect to a remote host.
- Parameters:
host (str) – A remote host filesystem. Supports using hosts defined in the ssh config file. The host can be specified as either “username@remote_host” or just “remote_host” in which case the username will be inferred from the current user.
- Return type:
None
- get_ssh(host)[source]¶
Get an SSH connection to a host.
- Parameters:
host (str) – A remote host filesystem. Supports using hosts defined in the ssh config file. The host can be specified as either “username@remote_host” or just “remote_host” in which case the username will be inferred from the current user.
- Returns:
An ssh client to the host.
- Return type:
.SSHClient
- get_sftp(host)[source]¶
Get an SFTP connection to a host.
- Parameters:
host (str) – A remote host filesystem. Supports using hosts defined in the ssh config file. The host can be specified as either “username@remote_host” or just “remote_host” in which case the username will be inferred from the current user.
- Returns:
An sftp client to the host.
- Return type:
.SFTPClient
- copy(src_filename, dest_filename, src_host=None, dest_host=None)[source]¶
Copy a file from source to destination.
- gzip(path, host=None, compresslevel=6, force=False)[source]¶
Gzip a file.
- Parameters:
path (str or Path) – Path to a file to gzip.
host (str or None) – A remote file system host on which to perform file operations.
compresslevel (bool) – Level of compression, 1-9. 9 is default for GzipFile, 6 is default for gzip.
force (bool) –
How to handle writing a gzipped file if it already exists. Accepts either a string or bool:
”force” or True: Overwrite gzipped file if it already exists.
”raise” or False: Raise an error if file already exists.
”skip” Skip file if it already exists.
- Return type:
None
- gunzip(path, host=None, force=False)[source]¶
Ungzip a file.
- Parameters:
path (str or Path) – Path to a file to gzip.
host (str or None) – A remote file system host on which to perform file operations.
force (bool) –
How to handle writing a non-gzipped file if it already exists. Accepts either a string or bool:
”force” or True: Overwrite non-gzipped file if it already exists.
”raise” or False: Raise an error if file already exists.
”skip” Skip file if it already exists.
- Return type:
None