univention.management.console.modules.updater package#

class univention.management.console.modules.updater.Watched_File(path: str, count: int = 2)[source]#

Bases: object

A 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.

timestamp() int[source]#

Main function. returns the current timestamp whenever size or mtime have changed. Defers returning the new value until changes have settled down, e.g. until the same values have appeared ‘count’ times.

class univention.management.console.modules.updater.Watched_Files(files: Iterable[str], count: int = 2)[source]#

Bases: object

Convenience class to monitor more than one file at a time.

timestamp() int[source]#
class univention.management.console.modules.updater.Instance(*args, **kwargs)[source]#

Bases: Base

init() None[source]#

this function is invoked after the module process started.

query_maintenance_information(request, *args, **kwargs)[source]#
query_releases(request, *args, **kwargs)[source]#

Returns a list of system releases suitable for the corresponding ComboBox

call_hooks(request)[source]#

Calls the specified hooks and returns data given back by each hook

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)

status(request) None[source]#

One call for all single-value variables.

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: object

This 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:

valTrue to pass exceptions through, False to return them instead of the return value.

get_hook_list() Iterable[str][source]#

returns a list of hook names that have been defined by loaded Python modules.

call_hook(name: str, *args: Any, **kwargs: Any) list[Any][source]#

All additional arguments are passed to hook methods. If self.__raise_exceptions is False, all exceptions while calling hooks will be caught and returned in result list. If return value is an empty list, no hook has been called.