Utilities

brain.utils.general.general.build_routemap(app)[source]

Builds a Flask Web App’s dictionary of routes

Constructs a dictionary containing all the routes defined inside a given Flask Web App. The route endpoints are deconstructed into a set of nested dictionaries of the form [blueprint][endpoint], which contains a methods and a url key. The url key returns the full route path.

E.g. the API route to get a cube, which has a name “getCube” is expressed as [‘api’][‘getCube’]. To access the url, [‘api’][‘getCube’][‘url’] returns “/marvin/api/cubes/{name}/”

Parameters

app (Flask Application) – The Flask app to extract routes from

Returns

A dict of all routes

brain.utils.general.general.collaboration_authenticate(username=None, password=None, verbose=None)[source]

Authenticate with Trac using Collaboration

Authenticate using the SDSS collaboration python package

Parameters
  • username (str) – The Trac username

  • password (str) – The Trac user password

Returns

A dictionary of user info specifying if the user has authenticated and is valid

brain.utils.general.general.compress_data(data, compress_with=None, uncompress=None)[source]

Compress data via json or msgpack

Parameters
  • data (obj) – The input data to compress or uncompress

  • compress_with (str) – Compression algorithm. Defaults to config.compression.

  • uncompress (bool) – If True, uncompresses the data instead of compressing. Default is False

Returns

Data compressed with with json or msgpack

brain.utils.general.general.convertIvarToErr(ivar)[source]

Converts a list of inverse variance into an a list of standard errors

brain.utils.general.general.getDbMachine()[source]

Get the machine that the app is running on.

This determines correct database and app configuration

brain.utils.general.general.get_db_user(username, password, dbsession=None, user_model=None, request=None)[source]

Get a User from a database session

Gets a User object from the database User table. If the User does not exists, adds the User.

Parameters
  • username (str) – The user id

  • password (str) – The user password

  • dbsession (db.Session) – The SQLAlchemy database session object

  • user_model (Model) – The SQLALchemy User ModelClass

  • request (Request) – The Flask request object

Returns

The database User object.

brain.utils.general.general.get_yaml_loader()[source]

Get a yaml loader based on the yaml package version

brain.utils.general.general.inspection_authenticate(session, username=None, password=None)[source]

Authenticate with Trac using Inspection

Deprecated since version 2.3.0.

Use brain.utils.general.collaboration_authenticate instead.

Parameters
  • session (dict) – A dict or Flask session object to collect parameters

  • username (str) – The Trac username

  • password (str) – The Trac user password

Returns

A dictionary of user info specifying if the user has authenticated and is valid

brain.utils.general.general.merge(user, default)[source]

Merges a user configuration with the default one.

Merges two dictionaries, replacing default values of similar matching keys from user.

Parameters
  • user (dict) – A user defined dictionary

  • default (dict) –

Returns

A new merged dictionary

brain.utils.general.general.uncompress_data(data, uncompress_with=None)[source]

Compress data via json or msgpack

Parameters
  • data (obj) – The data to compress

  • uncompress_with (str) – Compression algorithm. Defaults to config.compression.

Returns

Data compressed with with json or msgpack

brain.utils.general.general.validate_user(username, password, htpassfile=None, request=None)[source]

Validate the User with htpassfile or Trac

Tries to validate a user first with a user login from the htpassfile, and second from a Trac wiki account.

Parameters
  • username (str) – The login user id

  • password (str) – The login user password

  • htpassfile (str) – Optional. The full path to an htpassfile.

  • request (Request) – The Flask request object

Returns

A tuple of (boolean if the user is valid, the username, and the results dictionary)