OpenQuake Utilities

The Utils Sub-package

Utility functions that are of interest to and shared by the entire OpenQuake python code base.

version

Utility functions related to OpenQuake version information.

openquake.engine.utils.version.info(version_data)[source]

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.

config

Various utility functions concerned with configuration.

openquake.engine.utils.config.OQ_CONFIG_FILE_VAR = 'OQ_CONFIG_FILE'

Environment variable name for specifying a custom openquake.cfg. The file name doesn’t matter.

openquake.engine.utils.config.abort_if_no_config_available()[source]

Call sys.exit() if no openquake configuration file is readable.

openquake.engine.utils.config.context(*args, **kwds)[source]

Context manager used to change the parameters of a configuration section on the fly. For use in the tests.

openquake.engine.utils.config.flag_set(section, setting)[source]

True if the given boolean setting is enabled in openquake.cfg

Parameters:
  • section (string) – name of the configuration file section
  • setting (string) – name of the configuration file setting
Returns:

True if the setting is enabled in openquake.cfg, False otherwise

openquake.engine.utils.config.get(section, key)[source]

The configuration value for the given section and key or None.

openquake.engine.utils.config.get_section(section)[source]

A dictionary of key/value pairs for the given section or None.

openquake.engine.utils.config.refresh()[source]

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.

tasks

Various utility functions related to splitting work into tasks and/or managing these.

Utility functions related to splitting work into tasks.

exception openquake.engine.utils.tasks.JobNotRunning[source]

Bases: exceptions.Exception

class openquake.engine.utils.tasks.OqTaskManager(oqtask, name=None)[source]

Bases: openquake.commonlib.parallel.TaskManager

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.

aggregate_result_set(agg, acc)[source]

Loop on a set of celery AsyncResults and update the accumulator by using the aggregation function.

Parameters:
  • agg – the aggregation function, (acc, val) -> new acc
  • acc – the initial value of the accumulator
Returns:

the final value of the accumulator

static progress(msg, *args, **kwargs)

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.

openquake.engine.utils.tasks.oqtask(task_func)[source]

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

Table Of Contents

Previous topic

OpenQuake NRML schema

Next topic

Writer

This Page