openquake.server package#

Subpackages#

Submodules#

openquake.server.manage module#

openquake.server.middleware module#

class openquake.server.middleware.LoginRequiredMiddleware(get_response)[source]#

Bases: object

Middleware that requires a user to be authenticated to view any page other than LOGIN_URL. Exemptions to this requirement can be specified in settings via a list of regular expressions in LOGIN_EXEMPT_URLS.

Requires authentication middleware and template context processors to be loaded. You’ll get an error if they aren’t.

class openquake.server.middleware.PrintHeadersMiddleware(get_response)[source]#

Bases: object

openquake.server.settings module#

openquake.server.urls module#

openquake.server.utils module#

openquake.server.utils.check_webserver_running(url='http://localhost:8800', max_retries=30, warn=True)[source]#

Returns True if a given URL is responding within a given timeout.

openquake.server.utils.get_acl_on(request)[source]#

Returns True if ACL should be honorated, returns otherwise False.

openquake.server.utils.get_or_create_django_secret_key()[source]#
openquake.server.utils.get_username(request)[source]#

Returns the users from request if authentication is enabled, otherwise returns the default user (from settings, or as reported by the OS).

openquake.server.utils.get_valid_users(request)[source]#

” Returns a list of users based on groups membership. Returns a list made of a single user when it is not member of any group.

openquake.server.utils.is_superuser(request)[source]#

Without authentication (settings.LOCKDOW is false) every user is considered a superuser, otherwise look at the attribute request.user.is_superuser.

openquake.server.utils.oq_server_context_processor(request)[source]#

A custom context processor which allows injection of additional context variables.

openquake.server.utils.user_has_permission(request, owner, job_status)[source]#

Returns True if user coming from the request has the permission to view a job-related resource, returns False otherwise.

openquake.server.views module#

openquake.server.views.add_tag_to_job(user_level, calc_id, tag_name)[source]#
openquake.server.views.aelo_changelog(request, **kwargs)[source]#
openquake.server.views.aelo_run(request, *args, **kwargs)[source]#
openquake.server.views.aelo_site_classes(request, *args, **kwargs)[source]#
openquake.server.views.ajax_login(request, *args, **kwargs)[source]#
openquake.server.views.ajax_logout(request, *args, **kwargs)[source]#
openquake.server.views.build_impact_resources(request, calc_id, dstore)[source]#

Describe impact resources and their presentation URLs.

openquake.server.views.calc(request, *args, **kwargs)[source]#
openquake.server.views.calc_abort(request, *args, **kwargs)[source]#
openquake.server.views.calc_add_tag(request, *args, **kwargs)[source]#
openquake.server.views.calc_count(request, *args, **kwargs)[source]#
openquake.server.views.calc_create_tag(request, *args, **kwargs)[source]#
openquake.server.views.calc_datastore(request, *args, **kwargs)[source]#
openquake.server.views.calc_delete_tag(request, *args, **kwargs)[source]#
openquake.server.views.calc_get_preferred_job_for_tag(request, *args, **kwargs)[source]#
openquake.server.views.calc_impact_resources(request, *args, **kwargs)[source]#
openquake.server.views.calc_list(request, *args, **kwargs)[source]#
openquake.server.views.calc_list_tags(request, *args, **kwargs)[source]#
openquake.server.views.calc_log(request, *args, **kwargs)[source]#
openquake.server.views.calc_log_size(request, *args, **kwargs)[source]#
openquake.server.views.calc_remove(request, *args, **kwargs)[source]#
openquake.server.views.calc_remove_tag(request, *args, **kwargs)[source]#
openquake.server.views.calc_result(request, *args, **kwargs)[source]#
openquake.server.views.calc_results(request, *args, **kwargs)[source]#
openquake.server.views.calc_run(request, *args, **kwargs)[source]#
openquake.server.views.calc_run_ini(request, *args, **kwargs)[source]#
openquake.server.views.calc_run_scenario_from_ses(request, *args, **kwargs)[source]#
openquake.server.views.calc_set_preferred_job_for_tag(request, *args, **kwargs)[source]#
openquake.server.views.calc_share(request, *args, **kwargs)[source]#
openquake.server.views.calc_traceback(request, *args, **kwargs)[source]#
openquake.server.views.calc_unset_preferred_job_for_tag(request, *args, **kwargs)[source]#
openquake.server.views.calc_unshare(request, *args, **kwargs)[source]#
openquake.server.views.calc_zip(request, *args, **kwargs)[source]#
openquake.server.views.can_extract(request, resource)[source]#
openquake.server.views.check_callback(request, *args, **kwargs)[source]#
openquake.server.views.check_db_response(resp)[source]#
openquake.server.views.create_impact_job(request, params, email_file_path)[source]#
openquake.server.views.create_tag(user_level, tag_name)[source]#
openquake.server.views.cross_domain_ajax(func)[source]#
openquake.server.views.delete_tag(user_level, tag_name)[source]#
openquake.server.views.determine_precision(weights)[source]#

Determine the minimum decimal places needed to represent the weights accurately

openquake.server.views.download_aggrisk(request, *args, **kwargs)[source]#
openquake.server.views.download_png(request, *args, **kwargs)[source]#
openquake.server.views.exposure_by_lse(request, *args, **kwargs)[source]#
openquake.server.views.exposure_by_mmi(request, *args, **kwargs)[source]#
openquake.server.views.extract(request, *args, **kwargs)[source]#
openquake.server.views.extract_html_table(request, *args, **kwargs)[source]#
openquake.server.views.extract_report_from_datastore(dstore, iso3, file_format, page=1)[source]#
openquake.server.views.format_oqparam(oqparam)[source]#
openquake.server.views.format_time_delta(td)[source]#
openquake.server.views.get_aelo_notes_and_warnings(ds)[source]#
openquake.server.views.get_allowed_outputs(oes, request)[source]#
openquake.server.views.get_authentication_status(request, *args, **kwargs)[source]#
openquake.server.views.get_available_gsims(request, *args, **kwargs)[source]#
openquake.server.views.get_disp_val(val)[source]#
openquake.server.views.get_engine_latest_version(request, *args, **kwargs)[source]#
openquake.server.views.get_engine_version(request, *args, **kwargs)[source]#
openquake.server.views.get_impact_form_defaults(request, *args, **kwargs)[source]#
openquake.server.views.get_impact_rupture_data(post, user, rupture_path)[source]#

Validate a rupture and build the data needed by the IMPACT UI.

openquake.server.views.get_impact_warnings(ds)[source]#
openquake.server.views.get_ini_defaults(request, *args, **kwargs)[source]#
openquake.server.views.get_preferred_job_for_tag(tag_name)[source]#
openquake.server.views.get_site_class_display_name(ds)[source]#
openquake.server.views.get_user_level(request)[source]#
openquake.server.views.group_keys_by_value(d)[source]#

Groups keys from the input dictionary by their shared values. If a value is shared by multiple keys, those keys are grouped into a tuple. Otherwise, the key is kept as-is.

Parameters:

d – a dictionary with hashable keys and values

Returns:

a dictionary where keys are either individual keys or tuples of keys that shared the same value, and values are the original values

Example:
>>> group_keys_by_value({0: 'a', 1: 'b', 2: 'a'})
{(0, 2): 'a', 1: 'b'}
openquake.server.views.impact_get_nodal_planes_and_info(request, *args, **kwargs)[source]#
openquake.server.views.impact_get_rupture_data(request, *args, **kwargs)[source]#
openquake.server.views.impact_get_shakemap_versions(request, *args, **kwargs)[source]#
openquake.server.views.impact_get_stations_from_usgs(request, *args, **kwargs)[source]#
openquake.server.views.impact_report(request, *args, **kwargs)[source]#
openquake.server.views.impact_results(request, *args, **kwargs)[source]#
openquake.server.views.impact_run(request, *args, **kwargs)[source]#
openquake.server.views.impact_run_with_shakemap(request, *args, **kwargs)[source]#
openquake.server.views.infer_site_class(asce_version, vs30)[source]#
openquake.server.views.is_model_preliminary(ds)[source]#
openquake.server.views.jobs_from_inis(request, *args, **kwargs)[source]#
openquake.server.views.license(request, **kwargs)[source]#
openquake.server.views.list_tags()[source]#
openquake.server.views.log_to_json(log)[source]#

Convert a log record into a list of strings

openquake.server.views.model_provenance(request, *args, **kwargs)[source]#
openquake.server.views.on_same_fs(request, *args, **kwargs)[source]#
openquake.server.views.remove_tag_from_job(user_level, calc_id, tag_name)[source]#
openquake.server.views.save_pik(job, dirname)[source]#

Save a LogContext object in pickled format; returns the path to it

openquake.server.views.set_preferred_job_for_tag(user_level, calc_id, tag_name)[source]#
openquake.server.views.share_job(request, calc_id, share)[source]#
openquake.server.views.stream_response(fname, content_type, exportname='')[source]#

Stream a file stored in a temporary directory via Django

openquake.server.views.submit_job(request_files, ini, username, hc_id, notify_to=None)[source]#

Create a job object from the given files and run it in a new process.

Returns:

a job ID

openquake.server.views.unset_preferred_job_for_tag(user_level, tag_name)[source]#
openquake.server.views.v1_calc_info(request, calc_id)[source]#

Return the information about a calculation.

openquake.server.views.v1_calc_list_count(request)[source]#

Count the calculations matching the filters of the list view.

openquake.server.views.validate_ini(request, *args, **kwargs)[source]#
openquake.server.views.validate_nrml(request, *args, **kwargs)[source]#
openquake.server.views.validate_zip(request, *args, **kwargs)[source]#
openquake.server.views.web_engine(request, **kwargs)[source]#
openquake.server.views.web_engine_get_outputs(request, *args, **kwargs)[source]#
openquake.server.views.web_engine_get_outputs_aelo(request, *args, **kwargs)[source]#
openquake.server.views.web_engine_get_outputs_impact(request, *args, **kwargs)[source]#

openquake.server.internal_api module#

Internal API of the engine, i.e. the API used only by the processes of the engine itself and protected by the key in the authkey of the [webapi] section of openquake.cfg. It contains the machinery to write the views checking the key (internal_view()), the database and worker actions of the /v0 API and the plumbing of the other views.

This module does not import openquake.server.services nor the views, which import it.

exception openquake.server.internal_api.ApiError(status, detail=None, content=None)[source]#

Bases: Exception

Error returned to the caller with the given HTTP status.

response()[source]#

Return the JSON response describing the error.

openquake.server.internal_api.db_action(action, payload)[source]#

Execute an allowlisted database action.

openquake.server.internal_api.has_api_key(request)[source]#

Return whether the request carries the internal API key.

openquake.server.internal_api.internal_view(*methods, auth=True)[source]#

Turn a function of the request into a Django view accepting only the given HTTP methods. The view is exempt from CSRF checks, since the callers are programs, and it requires the internal API key unless auth is false.

openquake.server.internal_api.json_response(data, status=200)[source]#

Return a JSON response, converting dates and numpy scalars.

openquake.server.internal_api.make_form(*sources)[source]#

Merge plain fields (dictionaries or QueryDicts) and uploaded files into a single MultiValueDict, the form accepted by the internal functions.

openquake.server.internal_api.run(func, *args, **kwargs)[source]#

Call an internal API function and return its response. The errors raised as ApiError or as dbapi.NotFound become JSON error responses, while a returned HTTP response is passed unchanged.

openquake.server.internal_api.v0_db_action(request, action)[source]#

Execute an allowlisted database action.

openquake.server.internal_api.v0_worker(request, action)[source]#

Run an authenticated worker-control action.

openquake.server.internal_api.worker_action(action, payload)[source]#

Run an authenticated worker-control action.

openquake.server.services module#

The logic of the WebUI, called in-process by openquake.server.views: running, aborting and removing calculations, reading their logs and exporting their results, the AELO and IMPACT runs and their notifications. The functions raise openquake.server.internal_api.ApiError on failure, which openquake.server.internal_api.run() turns into a JSON response.

openquake.server.services.DEFAULT_EXPORT_TYPE = 'xml'#

For exporting calculation outputs, the client can request a specific format (xml, geojson, csv, etc.). If the client does not specify, give them (NRML) XML by default.

class openquake.server.services.ExportResponse(fname, **kwargs)[source]#

Bases: FileResponse

Stream an exported file and remove its directory once closed.

close()[source]#
openquake.server.services.aelo_callback(job_id, job_owner_email, outputs_uri, inputs, exc=None, warnings=None, email_file_path=None)[source]#
openquake.server.services.aelo_run(form)[source]#

Run an AELO calculation from the given form.

openquake.server.services.aelo_validate(request)[source]#
openquake.server.services.calc_abort(calc_id)[source]#

Abort a running calculation.

openquake.server.services.calc_info(calc_id)[source]#

Return the information about a calculation.

openquake.server.services.calc_list_count(params, valid_users, acl_on)[source]#

Count the calculations matching the filters of the list view.

openquake.server.services.calc_log(calc_id, start, stop)[source]#

Return a slice of the log of a calculation.

openquake.server.services.calc_log_size(calc_id)[source]#

Return the number of log lines of a calculation.

openquake.server.services.calc_remove(calc_id, username)[source]#

Remove a calculation on behalf of its owner.

openquake.server.services.calc_result(result_id, export_type=None)[source]#

Export a result in the requested format, as a downloadable file.

openquake.server.services.calc_run(form)[source]#

Submit a calculation, using the archive in the form if present.

openquake.server.services.calc_traceback(calc_id)[source]#

Return the traceback of a calculation.

openquake.server.services.create_impact_job(params, username, job_owner_email, build_urls, callback, email_file_path)[source]#

Create and start an IMPACT job using injected adapters.

openquake.server.services.export_result(result_id, export_type=None)[source]#

Export a calculation result in the requested format.

Parameters:
  • result_id – ID of the result to export

  • export_type – export format, NRML XML by default

Returns:

a triple (fname, content_type, exportname) where fname is the path of a file inside a fresh temporary directory, or None if the result cannot be exported in the given format

Raises:

DataStoreExportError if the export fails

openquake.server.services.get_impact_resource_data(dstore)[source]#

Return available IMPACT resources without presentation URLs.

openquake.server.services.get_impact_rupture_data(post, user, rupture_path)[source]#

Validate a rupture and build the data needed by the IMPACT UI.

openquake.server.services.get_papers_job_ctx(papers, rup_id, form)[source]#

Build a PAPERS job context using an injected papers adapter.

openquake.server.services.get_uploaded_file_path(files, filename)[source]#

Copy an uploaded file to a temporary path and return its location.

openquake.server.services.impact_callback(job_id, params, job_owner_email, outputs_uri, exc=None, warnings=None, email_file_path=None)[source]#
openquake.server.services.impact_get_rupture_data(form)[source]#

Build the rupture data of an IMPACT job from the given form.

openquake.server.services.impact_run(form)[source]#

Run an IMPACT calculation from the given form.

openquake.server.services.model_provenance(calc_id)[source]#

Return the model provenance of a calculation.

openquake.server.services.remove_exported(fname)[source]#

Remove the temporary directory containing an exported file.

openquake.server.services.run_aelo(lon, lat, site_name, asce_version, site_class, vs30, username, job_owner_email, build_urls, callback, email_file_path)[source]#

Create and start an AELO job using injected URL and callback helpers.

openquake.server.services.run_scenario_calc_from_ses_rupture(rup_id, form)[source]#

Run a PAPERS scenario calculation for an SES rupture.

openquake.server.services.save_pik(job, dirname)[source]#

Save a calculation job context for an external submit command.

openquake.server.services.store(request_files, ini, calc_id)[source]#

Store the uploaded files in calc_dir and select the job file by looking at the .ini extension.

Returns:

full path of the ini file

openquake.server.services.submit_job(request_files, ini, username, hc_id, notify_to=None)[source]#

Create a calculation job and submit it without Django dependencies.

openquake.server.services.validate_aelo_data(post, form_labels, max_site_name_length)[source]#

Validate AELO form data without depending on Django.

openquake.server.services.validate_job(job_file)[source]#

Validate a calculation input and return its JSON-compatible result.

openquake.server.services.validate_upload(form, field, missing_message)[source]#

Validate the calculation file stored under the given field.

Module contents#