l.s.osutils : module documentation

Part of lp.services

Utilities for doing the sort of thing the os module does.
Function remove_tree Remove the tree at 'path' from disk.
Function set_environ Set the environment variables as specified by new_values.
Function override_environ Override environment variables with the kwarg values.
Function ensure_directory_exists Create 'directory' if it doesn't exist.
Function open_for_writing Open 'filename' for writing, creating directories if necessary.
Function two_stage_kill Kill process 'pid' with SIGTERM. If it doesn't die, SIGKILL it.
Function get_pid_from_file Retrieve the PID from the given file, if it exists, None otherwise.
Function kill_by_pidfile Kill a process identified by the pid stored in a file.
Function remove_if_exists Remove the given file if it exists.
Function write_file Undocumented
Function find_on_path Is 'command' on the executable search path?
Function process_exists Return True if the specified process already exists.
Function _kill_may_race Kill a pid accepting that it may not exist.
def remove_tree(path):
Remove the tree at 'path' from disk.
def set_environ(new_values):
Set the environment variables as specified by new_values.
Returnsa dict of the old values
@contextmanager
def override_environ(**kwargs):
Override environment variables with the kwarg values.

If a value is None, the environment variable is deleted. Variables are restored to their previous state when exiting the context.

def ensure_directory_exists(directory, mode=511):
Create 'directory' if it doesn't exist.
ReturnsTrue if the directory had to be created, False otherwise.
def open_for_writing(filename, mode, dirmode=511):
Open 'filename' for writing, creating directories if necessary.
ParametersfilenameThe path of the file to open.
modeThe mode to open the filename with. Should be 'w', 'a' or something similar. See open for more details. If you pass in a read-only mode (e.g. 'r'), then we'll just accept that and return a read-only file-like object.
dirmodeThe mode to use to create directories, if necessary.
ReturnsA file-like object that can be used to write to 'filename'.
def _kill_may_race(pid, signal_number):
Kill a pid accepting that it may not exist.
def two_stage_kill(pid, poll_interval=0.1, num_polls=50, get_status=True):
Kill process 'pid' with SIGTERM. If it doesn't die, SIGKILL it.
ParameterspidThe pid of the process to kill.
poll_intervalThe polling interval used to check if the process is still around.
num_pollsThe number of polls to do before doing a SIGKILL.
get_statusIf True, collect the process' exit status (which requires it to be a child of the process running this function).
def get_pid_from_file(pidfile_path):
Retrieve the PID from the given file, if it exists, None otherwise.
def kill_by_pidfile(pidfile_path, poll_interval=0.1, num_polls=50):
Kill a process identified by the pid stored in a file.

The pid file is removed from disk.

def remove_if_exists(path):
Remove the given file if it exists.
def write_file(path, content):
Undocumented
def find_on_path(command):
Is 'command' on the executable search path?
def process_exists(pid):
Return True if the specified process already exists.
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.