file
#
Description#
A plugin for general-purpose file methods
Configuration#
file:
# No configuration required
Actions#
Module reference#
- class platypush.plugins.file.FilePlugin(**kwargs)[source]#
Bases:
Plugin
A plugin for general-purpose file methods
- __init__(**kwargs)#
- append(file: str, content)[source]#
Append content to a specified (text) file.
- Parameters:
file – Path of the file.
content – Content to write.
- chmod(file: str, mode)[source]#
Change the mode/permissions of a file.
- Parameters:
file – File name/path.
mode – New file permissions.
- link(file: str, target: str, symbolic=True)[source]#
Create a link to a file.
- Parameters:
file – File to symlink.
target – Symlink path.
symbolic – If True, then the target link will be a symbolic link. Otherwise, it will be a hard link (default: symbolic).
- list(path: str | None = None) List[Dict[str, str]] [source]#
List a file or all the files in a directory.
- Parameters:
path – File or directory (default: root directory).
- Returns:
List of files in the specified path, or absolute path of the specified path if
path
is a file and it exists. Each item will contain the fieldstype
(file
ordirectory
) andpath
.
- mkdir(directory: str, exist_ok=True, parents=True, mode=493)[source]#
Create a directory.
- Parameters:
directory – Directory name/path.
exist_ok – If set and the directory already exist the method will not return an error (default: True).
parents – If set and any of the parent directories in the path don’t exist they will be created (analogous to mkdir -p) (default: True).
mode – Access mode (default: 0755).
- read(file: str)[source]#
Read and return the content of a (text) file.
Note that this method should only be used for small text files, as it reads the entire file in memory.
If you need to read large/binary files, consider using the
GET /file?path=<path>
HTTP API endpoint instead.- Parameters:
file – Path of the file.
- rename(file: str, name: str)[source]#
Rename/move a file.
- Parameters:
file – File to rename.
name – New file name.
- rmdir(directory: str)[source]#
Remove a directory. The directory must be empty.
- Parameters:
directory – Directory name/path.