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_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_callback(job_id, job_owner_email, outputs_uri, inputs, exc=None, warnings=None, email_file_path=None)[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.aelo_validate(request)[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)[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_callback(job_id, params, job_owner_email, outputs_uri, exc=None, warnings=None, email_file_path=None)[source]#
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.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 WebUI, served by Django under the /v0 and /v1 paths of the server.

The functions without the v0_/v1_ prefix implement the endpoints: they are called in-process by openquake.server.views and they raise ApiError on failure. The decorated functions are the HTTP views, which check the internal API key and turn the outcome into a response.

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.

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

Bases: FileResponse

Stream an exported file and remove its directory once closed.

close()[source]#
openquake.server.internal_api.aelo_run(form)[source]#

Run an AELO calculation from the given form.

openquake.server.internal_api.aelo_site_classes()[source]#

Return the AELO site-class definitions.

openquake.server.internal_api.calc_abort(calc_id)[source]#

Abort a running calculation.

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

Return the information about a calculation.

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

Count the calculations matching the filters of the list view.

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

Return a slice of the log of a calculation.

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

Return the number of log lines of a calculation.

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

Remove a calculation on behalf of its owner.

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

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

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

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

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

Return the traceback of a calculation.

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

Execute an allowlisted database action.

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

Return available IMPACT resources without presentation URLs.

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

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

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

Return whether the request carries the internal API key.

openquake.server.internal_api.impact_form_defaults()[source]#

Return the default values for the IMPACT form.

openquake.server.internal_api.impact_get_rupture_data(form)[source]#

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

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

Run an IMPACT calculation from the given form.

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.model_provenance(calc_id)[source]#

Return the model provenance of a calculation.

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.run_scenario_calc_from_ses_rupture(rup_id, form)[source]#

Run a PAPERS scenario calculation for an SES rupture.

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

Run an AELO calculation for an authenticated Django caller.

openquake.server.internal_api.v0_calc_abort(request, calc_id)[source]#

Abort a running calculation for an authenticated caller.

openquake.server.internal_api.v0_calc_log(request, calc_id, start, stop)[source]#

Return a calculation log slice.

openquake.server.internal_api.v0_calc_log_size(request, calc_id)[source]#

Return the number of log lines for a calculation.

openquake.server.internal_api.v0_calc_remove(request, calc_id)[source]#

Remove a calculation for an authenticated caller.

openquake.server.internal_api.v0_calc_result(request, result_id)[source]#

Export a calculation result in the requested format.

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

Submit a calculation for an authenticated Django caller.

openquake.server.internal_api.v0_calc_traceback(request, calc_id)[source]#

Return the traceback for a calculation.

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

Execute an allowlisted database action.

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

Build IMPACT rupture data for an authenticated Django caller.

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

Run IMPACT for an authenticated Django caller.

openquake.server.internal_api.v0_model_provenance(request, calc_id)[source]#

Return the model provenance of a calculation.

openquake.server.internal_api.v0_run_scenario(request, rup_id)[source]#

Run a papers scenario calculation for an authenticated caller.

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

Validate an uploaded INI file.

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

Validate an uploaded calculation archive.

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

Run an authenticated worker-control action.

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

Return the AELO site-class definitions.

openquake.server.internal_api.v1_calc_info(request, calc_id)[source]#

Return the information about a calculation.

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

Count the calculations matching the filters of the list view.

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

Return the default values for the IMPACT form.

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

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

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

Validate the calculation file stored under the given field.

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

Run an authenticated worker-control action.

Module contents#