helperFunctions.install module
- exception helperFunctions.install.InstallationError
Bases:
Exception
Class representing all expected errors that happen during installation, such as timeouts on remote hosts.
- class helperFunctions.install.OperateInDirectory(target_directory, remove=False)
Bases:
object
Context manager allowing to execute a number of commands in a given directory. On exit, the working directory is changed back to its previous value.
- Parameters:
target_directory (str | Path) – Directory path to use as working directory.
remove (bool) – Optional boolean to indicate if target_directory should be removed on exit.
- helperFunctions.install.apt_install_packages(*packages)
Install packages on Ubuntu / Debian / Mint / Kali systems.
- Parameters:
packages (str) – Iterable containing packages to install.
- helperFunctions.install.apt_remove_packages(*packages)
Remove packages from Ubuntu / Debian / Mint / Kali systems.
- Parameters:
packages (str) – Iterable containing packages to remove.
- helperFunctions.install.apt_update_sources()
Update package lists on Ubuntu / Debian / Mint / Kali systems.
- helperFunctions.install.check_distribution(allow_unsupported=False)
Check if the distribution is supported by the installer.
- Returns:
The codename of the distribution
- helperFunctions.install.check_if_command_in_path(command)
Check if a given command is executable on the current system, i.e. found in systems PATH. Useful to find out if a program is already installed.
- Parameters:
command (str) – Command to check.
- Return type:
bool
- helperFunctions.install.dnf_install_packages(*packages)
Install packages on Fedora / RedHat / Cent systems.
- Parameters:
packages (str) – Iterable containing packages to install.
- helperFunctions.install.dnf_remove_packages(*packages)
Remove packages from Fedora / RedHat / Cent systems.
- Parameters:
packages (str) – Iterable containing packages to remove.
- helperFunctions.install.dnf_update_sources()
Update package lists on Fedora / RedHat / Cent systems.
- helperFunctions.install.install_github_project(project_path, commands)
Install github project by cloning it, running a set of commands and removing the cloned files afterwards.
- Parameters:
project_path (str) – Github path to project. For FACT this is ‘fkie-cad/FACT_core’.
commands (list[str]) – List of commands to run after cloning to install project.
- Example:
install_github_project( 'ghusername/c-style-project', ['./configure', 'make', 'sudo make install'] )
- helperFunctions.install.install_pip_packages(package_file)
Install or upgrade python packages from file package_file using pip. Does not raise an error if the installation fails because the package is already installed through the system’s package manager. The package file should have one package per line (empty lines and comments are allowed).
- Parameters:
package_file (Path) – The path to the package file.
- helperFunctions.install.is_virtualenv()
Check if FACT runs in a virtual environment
- Return type:
bool
- helperFunctions.install.log_current_packages(packages, install=True)
Log which packages are installed or removed.
- Parameters:
packages (tuple[str]) – List of packages that are affected.
install (bool) – Identifier to distinguish installation from removal.
- helperFunctions.install.read_package_list_from_file(path)
Reads the file at path into a list. Each line in the file should be either a comment (starts with #) or a package name. There may not be multiple packages in one line.
- Parameters:
path (Path) – The path to the file.
- Returns:
A list of package names contained in the file.
- helperFunctions.install.remove_folder(folder_name)
Python equivalent to rm -rf. Remove a directory an all included files. If administrative rights are necessary, this effectively falls back to sudo rm -rf.
- Parameters:
folder_name (str) – Path to directory to remove.
- helperFunctions.install.run_cmd_with_logging(cmd, raise_error=True, shell=False, silent=False, **kwargs)
Runs cmd with subprocess.run, logs the command it executes and logs stderr on non-zero returncode. All keyword arguments are except raise_error passed to subprocess.run.
- Parameters:
shell – execute the command through the shell.
raise_error – Whether or not an error should be raised when cmd fails
silent (bool) – don’t log in case of error.
cmd (str) –