sirepo package

Subpackages

Submodules

sirepo.api_auth module

sirepo.api_perm module

decorators for API permissions and the permissions themselves

copyright:Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
class sirepo.api_perm.APIPerm(*args, **kwds)[source]

Bases: aenum.Flag

ALLOW_COOKIELESS_USER = <APIPerm.ALLOW_COOKIELESS_USER: 1>
ALLOW_LOGIN = <APIPerm.ALLOW_LOGIN: 2>
ALLOW_VISITOR = <APIPerm.ALLOW_VISITOR: 4>
REQUIRE_USER = <APIPerm.REQUIRE_USER: 8>
sirepo.api_perm.ATTR = 'api_perm'

decorator sets this attribute with an APIPerm

sirepo.api_perm.allow_cookieless_user(func)
sirepo.api_perm.allow_login(func)
sirepo.api_perm.allow_visitor(func)
sirepo.api_perm.require_user(func)

sirepo.base_pkconfig module

Default config

copyright:Copyright (c) 2016 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.base_pkconfig.alpha()[source]
sirepo.base_pkconfig.beta()[source]
sirepo.base_pkconfig.dev()[source]
sirepo.base_pkconfig.prod()[source]

sirepo.beaker_compat module

sirepo.bluesky module

sirepo.celery_tasks module

sirepo.comsol_register module

sirepo.cookie module

User state management via an HTTP cookie

copyright:Copyright (c) 2015 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.cookie.clear_user()[source]
sirepo.cookie.get_user(checked=True)[source]
sirepo.cookie.get_value(key)[source]
sirepo.cookie.has_key(key)[source]
sirepo.cookie.has_sentinel()[source]
sirepo.cookie.has_user_value()[source]
sirepo.cookie.init(unit_test=None)[source]
sirepo.cookie.init_mock(uid='invalid-uid')[source]

A mock cookie for pkcli

sirepo.cookie.init_module(app, uwsgi)[source]
sirepo.cookie.set_log_user(uid)[source]
sirepo.cookie.set_sentinel()[source]

Bypasses the state where the cookie has not come back from the client. This is used by bluesky and testing only, right now.

sirepo.cookie.set_user(uid)[source]
sirepo.cookie.set_value(key, value)[source]
sirepo.cookie.unchecked_remove(key)[source]

sirepo.crystal module

Get polarizability from X0h server (http://x-server.gmca.aps.anl.gov/x0h.html). For details see http://x-server.gmca.aps.anl.gov/pub/Stepanov_CR_1991_08.pdf.

sirepo.crystal.calc_bragg_angle(d, energy_eV, n=1)[source]

Calculate Bragg angle from the provided energy and d-spacing.

Parameters:
  • d (float) – interplanar spacing (d-spacing) [A].
  • energy_eV (float) – photon energy [eV].
  • n (int) – number of diffraction peak.
Returns:

the resulted dictionary with:

lamda (float): wavelength [nm]. bragg_angle (float): Bragg angle [rad]. bragg_angle_deg (float): Bragg angle [deg].

Return type:

dict

sirepo.crystal.get_crystal_parameters(material, energy_eV, h, k, l)[source]

Obtain parameters for the specified crystal and energy.

Parameters:
  • material (str) – material full name (e.g., ‘Silicon’).
  • energy_eV (float) – photon energy [eV].
  • h (int) – Miller’s index h.
  • k (int) – Miller’s index k.
  • l (int) – Miller’s index l.
Returns:

crystal parameters:

d (float): interplanar spacing (d-spacing) [A]. xr0 (float): real part of the 0-th Fourier component of crystal’s polarizability. xi0 (float): imaginary part of the 0-th Fourier component of crystal’s polarizability. xrh (float): real part of the H-th Fourier component of crystal’s polarizability (Sigma polarization). xih (float): imaginary part of the H-th Fourier component of crystal’s polarizability (Sigma polarization). bragg_angle_deg (float): Bragg angle [deg].

Return type:

dict

sirepo.exporter module

Export simulations in a single archive

copyright:Copyright (c) 2017 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.exporter.create_archive(sim_type, sim_id, filename)[source]

Zip up the json file and its dependencies

Parameters:
  • sim_type (str) – simulation type
  • sim_id (str) – simulation id
  • filename (str) – for file type
Returns:

zip file name

Return type:

py.path.Local

sirepo.feature_config module

List of features available

copyright:Copyright (c) 2016 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.feature_config.cfg = OrderedMapping(api_modules=(), rs4pi_dose_calc=False, sim_types=('srw', 'warppba', 'elegant', 'shadow', 'hellweg', 'warpvnd', 'rs4pi', 'jspec', 'synergia', 'myapp', 'adm', 'zgoubi'), srw=OrderedMapping(mask_in_toolbar=True), warpvnd=OrderedMapping(allow_3d_mode=True, display_test_boxes=True))

Configuration

sirepo.feature_config.for_sim_type(sim_type)[source]

Get cfg for simulation type

Parameters:sim_type (str) – srw, warppba, etc.
Returns:application specific config
Return type:dict

sirepo.http_reply module

response generation

copyright:Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.http_reply.gen_json(value, pretty=False)[source]

Generate JSON flask response

Parameters:
  • value (dict) – what to format
  • pretty (bool) – pretty print [False]
Returns:

flask response

Return type:

Response

sirepo.http_reply.gen_json_ok(*args, **kwargs)[source]

Generate state=ok JSON flask response

Returns:flask response
Return type:Response

sirepo.http_request module

request input parsing

copyright:Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.http_request.parse_json(assert_sim_type=True)[source]

sirepo.hundli_console module

Hundli: a dog height and weight simulation engine

This is not technically part of Sirepo. It demonstrates a arbitrary 3rd party code, which Sirepo calls as an independent program.

copyright:Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.hundli_console.main()[source]

Read the input yaml and write the output csv

sirepo.importer module

Import a single archive

copyright:Copyright (c) 2017 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.importer.do_form(form)[source]

Self-extracting archive post

Parameters:form (flask.request.Form) – what to import
Returns:data
Return type:dict
sirepo.importer.read_json(text, template=None)[source]

Read json file and return

Parameters:
  • text (IO) – file to be read
  • template (module) – expected type
Returns:

data

Return type:

dict

sirepo.importer.read_zip(stream, template=None)[source]

Read zip file and store contents

Parameters:
  • stream (IO) – file to read
  • template (module) – expected app
Returns:

data

Return type:

dict

sirepo.mpi module

Run Python processes in background

copyright:Copyright (c) 2016 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.mpi.run_program(cmd, output='mpi_run.out', env=None)[source]

Execute python script with mpi.

Parameters:
  • cmd (list) – cmd to run
  • output (str) – where to write stdout and stderr
  • env (dict) – what to pass as env
sirepo.mpi.run_script(script)[source]

Execute python script with mpi.

Parameters:script (str) – python text

sirepo.oauth module

sirepo.server module

sirepo.simulation_db module

Simulation database

copyright:Copyright (c) 2015 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
exception sirepo.simulation_db.CopyRedirect(resp)[source]

Bases: exceptions.Exception

sirepo.simulation_db.JSON_SUFFIX = '.json'

Json files

sirepo.simulation_db.RESOURCE_FOLDER = local('/home/docs/checkouts/readthedocs.org/user_builds/sirepo/checkouts/latest/sirepo/package_data')

The root of the pkresource tree (package_data)

sirepo.simulation_db.SCHEMA_COMMON = {u'appInfo': {u'warpvnd': {u'shortName': u'Warp VND', u'longName': u'Warp VND'}, u'zgoubi': {u'shortName': u'ZGOUBI', u'longName': u'ZGOUBI'}, u'jspec': {u'shortName': u'JSPEC', u'longName': u'JSPEC'}, u'rs4pi': {u'shortName': u'RS4PI', u'longName': u'RS4PI'}, u'elegant': {u'shortName': u'Elegant', u'longName': u'elegant'}, u'srw': {u'shortName': u'SRW', u'longName': u'Synchrotron Radiation Workshop'}, u'myapp': {u'shortName': u'MyApp', u'longName': u'MyApp'}, u'shadow': {u'shortName': u'SHADOW', u'longName': u'SHADOW'}, u'adm': {u'shortName': u'Sirepo Admin', u'longName': u'Sirepo Admin'}, u'synergia': {u'shortName': u'Synergia', u'longName': u'Synergia'}, u'warppba': {u'shortName': u'Warp PBA', u'longName': u'Warp PBA'}, u'hellweg': {u'shortName': u'Hellweg', u'longName': u'Hellweg'}}, u'common': {u'cookies': {u'getStarted': {u'name': u'strt', u'value': u'a'}, u'login': {u'timeout': 1, u'name': u'login', u'value': u'a'}, u'listView': {u'valType': u'b', u'name': u'lv', u'value': False}, u'firstVisit': {u'name': u'1st_vis', u'value': u'a'}}, u'staticFiles': {u'externalLibs': {u'css': [u'bootstrap-3.3.7.min.css', u'bootstrap-colxl.css', u'bootstrap-toggle.min.css', u'katex.min.css', u'cookieconsent.min.css'], u'js': [u'angular.min.js', u'jquery-2.2.4.min.js', u'cookieconsent.min.js']}, u'sirepoLibs': {u'css': [u'sirepo.css'], u'js': [u'sirepo.js']}}, u'enum': {u'ColorMap': [[u'grayscale', u'grayscale'], [u'viridis', u'viridis'], [u'afmhot', u'afmhot'], [u'coolwarm', u'coolwarm'], [u'jet', u'jet']]}, u'localRoutes': {u'simulationsFolder': {u'route': u'/simulations/:folderPath?', u'config': {u'controller': u'SimulationsController as simulations', u'templateUrl': u'/static/html/simulations.html'}}, u'notFound': {u'route': u'/not-found', u'config': {u'templateUrl': u'/static/html/not-found.html'}}, u'forbidden': {u'route': u'/forbidden', u'config': {u'templateUrl': u'/static/html/forbidden.html'}}, u'notAuthorized': {u'route': u'/missing-cookies', u'config': {u'templateUrl': u'/static/html/not-authorized.html'}}, u'loggedOut': {u'route': u'/logged-out', u'config': {u'controller': u'LoggedOutController as loggedOut', u'templateUrl': u'/static/html/logged-out.html'}}, u'source': {u'route': u'/source/:simulationId'}, u'simulations': {u'route': u'/simulations', u'config': {u'controller': u'SimulationsController as simulations', u'templateUrl': u'/static/html/simulations.html'}, u'isDefault': True}, u'notFoundCopy': {u'route': u'/copy-session/:simulationIds/:section', u'config': {u'controller': u'NotFoundCopyController as notFoundCopy', u'templateUrl': u'/static/html/copy-session.html'}}}, u'notifications': {u'getStarted': {u'content': u'', u'active': True, u'cookie': u'getStarted', u'name': u'getStarted'}, u'login': {u'content': u'', u'active': False, u'delay': 1, u'cookie': u'login', u'name': u'login'}}, u'dynamicFiles': {u'externalLibs': {u'js': [u'angular-cookies.min.js', u'angular-route.min.js', u'bootstrap-3.3.7.min.js', u'bootstrap-toggle.min.js', u'ngDraggable.js', u'stacktrace-0.6.4.js', u'colorbar.js', u'canvg-and-dependencies.js', u'FileSaver.js', u'Blob.js', u'canvas-toBlob.js', u'd3-3.5.9.min.js', u'fontdetect-0.3.js', u'ie10-viewport-bug-workaround.js', u'katex.min.js']}, u'sirepoLibs': {u'js': [u'sirepo-common.js', u'sirepo-components.js', u'sirepo-plotting.js', u'sirepo-plotting-vtk.js', u'sirepo-geometry.js']}, u'libURLs': [u'/user-state']}, u'model': {u'simFolder': {u'name': [u'Folder Name', u'SafePath'], u'parent': [u'Parent Folder', u'UserFolder']}, u'simulation': {u'notes': [u'Notes', u'Text', u''], u'documentationUrl': [u'Documentation URL', u'OptionalString', u''], u'folder': [u'Folder', u'UserFolder'], u'name': [u'Name', u'SimulationName']}}, u'view': {u'simFolder': {u'advanced': [u'name', u'parent'], u'title': u'New Folder'}, u'simulation': {u'advanced': [u'name', u'folder', u'notes'], u'title': u'Simulation'}, u'simDoc': {u'model': u'simulation', u'advanced': [u'documentationUrl'], u'title': u'Simulation Documentation'}}, u'constants': {u'oneDayMillis': 86400000, u'clientCookie': u'sirepo_cookie_js'}, u'appModes': {u'default': {u'localRoute': u'source', u'includeMode': False}}}, u'customErrors': {u'404': {u'url': u'not-found.html', u'msg': u'File Not Found', u'route': u'notFound'}, u'403': {u'url': u'forbidden.html', u'msg': u'Forbidden', u'route': u'forbidden'}, u'401': {u'url': u'not-authorized.html', u'msg': u'Missing Cookies', u'route': u'notAuthorized'}, u'422': {u'url': u'srw-magnet-file-error.html', u'msg': u'Invalid Magnet File'}, u'502': {u'url': u'server-error.html', u'msg': u'Proxy Error'}, u'500': {u'url': u'server-error.html', u'msg': u'Server Error'}}, u'productInfo': {u'shortName': u'Sirepo', u'longName': u'Sirepo'}, u'route': {u'importFile': u'/import-file/?<simulation_type>', u'getApplicationData': u'/get-application-data/?<filename>', u'userState': u'/user-state', u'robotsTxt': u'/robots.txt', u'copyNonSessionSimulation': u'/copy-non-session-simulation', u'downloadFile': u'/download-file/<simulation_type>/<simulation_id>/<filename>', u'favicon': u'/favicon.ico', u'simulationSchema': u'/simulation-schema', u'pythonSource': u'/python-source/<simulation_type>/<simulation_id>/?<model>/?<report>', u'blueskyAuth': u'/bluesky-auth', u'copySimulation': u'/copy-simulation', u'updateFolder': u'/update-folder', u'listSimulations': u'/simulation-list', u'homePage': u'/about', u'findByName': u'/find-by-name/<simulation_type>/<application_mode>/<simulation_name>', u'oauthLogin': u'/login/<simulation_type>/<oauth_type>', u'simulationFrame': u'/simulation-frame/<frame_id>', u'comsol': u'/comsol', u'uploadFile': u'/upload-file/<simulation_type>/<simulation_id>/<file_type>', u'errorLogging': u'/error-logging', u'srUnit': u'/ srunit', u'deleteFile': u'/delete-file', u'oauthAuthorized': u'/oauth-authorized/<oauth_type>', u'listFiles': u'/file-list/<simulation_type>/<simulation_id>/<file_type>', u'srwLight': u'/light', u'saveSimulationData': u'/save-simulation', u'downloadDataFile': u'/download-data-file/<simulation_type>/<simulation_id>/<model>/<frame>/?<suffix>', u'runStatus': u'/run-status', u'importArchive': u'/import-archive', u'simulationData': u'/simulation/<simulation_type>/<simulation_id>/<pretty>/?<section>', u'deleteSimulation': u'/delete-simulation', u'runSimulation': u'/run-simulation', u'staticFile': u'/static/*<path_info>', u'getServerData': u'/get-server-data/?<id>', u'exportArchive': u'/export-archive/<simulation_type>/<simulation_id>/<filename>', u'comsolRegister': u'/comsol-register', u'newSimulation': u'/new-simulation', u'oauthLogout': u'/logout/<simulation_type>', u'runCancel': u'/run-cancel', u'root': u'/<simulation_type>'}, 'version': '20181220.231326'}

Schema common values, e.g. version

sirepo.simulation_db.SIMULATION_DATA_FILE = 'sirepo-data.json'

Simulation file name is globally unique to avoid collisions with simulation output

sirepo.simulation_db.STATIC_FOLDER = local('/home/docs/checkouts/readthedocs.org/user_builds/sirepo/checkouts/latest/sirepo/package_data/static')

Where server files and static files are found

sirepo.simulation_db.app_version()[source]

Force the version to be dynamic if running in dev channel

Returns:chronological version
Return type:str
sirepo.simulation_db.celery_queue(data)[source]

Which queue to execute simulation in

Parameters:data (dict) – simulation parameters
Returns:celery queue name
Return type:str
sirepo.simulation_db.cfg = OrderedMapping(nfs_sleep=0.5, nfs_tries=10)

configuration

sirepo.simulation_db.default_data(sim_type)[source]

New simulation base data

Parameters:sim_type (str) – simulation type
Returns:simulation data
Return type:dict
sirepo.simulation_db.delete_simulation(simulation_type, sid)[source]

Deletes the simulation’s directory.

sirepo.simulation_db.examples(app)[source]
sirepo.simulation_db.find_global_simulation(sim_type, sid, checked=False)[source]
sirepo.simulation_db.fixup_old_data(data, force=False)[source]

Upgrade data to latest schema and updates version.

Parameters:
  • data (dict) – to be updated (destructively)
  • force (bool) – force validation
Returns:

upgraded data bool: True if data changed

Return type:

dict

sirepo.simulation_db.generate_json(data, pretty=False)[source]

Convert data to JSON to be send back to client

Use only for responses. Use :func:write_json to save. :param data: what to format :type data: dict :param pretty: pretty print [False] :type pretty: bool

Returns:formatted data
Return type:str
sirepo.simulation_db.get_schema(sim_type)[source]
sirepo.simulation_db.hack_nfs_write_status(status, run_dir)[source]

Verify status file exists before writing.

NFS doesn’t propagate files immediately so there is a race condition when the celery worker starts. This file handles this case.

Parameters:
  • status (str) – pending, running, completed, canceled
  • run_dir (py.path) – where to write the file
sirepo.simulation_db.init_by_server(app)[source]

Avoid circular import by explicit call from sirepo.server.

Parameters:app (Flask) – flask instance
sirepo.simulation_db.is_parallel(data)[source]

Is this report a parallel (long) simulation?

Parameters:data (dict) – report and models
Returns:True if parallel job
Return type:bool
sirepo.simulation_db.iterate_simulation_datafiles(simulation_type, op, search=None)[source]
sirepo.simulation_db.job_id(data)[source]

A Job is a simulation and report name.

A jid is words and dashes.

Parameters:data (dict) – extract sid and report
Returns:unique name
Return type:str
sirepo.simulation_db.json_filename(filename, run_dir=None)[source]

Append JSON_SUFFIX if necessary and convert to str

Parameters:
  • filename (py.path or str) – to convert
  • run_dir (py.path) – which directory to joing
Returns:

filename.json

Return type:

py.path

sirepo.simulation_db.json_load(*args, **kwargs)[source]
sirepo.simulation_db.lib_dir_from_sim_dir(sim_dir)[source]

Path to lib dir from simulation dir

Parameters:sim_dir (py.path) – simulation dir
Returns:directory name
Return type:py.path
sirepo.simulation_db.move_user_simulations(to_uid)[source]

Moves all non-example simulations for the current session into the target user’s dir.

sirepo.simulation_db.open_json_file(sim_type, path=None, sid=None, fixup=True)[source]

Read a db file and return result

Parameters:
  • sim_type (str) – simulation type (app)
  • path (py.path.local) – where to read the file
  • sid (str) – simulation id
Returns:

data

Return type:

dict

Raises:

CopyRedirect – if the simulation is in another user’s

sirepo.simulation_db.parse_sid(data)[source]

Extract id from data

Parameters:data (dict) – models or request
Returns:simulationId from data
Return type:str
sirepo.simulation_db.parse_sim_ser(data)[source]

Extract simulationStatus from data

Parameters:data (dict) – models or request
Returns:simulationSerial
Return type:int
sirepo.simulation_db.poll_seconds(data)[source]

Client poll period for simulation status

TODO(robnagler) needs to be encapsulated

Parameters:data (dict) – must container report name
Returns:number of seconds to poll
Return type:int
sirepo.simulation_db.prepare_simulation(data)[source]

Create and install files, update parameters, and generate command.

Copies files into the simulation directory (run_dir). Updates the parameters in data and save. Generate the pkcli command to pass to task runner.

Parameters:data (dict) – report and model parameters
Returns:pkcli command, simulation directory
Return type:list, py.path
sirepo.simulation_db.process_simulation_list(res, path, data)[source]
sirepo.simulation_db.read_json(filename)[source]

Read data from json file

Parameters:filename (py.path or str) – will append JSON_SUFFIX if necessary
Returns:json converted to python
Return type:object
sirepo.simulation_db.read_result(run_dir)[source]

Read result data file from simulation

Parameters:run_dir (py.path) – where to find output
Returns:result or describes error
Return type:dict
sirepo.simulation_db.read_simulation_json(sim_type, *args, **kwargs)[source]

Calls open_json_file and fixes up data, possibly saving

Parameters:sim_type (str) – simulation type
Returns:simulation data
Return type:data (dict)
sirepo.simulation_db.read_status(run_dir)[source]

Read status from simulation dir

Parameters:run_dir (py.path) – where to read
sirepo.simulation_db.report_info(data)[source]

Read the run_dir and return cached_data.

Only a hit if the models between data and cache match exactly. Otherwise, return cached data if it’s there and valid.

Parameters:data (dict) – parameters identifying run_dir and models or reportParametersHash
Returns:report parameters and hashes
Return type:Dict
sirepo.simulation_db.save_new_example(data)[source]
sirepo.simulation_db.save_new_simulation(data, do_validate=True)[source]
sirepo.simulation_db.save_simulation_json(data, do_validate=True)[source]

Prepare data and save to json db

Parameters:data (dict) – what to write (contains simulationId)
sirepo.simulation_db.sim_data_file(sim_type, sim_id)[source]

Simulation data file name

Parameters:
  • sim_type (str) – simulation type
  • sim_id (str) – simulation id
Returns:

simulation path

Return type:

py.path.local

sirepo.simulation_db.simulation_dir(simulation_type, sid=None)[source]

Generates simulation directory from sid and simulation_type

Parameters:
  • simulation_type (str) – srw, warppba, …
  • sid (str) – simulation id (optional)
sirepo.simulation_db.simulation_lib_dir(simulation_type)[source]

String name for user library dir

Parameters:simulation_type – which app is this for
Returns:directory name
Return type:py.path
sirepo.simulation_db.simulation_run_dir(data, remove_dir=False)[source]

Where to run the simulation

Parameters:
  • data (dict) – contains simulationType and simulationId
  • remove_dir (bool) – remove the directory [False]
Returns:

directory to run

Return type:

py.path

sirepo.simulation_db.static_file_path(file_dir, file_name)[source]

Absolute path to a static file For requesting static files (hence a public interface)

Parameters:
  • file_dir (str) – directory in package_data/static
  • file_name (str) – name of the file
Returns:

absolute path of the file

Return type:

py.path

sirepo.simulation_db.static_libs()[source]
sirepo.simulation_db.tmp_dir()[source]

Generates new, temporary directory

Returns:directory to use for temporary work
Return type:py.path
sirepo.simulation_db.uid_from_dir_name(dir_name)[source]

Extra user id from user_dir_name

Parameters:dir_name (py.path) – must be top level user dir or sim_dir
Returns:user id
Return type:str
sirepo.simulation_db.user_dir_name(uid=None)[source]

String name for user name

Parameters:uid (str) – properly formated user name (optional)
Returns:directory name
Return type:py.path
sirepo.simulation_db.validate_serial(req_data)[source]

Verify serial in data validates

Parameters:req_data (dict) – request with serial and possibly models
Returns:None if all ok, or json response (bad)
Return type:object
sirepo.simulation_db.verify_app_directory(simulation_type)[source]

Ensure the app directory is present. If not, create it and add example files.

sirepo.simulation_db.write_json(filename, data)[source]

Write data as json to filename

Parameters:filename (py.path or str) – will append JSON_SUFFIX if necessary
sirepo.simulation_db.write_result(result, run_dir=None)[source]

Write simulation result to standard output.

Parameters:
  • result (dict) – will set state to completed
  • run_dir (py.path) – Defaults to current dir
sirepo.simulation_db.write_status(status, run_dir)[source]

Write status to simulation

Parameters:
  • status (str) – pending, running, completed, canceled
  • run_dir (py.path) – where to write the file

sirepo.sirepo_console module

SiRepo front-end command line for pykern.pkcli.

Example:

copyright:Copyright (c) 2015 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.sirepo_console.main()[source]

sirepo.srunit module

Support for unit tests

copyright:Copyright (c) 2016 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.srunit.flask_client(cfg=None)[source]

Return FlaskClient with easy access methods.

Creates a new run directory every test file so can assume sharing of state on the server within a file (module).

Two methods of interest: sr_post and sr_get.

Parameters:cfg (dict) – extra configuration for reset_state_for_testing
Returns:for local requests to Flask server
Return type:FlaskClient
sirepo.srunit.init_user_db()[source]

Force a request that creates a user in db

sirepo.srunit.server = None

import sirepo.server

sirepo.srunit.test_in_request(op, cfg=None, before_request=None, headers=None, want_cookie=True)[source]

sirepo.uri_router module

Handles dispatching of uris to server.api_* functions

copyright:Copyright (c) 2017 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
exception sirepo.uri_router.NotFound(log_fmt, *args, **kwargs)[source]

Bases: exceptions.Exception

Raised to indicate page not found exception (404)

sirepo.uri_router.format_uri(simulation_type, application_mode, simulation_id, app_schema)[source]
sirepo.uri_router.init(app, uwsgi)[source]

Convert route map to dispatchable callables

Initializes _uri_to_route and adds a single flask route (_dispatch) to dispatch based on the map.

Parameters:
  • app (Flask) – flask app
  • uwsgi (WSGIApp) – uwsgi server object (or None)
sirepo.uri_router.register_api_module()[source]

Add caller_module to the list of modules which implements apis.

The module must have methods: api_XXX which do not collide with other apis.

sirepo.uri_router.srunit_uri = None

route for sirepo.srunit

sirepo.uri_router.uri_for_api(api_name, params=None, external=True)[source]

Generate uri for api method

Parameters:
  • api_name (str) – full name of api
  • params (str) – paramters to pass to uri
  • external (bool) – external uri? [True]
Returns:

formmatted external URI

Return type:

str

sirepo.util module

Utilities for requests

copyright:Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.util.err(obj, format='', *args, **kwargs)[source]
sirepo.util.raise_bad_request(*args, **kwargs)[source]
sirepo.util.raise_forbidden(*args, **kwargs)[source]
sirepo.util.raise_not_found(*args, **kwargs)[source]
sirepo.util.raise_unauthorized(*args, **kwargs)[source]
sirepo.util.random_base62(length=32)[source]

Returns a safe string of sufficient length to be a nonce

Parameters:length (int) – how long to make the base62 string [32]
Returns:random base62 characters
Return type:str

Module contents

sirepo package

copyright:Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html