univention.management.console.modules.updater package#
- class univention.management.console.modules.updater.Watched_File(path: str, count: int = 2)[source]#
Bases:
objectA class that takes a file name and watches changes to this file. We don’t use any advanced technologies (FAM, inotify etc.) but rather basic ‘stat’ calls, monitoring mtime and size.
- class univention.management.console.modules.updater.Watched_Files(files: Iterable[str], count: int = 2)[source]#
Bases:
objectConvenience class to monitor more than one file at a time.
- class univention.management.console.modules.updater.Instance(*args, **kwargs)[source]#
Bases:
Base- query_releases(request, *args, **kwargs)[source]#
Returns a list of system releases suitable for the corresponding ComboBox
- updates_check(request, *args, **kwargs)[source]#
Returns the list of packages to be updated/installed by a dist-upgrade.
- updates_available(request, *args, **kwargs)[source]#
Asks if there are package updates available. (don’t get confused by the name of the UniventionUpdater function that is called here.) This is a separate call since it can take an amount of time, thus being invoked by a separate button (and not in the background)
- running(request, *args, **kwargs)[source]#
Returns the id (key into INSTALLERS) of a currently running job, or the empty string if nothing is running.
- updater_log_file(request)[source]#
returns the content of the log file associated with the job.
- Parameters:
job – Job name.
count – has the same meaning as already known: <0 …… return timestamp of file (for polling) 0 ……. return whole file as a string list >0 …… ignore this many lines, return the rest of the file
Note
As soon as we have looked for a running job at least once, we know the job key and can associate it here.
TODO: honor a given ‘job’ argument
- updater_job_status(request)[source]#
Returns the status of the current/last update even if the job is not running anymore.
- run_installer(request)[source]#
This is the function that invokes any kind of installer. Arguments accepted:
- Parameters:
job – ….. the main thing to do. can be one of: ‘release’ …… perform a release update ‘distupgrade’ .. update all currently installed packages (distupgrade)
detail – ……. an argument that specifies the subject of the installer: for ‘release’ …. the target release number, for all other subjects: detail has no meaning.
- class univention.management.console.modules.updater.HookManager(module_dir: str, raise_exceptions: bool = True)[source]#
Bases:
objectThis class tries to provide a simple interface to load and call hooks within existing code. Python modules are loaded from specified module_dir and automatically registered. These Python modules have to contain at least a global method register_hooks() that returns a list of tuples (hook_name, callable).
Simple hook file example:
def test_hook(*args, **kwargs): print('1ST_TEST_HOOK:', args, kwargs) return ('Result', 1) def other_hook(*args, **kwargs): print('OTHER_HOOK:', args, kwargs) return 'Other result' def register_hooks(): return [ ('test_hook', test_hook), ('pre_hook', other_hook), ]
The method call_hook(hookname, *args, **kwargs) calls all registered methods for specified hookname and passes *args and **kwargs to them. The return value of each method will be saved and returned by call_hook() as a list. If no method has been registered for specified hookname, an empty list will be returned.
If raise_exceptions has been set to False, exceptions while loading Python modules will be discarded silently. If a hook raises an exception, it will be caught and returned in result list of call_hooks() instead of corresponding return value. E.g.:
[['Mein', 'Result', 123], <exceptions.ValueError instance at 0x7f80496f6638>]
How to use HookManager:
>>> hm = HookManager(TESTDIR) >>> list(hm.get_hook_list()) ['test_hook', 'pre_hook'] >>> result = hm.call_hook('test_hook', 'abc', 123, x=1) 1ST_TEST_HOOK: ('abc', 123) {'x': 1} 2ND_TEST_HOOK: ('abc', 123) {'x': 1} >>> result [('Result', 1), ('Result', 2)] >>> hm.call_hook('unknown_hook') []
- Parameters:
module_dir – path to directory that contains Python modules with hook functions
raise_exceptions – if False, all exceptions while loading Python modules will be dropped and all exceptions while calling hooks will be caught and returned in result list
- set_raise_exceptions(val: bool) None[source]#
Enable or disable raising exceptions.
- Parameters:
val – True to pass exceptions through, False to return them instead of the return value.