helperFunctions.install module
- exception helperFunctions.install.InstallationError
Bases:
ExceptionClass representing all expected errors that happen during installation, such as timeouts on remote hosts.
- class helperFunctions.install.OperateInDirectory(target_directory, remove=False)
Bases:
objectContext 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.
- Return type:
str
- helperFunctions.install.apt_remove_packages(*packages)
Remove packages from Ubuntu / Debian / Mint / Kali systems.
- Parameters:
packages (str) – Iterable containing packages to remove.
- Return type:
str
- helperFunctions.install.apt_update_sources()
Update package lists on Ubuntu / Debian / Mint / Kali systems.
- Return type:
str
- helperFunctions.install.check_distribution(allow_unsupported=False)
Check if the distribution is supported by the installer.
- Returns:
The codename of the distribution
- Parameters:
allow_unsupported (bool) –
- Return type:
str
- 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.
- Return type:
str
- helperFunctions.install.dnf_remove_packages(*packages)
Remove packages from Fedora / RedHat / Cent systems.
- Parameters:
packages (str) – Iterable containing packages to remove.
- Return type:
str
- helperFunctions.install.dnf_update_sources()
Update package lists on Fedora / RedHat / Cent systems.
- Return type:
str
- helperFunctions.install.install_github_project(project_path, commands)
Install GitHub project by cloning it, running a set of commands and removing the cloned files afterward.
- 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'] )
- Return type:
None
- 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.
- Return type:
None
- helperFunctions.install.install_single_pip_package(package)
- Parameters:
package (str) –
- Return type:
None
- 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 (Iterable[str]) – List of packages that are affected.
install (bool) – Identifier to distinguish installation from removal.
- Return type:
None
- 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.
- Return type:
list[str]
- 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.
- Return type:
None
- 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 return code. All keyword arguments are except raise_error passed to subprocess.run.
- Parameters:
cmd (str) – the command to execute.
shell (bool) – execute the command through the shell.
raise_error (bool) – Whether or not an error should be raised when cmd fails
silent (bool) – don’t log in case of error.
- Return type:
None