file#

class platypush.plugins.file.FilePlugin(**kwargs)[source]#

Bases: Plugin

A plugin for general-purpose file methods

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.

getsize(file)[source]#

Get the size of the specified file in bytes.

Parameters:

file – File path.

home() str[source]#

Returns the current user’s home directory.

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 = '/') 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 fields type (file or directory) and path.

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.

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.

touch(file: str, mode=420)[source]#

Create/touch a file.

Parameters:
  • file – File name/path.

  • mode – File permissions (default: 0644).

Remove a file or symbolic link.

Parameters:

file – File/link to remove.

write(file: str, content: str)[source]#

Writes content to a specified (text) file. Previous content will be truncated.

Parameters:
  • file – Path of the file.

  • content – Content to write.