filesystem operations

class reemote.operations.filesystem.directory.Directory(path: str, present: bool)[source]

Bases: object

A class to encapsulate idempotent operations on a directory in Unix-like operating systems.

path

The directory path to create or remove.

Type:

str

attrs

asyncssh SFTPAttrs object for directory attributes.

Type:

str

present

Whether the directory should exist or not.

Type:

bool

Examples:

yield Directory(
    path='/home/user/hfs',
    present=True,
    attrs=asyncssh.SFTPAttrs(),
)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

Notes

If hosts is None or empty, the operation will execute on the current host.

class reemote.operations.filesystem.chown.Chown(path: str, owner: str, group: str, sudo: bool = False, su: bool = False)[source]

Bases: object

A class to implement chown operations on a directory in Unix-like operating systems.

This class provides functionality to change the ownership of files or directories on remote systems. It handles both regular Unix systems and Alpine Linux specially.

path

The file or directory path to change ownership.

Type:

str

owner

The new owner of the file or directory.

Type:

str

group

The new group of the file or directory.

Type:

str

sudo

If True, the commands will be executed with sudo privileges.

Type:

bool

su

If True, the commands will be executed with su privileges.

Type:

bool

Examples:

# Change ownership of a directory
r = yield Chown("/var/www", "www-data", "www-data", sudo=True)
# The ownership change is applied on all hosts
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

Notes

  • Uses a temporary shell script approach to execute the chown command.

  • Handles Alpine Linux differently by using sh -c instead of bash.

  • Automatically cleans up the temporary script after execution.

  • Requires sftp capabilities for file operations.