datacatalog.linkedstores.experiment_design.mappings.gdrive package

Submodules

datacatalog.linkedstores.experiment_design.mappings.gdrive.build_list module

datacatalog.linkedstores.experiment_design.mappings.gdrive.errors module

exception datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.ExperimentReferenceError[source]

Bases: Exception

exception datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.GoogleSheetsError[source]

Bases: datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.ExperimentReferenceError

exception datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.IncorrectConfiguration[source]

Bases: datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.ExperimentReferenceError

exception datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.LookupNotPopulated[source]

Bases: datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.ExperimentReferenceError

exception datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.MappingNotFound[source]

Bases: datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.ExperimentReferenceError

exception datacatalog.linkedstores.experiment_design.mappings.gdrive.errors.UnsupportedMapping[source]

Bases: NotImplementedError

datacatalog.linkedstores.experiment_design.mappings.gdrive.gdrive module

class datacatalog.linkedstores.experiment_design.mappings.gdrive.gdrive.ExperimentReferenceMapping(mapper_config, google_client=None, google_client_path=None)[source]

Bases: object

Synchronizable mapping between ExperimentDesign and a Google Document

__init__(mapper_config, google_client=None, google_client_path=None)[source]

Initialize connection to Google Drive API

Parameters:
  • mapper_config (dict) – A structured configuration dictionary
  • google_client (dict, optional) – A structured dictionary containing API credentials
  • google_client_path (str, optional) – Filesystem path to a file containing API credentials
Raises:

IncorrectConfiguration – Raised when mapper_config is incorrect

config = None

Value passed for mapping_config

encode_files(files_listing)[source]

Transform a Google Drive listing into ExperimentDesigns

Parameters:files_listing (list) – a listing from Google files API v3
Returns:List of ExperimentDesign dict objects
Return type:list
encode_title_as_id(textstring, stopwords=[], separator='-')[source]

Transform Google Document title into an identifier

Parameters:
  • textstring (str) – The title of a document
  • stopwords (list, optional) – List of stopwords to filter from encoded identifier
  • separator (str, optional) – Separator character for joining slugified words
Returns:

The slugified version of textstring

Return type:

str

failures = None

Cache of failed Google Drive API query responses

filescache = None

Cached lookups from Google Drive API queries

id_to_key(id, keyname)[source]

Get the value for a key associated with a given identifier

Parameters:
  • id (str) – One of the known set of document identifiers
  • keyname (str) – The name of the key whose value will be returned
Raises:
  • UnsupportedMapping – Occurs when keyname does not exist in the document
  • MappingNotFound – Occurs when id is not known
Returns:

The value of keyname in the ExperimentMapping identifier by id

Return type:

object

id_to_title(id)[source]

Get the human-readable title associated with an identifier

id_to_uri(id)[source]

Get the URI associated with an identifier

populate()[source]

Populate the mapping cache

This must be done explicitly after __init__` to avoid thrashing the API client.

Raises:GoogleSheetsError – Occurs if connection or query to Google fails
Returns:Returns self so that populate can be chained to another service call
Return type:object
ready = None

Semaphore marking the Google Drive API client as ready

title_to_id(title)[source]
title_to_uri(title)[source]
token = None

Google API client

tokenpath = None

Path to API credentials file

uri_to_id(uri)[source]

Get the document identifier associated with a reference URI

uri_to_key(uri, keyname)[source]

Get the value for a key associated with a reference URI

Parameters:
  • uri (str) – One of the known set of Google Drive document URIs
  • keyname (str) – The name of the key whose value will be returned
Raises:
  • UnsupportedMapping – Occurs when uri is not a valid URI or keyname does not exist in document
  • MappingNotFound – Occurs when mapping is not successful
Returns:

The value of keyname in the ExperimentMapping identifier by uri

Return type:

object

uri_to_title(uri)[source]

Get the title associated with a reference URI

datacatalog.linkedstores.experiment_design.mappings.gdrive.google_utils module

datacatalog.linkedstores.experiment_design.mappings.gdrive.google_utils.get_drive_service(credential_path='service_account.json', scopes=['https://www.googleapis.com/auth/drive.metadata.readonly'])[source]

Set up interface for interacting with Google Drive.

Relies on service account credentials

datacatalog.linkedstores.experiment_design.mappings.gdrive.google_utils.get_files(filename, folder_id, drive_service=None)[source]

Return a list of dicts representing the matches to the file.

datacatalog.linkedstores.experiment_design.mappings.gdrive.quickstart_service module

datacatalog.linkedstores.experiment_design.mappings.gdrive.quickstart_service.main()[source]