sirup.TemporaryFileWithRootPermission

Classes

TemporaryFileWithRootPermission

Temporary file that requires root permission.

Module Contents

class sirup.TemporaryFileWithRootPermission.TemporaryFileWithRootPermission(password, suffix=None)[source]

Temporary file that requires root permission. The purpose of this class is to handle files that the OpenVPN command-line interface (CLI) writes to. Because the CLI works with root permission, the files it writes to also require root permission, and can for instance only be removed with root permission.

When used as a context manager, a random file name in a temporary directory is generated, which can then be used like normal file. Upon __exit__, the file is deleted.

When used without a context manager, the create_path method needs to be called to generate the file name. The filename can be passed on to other tasks, like the openvpn subprocesses. To remove the file one needs to call self.remove.

Parameters:
  • passsword (str) – Password for the user with root access.

  • suffix (str, optional) – suffix to be appended after the random file name.

__enter__()[source]
create_path(file_name)[source]

Create the full path to a new file in the temp directory. Remove any existing file with the same name.

Parameters:

file_name (str) – name of the file in the temp directory.

remove()[source]

Remove the file.

__exit__(exc_type, exc_val, exc_tb)[source]