Differencesolver¶
This module implements the Difference-Solvers (at the moment there is only the standart DiffSolver) and their resulting data structure DiffLog.
DiffLog |
This class stores the operations that were determined by a Difference-Solver. |
DiffSolver |
This is the abstract base class for difference solvers. |
-
class
differencesolver.
DiffLog
¶ Bases:
object
This class stores the operations that were determined by a Difference-Solver. Furthermore it provides helpers to create such operations and a function that allows multiple interpreters to interprete the operations at the same time.
-
data
¶ Used to store the operations
Type: list
-
_DiffLog__append_data
(operation, profilename, **kwargs)¶ Appends a new operation to
self.data
.Parameters: - operation (str) -- Name of the operation
- profilename (str) -- Name of the profile that is associated with the operation
- **kwargs (dict) -- All further key/value pairs of the operation
-
__init__
()¶ Constructor
-
add_info
(profilename, message)¶ Create an info operation.
Info operations can be used to print out profile information to the user. At the moment this is only evaluated by the
PrintInterpreter
to print out a string like:[profilename]: message
Parameters: - profilename (str) -- The name of the profile that prints the information
- message (str) -- The message to be printed
-
add_link
(symlink, profilename)¶ Create an add-link operation.
Add-link operations indicate that a new link needs to be created. This will be - for example - evaluated by the
ExecuteInterpreter
to create the link in the filesystem and create an entry in the installed file.Parameters: - symlink (dict) -- A dictionary that describes the symbolic link that needs to be created
- profilename (str) -- The name of profile that the link belongs to
-
add_profile
(profilename, parentname=None)¶ Create an add-profile operation.
Add-profile operations indicate that a new profile will be added/installed. This will be - for example - evalutated by the
ExecuteInterpreter
to create a new empty entry in the installed-file.Parameters: - profilename (str) -- The name of the new profile
- parentname (str) -- The name of the parent of the new profile. If
None
it will be treated as a root profile
-
remove_link
(symlink_name, profilename)¶ Create a remove-link operation.
Remove-link operations indicate that a certain link needs to be removed. This will be - for example - evaluated by the
ExecuteInterpreter
to remove the link from the filesystem and the installed file.Parameters: - symlink_name (str) -- The absolute path to the symbolic link
- profilename (str) -- The profile that the link is removed from
-
remove_profile
(profilename)¶ Create a remove-profile operation.
Remove-profile operations indicate that a certain profile will be removed/uninstalled. This will be - for example - evaluated by the
ExecuteInterpreter
to remove the profile in the installed file.Parameters: profilename (str) -- The name of the to be removed profile
-
run_interpreter
(*interpreters)¶ Run a list of
interpreters
for all operations.This function iterates over all operations and evaluates them by feeding them into the given interpreters. Furthermore it initializes the interpreters and feeds them additional "start" and "fin" operations.
Parameters: interpreters (Interpreter) -- A list of interpreters that will interpret the operations
-
update_link
(installed_symlink, new_symlink, profilename)¶ Create an update-link operation.
Update-link operations indicate that a certain link needs to be replaced by a new link. This will be - for example - evaluated by the
ExecuteInterpreter
to remove the old link from the filesystem, create the new link in the filesystem and update the entry of the old link in the installed-file.Parameters: - installed_symlink (dict) -- A dictionary that describes the symbolic link that needs to be replaced
- new_symlink (dict) -- A dictionary that describes the symbolic link that will replace the old link
-
update_parent
(profilename, parentname)¶ Create an update-parent operation.
Update-parent operations indicate that a certain profile will change its parent.
Parameters: - profilename (str) -- The name of the to be updated profile
- parentname (str) -- The name of the new parent of the profile. If
None
it will be a root profile from now on.
-
update_profile
(profilename)¶ Create an update-profile operation.
Update-profile operations indicate that a certain profile will be updated. This will be - for example - evaluated by the
ExecuteInterpreter
to update the changed-date of a profile in the installed file.Parameters: profilename (str) -- The name of the to be updated profile
-
update_script
(enabled, profilename, event_name)¶ Create an update-script operation.
Update-script operations indicate that the onUninstall-script needs to be updated by a new path. This will be evaluated by the
ExecuteInterpreter
to update the entry of the old script in the installed-file.Parameters: - enabled (bool) -- True, if script shall be executed
- profilename (str) -- The name of the profile that will be updated
-
-
class
differencesolver.
DiffSolver
¶ Bases:
object
This is the abstract base class for difference solvers. Difference solver take two "different states" of the filesystem (e.g. one state could be an installed-file and another one a result of executed profiles) and create a
DiffLog
that holds all operations that are needed to transfer from the fist state to the second.-
difflog
¶ The DiffLog that will be used to store all calculated operations
Type: Difflog
-
__init__
()¶ Constructor.
-
_generate_operations
()¶ Calculate the operations needed to solve the differences and append them to
self.difflog
. Needs to be implemented by subclasses.
-
-
class
differencesolver.
UninstallDiffSolver
(installed, profile_names)¶ Bases:
differencesolver.DiffSolver
This difference solver takes the current installed file and a list of profile names. It is used to calculate all operations needed to uninstall the given profiles.
-
installed
¶ The installed-file that is used for solving
Type: dict
-
profile_names
¶ A list of profile names that will be uninstalled
Type: list
-
_UninstallDiffSolver__generate_profile_unlink
(profile_name)¶ Generate operations to remove a single installed profile.
Appends to
DiffLog
that we want to remove a profile, all it's subprofiles and all their links.Parameters: profile_name (str) -- Name of the profile that will be removed
-
__init__
(installed, profile_names)¶ Constructor.
Parameters: - installed (dict) -- The installed-file that is used for solving
- profile_names (list) -- A list of profile names that will be uninstalled
-
_generate_operations
(profilelist=None)¶ Generates operations to remove all installed profiles of
profilelist
.Skips profiles that are not installed.
Parameters: profilelist (list) -- A list of names of profiles that will be unlinked
-
-
class
differencesolver.
UpdateDiffSolver
(installed, profile_results, parent)¶ Bases:
differencesolver.DiffSolver
This solver determines the differences between an installed-file and a list of profiles.
-
installed
¶ The installed-file that is used for solving
Type: dict
-
profile_results
¶ The result of the executed profiles
Type: dict
-
parent
¶ The name of the parent that all profiles will change its parent to (only set if
--parent
was specified)Type: str
-
_UpdateDiffSolver__generate_profile_link
(profile_dict, all_profilenames, parent_name)¶ Generate operations for resolving the differences between a single profile and the installed ones and appends the corresponding operations to the DiffLog for those differences. Calls itself recursively for all subprofiles.
Parameters: - profile_dict (dict) -- The result of an executed profile that will be compared against the installed-file
- all_profilenames (list) -- A list with all profile names (including all sub- and root-profiles)
- parent_name (str) -- The name of the profiles (new) parent. If
parent_name is
None
, the profile is treated as a root profile
-
__init__
(installed, profile_results, parent)¶ Constructor.
Parameters: - installed (dict) -- The installed-file that is used for solving
- profile_results (list) -- A list of the result of the executed profiles
- parent (str) -- The value of the cli argument --parent
-
_generate_operations
()¶ Generates operations to update all profiles.
This function resolves each root profile with their subprofiles separately.
-