Utility functions that are of interest to and shared by the entire OpenQuake python code base.
Utility functions related to OpenQuake version information.
Return a string with the OpenQuake version infomation.
Version info data set to -1 will be ignored and assumed to have value zero. Release dates that lie more than 30 days in the future are ignored.
|Parameters:||version_data – A 4-tuple of integers that are the major, minor and sprint number respectively. The last datum is the number of seconds since epoch and represents the release date.|
|Returns:||A string with human readable OpenQuake version information.|
Various utility functions concerned with configuration.
Environment variable name for specifying a custom openquake.cfg. The file name doesn’t matter.
Call sys.exit() if no openquake configuration file is readable.
Context manager used to change the parameters of a configuration section on the fly. For use in the tests.
True if the given boolean setting is enabled in openquake.cfg
True if the setting is enabled in openquake.cfg, False otherwise
The configuration value for the given section and key or None.
A dictionary of key/value pairs for the given section or None.
Re-parse config files and refresh the cached configuration.
NOTE: Use with caution. Calling this during some phases of a calculation could cause undesirable side-effects.
Various utility functions related to splitting work into tasks and/or managing these.
Utility functions related to splitting work into tasks.
A celery-based task manager. The usage is:
oqm = OqTaskManager(do_something, logs.LOG.progress) oqm.send(arg1, arg2) oqm.send(arg3, arg4) print oqm.aggregate_results(agg, acc)
Progress report is built-in.
Loop on a set of celery AsyncResults and update the accumulator by using the aggregation function.
the final value of the accumulator
Log the message using the progress reporting logging level.
args and kwargs are the same as logging.Logger.debug(), except that this method has an additional possible keyword: indent.
Normally, progress messages are logged with a ‘** ‘ prefix. If indent is True, messages will be logged with a ‘** >’ prefix.
If indent is not specified, it will default to False.
Task function decorator which sets up logging and catches (and logs) any errors which occur inside the task. Also checks to make sure the job is actually still running. If it is not running, the task doesn’t get executed, so we don’t do useless computation.
|Parameters:||task_func – the function to decorate|