managers Package¶
managers
Package¶
Classes that manage resources (models, tools, etc.) by using the current Transaction.
Encapsulates the intersection of trans (or trans.sa_session), models, and Controllers.
- Responsibilities:
model operations that involve the trans/sa_session (CRUD) security:
ownership, accessibility- common aspect-oriented operations via new mixins:
- sharable, annotatable, tagable, ratable
- Not responsible for:
- encoding/decoding ids any http gobblygook formatting of returned data (always python structures) formatting of raised errors
- The goal is to have Controllers only handle:
- query-string/payload parsing and encoding/decoding ids http return formatting
- and:
- control, improve namespacing in Controllers DRY for Controller ops (define here - use in both UI/API Controllers)
In other words, ‘Business logic’ independent of web transactions/user context (trans) should be pushed into models - but logic that requires the context trans should be placed under this module.
api_keys
Module¶
base
Module¶
Keeps the older BaseController security and fetching methods and also defines a base ModelManager, ModelSerializer, and ModelDeserializer.
ModelManagers are used for operations on models that occur outside the scope of a single model object, such as:
- object creation
- object lookup
- interactions between 2+ objects of different model classes
(Since these were to replace model Mixins from web/framework/base/controller.py the rule of thumb used there also generally has been applied here: if it uses the trans or sa_session, put it in a manager and not the model.)
ModelSerializers allow flexible conversion of model objects to dictionaries. They control what keys are sent, how values are simplified, can remap keys, and allow both predefined and user controlled key sets.
ModelDeserializers control how a model validates and process an incoming attribute change to a model object.
-
class
galaxy.managers.base.
ModelDeserializer
(app)[source]¶ Bases:
object
An object that converts an incoming serialized dict into values that can be directly assigned to an item’s attributes and assigns them.
-
add_deserializers
()[source]¶ Register a map of attribute keys -> functions that will deserialize data into attributes to be assigned to the item.
-
default_deserializer
(item, key, val, **context)[source]¶ If the incoming val is different than the item value change it and, in either case, return the value.
-
deserialize
(item, data, flush=True, **context)[source]¶ Convert an incoming serialized dict into values that can be directly assigned to an item’s attributes and assign them
-
deserialize_genome_build
(item, key, val, **context)[source]¶ Make sure val is a valid dbkey and assign it.
-
model_manager_class
= None¶ the class used to create this deserializer’s generically accessible model_manager
-
-
exception
galaxy.managers.base.
ModelDeserializingError
(err_msg=None, type='info', **extra_error_info)[source]¶ Bases:
galaxy.exceptions.ObjectAttributeInvalidException
Thrown when an incoming value isn’t usable by the model (bad type, out of range, etc.)
-
class
galaxy.managers.base.
ModelFilterParser
(app)[source]¶ Bases:
object
Converts string tuples (partially converted query string params) of attr, op, val into either:
- ORM based filters (filters that can be applied by the ORM at the SQL
level) or - functional filters (filters that use derived values or values not within the SQL tables)
These filters can then be applied to queries.
This abstraction allows ‘smarter’ application of limit and offset at either the SQL level or the generator/list level based on the presence of functional filters. In other words, if no functional filters are present, limit and offset may be applied at the SQL level. If functional filters are present, limit and offset need to applied at the list level.
These might be safely be replaced in the future by creating SQLAlchemy hybrid properties or more thoroughly mapping derived values.
-
UNDERSCORED_OPS
= ('lt', 'le', 'eq', 'ne', 'ge', 'gt')¶ these are the easier/shorter string equivalents to the python operator fn names that need ‘__’ around them
-
fn_filter_parsers
= None¶ dictionary containing parsing data for functional filters - applied after a query is made
-
model_class
= None¶ model class
-
orm_filter_parsers
= None¶ - dictionary containing parsing data for ORM/SQLAlchemy-based filters
- over potentially expensive queries
-
parse_filter
(attr, op, val)[source]¶ Attempt to parse filter as a custom/fn filter, then an orm filter, and if neither work - raise an error.
Raises exceptions.RequestParameterInvalidException: if no functional or orm filter can be parsed.
-
class
galaxy.managers.base.
ModelManager
(app)[source]¶ Bases:
object
Base class for all model/resource managers.
Provides common queries and CRUD operations as a (hopefully) light layer over the ORM.
-
associate
(associate_with, item, foreign_key_name=None)[source]¶ Generically associate item with associate_with based on foreign_key_name.
-
by_ids
(ids, filters=None, **kwargs)[source]¶ Returns an in-order list of models with the matching ids in ids.
-
foreign_key_name
= None¶
-
list
(filters=None, order_by=None, limit=None, offset=None, **kwargs)[source]¶ Returns all objects matching the given filters
-
model_class
¶ alias of
object
-
query
(eagerloads=True, filters=None, order_by=None, limit=None, offset=None, **kwargs)[source]¶ Return a basic query from model_class, filters, order_by, and limit and offset.
Set eagerloads to False to disable them for this query.
-
-
class
galaxy.managers.base.
ModelSerializer
(app)[source]¶ Bases:
object
Turns models into JSONable dicts.
Maintains a map of requestable keys and the Callable() serializer functions that should be called for those keys. E.g. { ‘x’ : lambda item, key: item.x, ... }
Note: if a key to serialize is not listed in the Serializer.serializable_keyset or serializers, it will not be returned.
- To serialize call:
- my_serializer = MySerializer( app ) ... keys_to_serialize = [ ‘id’, ‘name’, ‘attr1’, ‘attr2’, ... ] item_dict = MySerializer.serialize( my_item, keys_to_serialize )
-
add_serializers
()[source]¶ Register a map of attribute keys -> serializing functions that will serialize the attribute.
-
add_view
(view_name, key_list, include_keys_from=None)[source]¶ Add the list of serializable attributes key_list to the serializer’s view dictionary under the key view_name.
If include_keys_from is a proper view name, extend key_list by the list in that view.
-
serialize
(item, keys, **context)[source]¶ Serialize the model item to a dictionary.
Given model item and the list keys, create and return a dictionary built from each key in keys that also exists in serializers and values of calling the keyed/named serializers on item.
-
serialize_to_view
(item, view=None, keys=None, default_view=None, **context)[source]¶ Use a predefined list of keys (the string view) and any additional keys listed in keys.
- The combinations can be:
- view only: return those keys listed in the named view keys only: return those keys listed no view or keys: use the default_view if any view and keys: combine both into one list of keys
-
skip
(msg='skipped')[source]¶ To be called from inside a serializer to skip it.
Handy for config checks, information hiding, etc.
-
static
url_for
(*args, **kargs)¶ ‘service’ to use for getting urls - use class var to allow overriding when testing
-
exception
galaxy.managers.base.
ModelSerializingError
(err_msg=None, type='info', **extra_error_info)[source]¶ Bases:
galaxy.exceptions.InternalServerError
Thrown when request model values can’t be serialized
-
class
galaxy.managers.base.
ModelValidator
(app, *args, **kwargs)[source]¶ Bases:
object
An object that inspects a dictionary (generally meant to be a set of new/updated values for the model) and raises an error if a value is not acceptable.
-
exception
galaxy.managers.base.
SkipAttribute
[source]¶ Bases:
exceptions.Exception
Raise this inside a serializer to prevent the returned dictionary from having a the associated key or value for this attribute.
-
galaxy.managers.base.
get_class
(class_name)[source]¶ Returns the class object that a string denotes. Without this method, we’d have to do eval(<class_name>).
-
galaxy.managers.base.
get_object
(trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None)[source]¶ Convenience method to get a model object with the specified checks. This is a generic method for dealing with objects uniformly from the older controller mixin code - however whenever possible the managers for a particular model should be used to load objects.
-
galaxy.managers.base.
security_check
(trans, item, check_ownership=False, check_accessible=False)[source]¶ Security checks for an item: checks if (a) user owns item or (b) item is accessible to user. This is a generic method for dealing with objects uniformly from the older controller mixin code - however whenever possible the managers for a particular model should be used to perform security checks.
citations
Module¶
-
class
galaxy.managers.citations.
DoiCitation
(elem, directory, citation_manager)[source]¶ Bases:
galaxy.managers.citations.BaseCitation
-
BIBTEX_UNSET
= <object object>¶
-
collections
Module¶
-
class
galaxy.managers.collections.
DatasetCollectionManager
(app)[source]¶ Bases:
object
Abstraction for interfacing with dataset collections instance - ideally abstarcts out model and plugin details.
-
ELEMENTS_UNINITIALIZED
= <object object>¶
-
create
(trans, parent, name, collection_type, element_identifiers=None, elements=None, implicit_collection_info=None)[source]¶
-
collections_util
Module¶
-
galaxy.managers.collections_util.
api_payload_to_create_params
(payload)[source]¶ Cleanup API payload to pass into dataset_collections.
context
Module¶
Mixins for transaction-like objects.
-
class
galaxy.managers.context.
ProvidesAppContext
[source]¶ Bases:
object
For transaction-like objects to provide Galaxy convience layer for database and event handling.
Mixed in class must provide app property.
-
install_model
¶
-
log_action
(user=None, action=None, context=None, params=None)[source]¶ Application-level logging of user actions.
-
log_event
(message, tool_id=None, **kwargs)[source]¶ Application level logging. Still needs fleshing out (log levels and such) Logging events is a config setting - if False, do not log.
-
model
¶
-
sa_session
¶ Returns a SQLAlchemy session – currently just gets the current session from the threadlocal session context, but this is provided to allow migration toward a more SQLAlchemy 0.4 style of use.
-
-
class
galaxy.managers.context.
ProvidesHistoryContext
[source]¶ Bases:
object
For transaction-like objects to provide Galaxy convience layer for reasoning about histories.
Mixed in class must provide user, history, and app properties.
-
db_builds
¶ Returns the builds defined by galaxy and the builds defined by the user (chromInfo in history).
-
folders
Module¶
Manager and Serializer for Library Folders.
-
class
galaxy.managers.folders.
FolderManager
[source]¶ Bases:
object
Interface/service object for interacting with folders.
-
can_add_item
(trans, folder)[source]¶ Return true if the user has permissions to add item to the given folder.
-
check_accessible
(trans, folder)[source]¶ Check whether the folder is accessible to current user. By default every folder is accessible (contents have their own permissions).
-
check_manageable
(trans, folder)[source]¶ Check whether the user can manage the folder.
Returns: the original folder Return type: LibraryFolder Raises: AuthenticationRequired, InsufficientPermissionsException
-
create
(trans, parent_folder_id, new_folder_name, new_folder_description='')[source]¶ Create a new folder under the given folder.
Parameters: - parent_folder_id (int) – decoded id
- new_folder_name (str) – name of the new folder
- new_folder_description (str) – description of the folder (optional, defaults to empty string)
Returns: the new folder
Return type: Raises: InsufficientPermissionsException
-
cut_and_decode
(trans, encoded_folder_id)[source]¶ Cuts the folder prefix (the prepended ‘F’) and returns the decoded id.
Parameters: encoded_folder_id (string) – encoded id of the Folder object Returns: decoded Folder id Return type: int
-
cut_the_prefix
(encoded_folder_id)[source]¶ Remove the prefix from the encoded folder id.
Parameters: encoded_folder_id (string) – encoded id of the Folder object with ‘F’ prepended Returns: encoded Folder id without the ‘F’ prefix Return type: string Raises: MalformedId
-
decode_folder_id
(trans, encoded_folder_id)[source]¶ Decode the folder id given that it has already lost the prefixed ‘F’.
Parameters: encoded_folder_id (string) – encoded id of the Folder object Returns: decoded Folder id Return type: int Raises: MalformedId
-
delete
(trans, folder, undelete=False)[source]¶ Mark given folder deleted/undeleted based on the flag.
Parameters: - folder (LibraryFolder) – the model object
- undelete (Bool) – flag whether to delete (when False) or undelete
Returns: the folder
Return type: Raises: ItemAccessibilityException
-
get
(trans, decoded_folder_id, check_manageable=False, check_accessible=True)[source]¶ Get the folder from the DB.
Parameters: Returns: the requested folder
Return type: Raises: InconsistentDatabase, RequestParameterInvalidException, InternalServerError
-
get_current_roles
(trans, folder)[source]¶ Find all roles currently connected to relevant permissions on the folder.
Parameters: folder (LibraryFolder) – the model object Returns: dict of current roles for all available permission types Return type: dictionary
-
get_folder_dict
(trans, folder)[source]¶ Return folder data in the form of a dictionary.
Parameters: folder (LibraryFolder) – folder item Returns: dict with data about the folder Return type: dictionary
-
secure
(trans, folder, check_manageable=True, check_accessible=True)[source]¶ Check if (a) user can manage folder or (b) folder is accessible to user.
Parameters: - folder (LibraryFolder) – folder item
- check_manageable (bool) – flag whether to check that user can manage item
- check_accessible (bool) – flag whether to check that user can access item
Returns: the original folder
Return type:
-
hdas
Module¶
Manager and Serializer for HDAs.
HistoryDatasetAssociations (HDAs) are datasets contained or created in a history.
-
class
galaxy.managers.hdas.
HDADeserializer
(app)[source]¶ Bases:
galaxy.managers.datasets.DatasetAssociationDeserializer
,galaxy.managers.taggable.TaggableDeserializerMixin
,galaxy.managers.annotatable.AnnotatableDeserializerMixin
Interface/service object for validating and deserializing dictionaries into histories.
-
model_manager_class
¶ alias of
HDAManager
-
-
class
galaxy.managers.hdas.
HDAFilterParser
(app)[source]¶ Bases:
galaxy.managers.datasets.DatasetAssociationFilterParser
,galaxy.managers.taggable.TaggableFilterMixin
,galaxy.managers.annotatable.AnnotatableFilterMixin
-
model_class
¶ alias of
HistoryDatasetAssociation
-
-
class
galaxy.managers.hdas.
HDAManager
(app)[source]¶ Bases:
galaxy.managers.datasets.DatasetAssociationManager
,galaxy.managers.secured.OwnableManagerMixin
,galaxy.managers.taggable.TaggableManagerMixin
,galaxy.managers.annotatable.AnnotatableManagerMixin
Interface/service object for interacting with HDAs.
-
annotation_assoc
¶ alias of
HistoryDatasetAssociationAnnotationAssociation
-
create
(history=None, dataset=None, flush=True, **kwargs)[source]¶ Create a new hda optionally passing in it’s history and dataset.
..note: to explicitly set hid to None you must pass in hid=None, otherwise it will be automatically set.
-
data_conversion_status
(hda)[source]¶ Returns a message if an hda is not ready to be used in visualization.
-
foreign_key_name
= 'history_dataset_association'¶
-
is_accessible
(hda, user, **kwargs)[source]¶ Override to allow owners (those that own the associated history).
-
is_owner
(hda, user, current_history=None, **kwargs)[source]¶ Use history to see if current user owns HDA.
-
model_class
¶ alias of
HistoryDatasetAssociation
-
tag_assoc
¶ alias of
HistoryDatasetAssociationTagAssociation
-
-
class
galaxy.managers.hdas.
HDASerializer
(app)[source]¶ Bases:
galaxy.managers.datasets.DatasetAssociationSerializer
,galaxy.managers.taggable.TaggableSerializerMixin
,galaxy.managers.annotatable.AnnotatableSerializerMixin
-
serialize_display_apps
(hda, key, trans=None, **context)[source]¶ Return dictionary containing new-style display app urls.
-
histories
Module¶
Manager and Serializer for histories.
Histories are containers for datasets or dataset collections created (or copied) by users over the course of an analysis.
-
class
galaxy.managers.histories.
HistoryDeserializer
(app)[source]¶ Bases:
galaxy.managers.sharable.SharableModelDeserializer
,galaxy.managers.deletable.PurgableDeserializerMixin
Interface/service object for validating and deserializing dictionaries into histories.
-
model_manager_class
¶ alias of
HistoryManager
-
-
class
galaxy.managers.histories.
HistoryFilters
(app)[source]¶ Bases:
galaxy.managers.sharable.SharableModelFilters
,galaxy.managers.deletable.PurgableFiltersMixin
-
model_class
¶ alias of
History
-
-
class
galaxy.managers.histories.
HistoryManager
(app, *args, **kwargs)[source]¶ Bases:
galaxy.managers.sharable.SharableModelManager
,galaxy.managers.deletable.PurgableManagerMixin
-
annotation_assoc
¶ alias of
HistoryAnnotationAssociation
-
by_user
(user, current_history=None, **kwargs)[source]¶ Get all the histories for a given user (allowing anon users’ theirs) ordered by update time.
-
foreign_key_name
= 'history'¶
-
is_owner
(history, user, current_history=None, **kwargs)[source]¶ True if the current user is the owner of the given history.
-
model_class
¶ alias of
History
-
most_recent
(user, filters=None, current_history=None, **kwargs)[source]¶ Return the most recently update history for the user.
If user is anonymous, return the current history. If the user is anonymous and the current history is deleted, return None.
-
purge
(history, flush=True, **kwargs)[source]¶ Purge this history and all HDAs, Collections, and Datasets inside this history.
-
rating_assoc
¶ alias of
HistoryRatingAssociation
-
tag_assoc
¶ alias of
HistoryTagAssociation
alias of
HistoryUserShareAssociation
-
-
class
galaxy.managers.histories.
HistorySerializer
(app)[source]¶ Bases:
galaxy.managers.sharable.SharableModelSerializer
,galaxy.managers.deletable.PurgableSerializerMixin
Interface/service object for serializing histories into dictionaries.
-
SINGLE_CHAR_ABBR
= 'h'¶
-
serialize_history_state
(history, key, **context)[source]¶ Returns the history state based on the states of the HDAs it contains.
-
lddas
Module¶
libraries
Module¶
Manager and Serializer for libraries.
-
class
galaxy.managers.libraries.
LibraryManager
(*args, **kwargs)[source]¶ Bases:
object
Interface/service object for interacting with libraries.
-
delete
(trans, library, undelete=False)[source]¶ Mark given library deleted/undeleted based on the flag.
-
get
(trans, decoded_library_id, check_accessible=True)[source]¶ Get the library from the DB.
Parameters: Returns: the requested library
Return type:
-
get_current_roles
(trans, library)[source]¶ Load all permissions currently related to the given library.
Parameters: library (Library) – the model object Return type: dictionary Returns: dict of current roles for all available permission types
-
get_library_dict
(trans, library)[source]¶ Return library data in the form of a dictionary.
Parameters: library (Library) – library Returns: dict with data about the library Return type: dictionary
-
list
(trans, deleted=False)[source]¶ Return a list of libraries from the DB.
Parameters: deleted (boolean (optional)) – if True, show only deleted
libraries, if False show onlynon-deleted
Returns: query that will emit all accessible libraries Return type: sqlalchemy query
-
secure
(trans, library, check_accessible=True)[source]¶ Check if library is accessible to user.
Parameters: Returns: the original folder
Return type:
-
roles
Module¶
Manager and Serializer for Roles.
-
class
galaxy.managers.roles.
RoleManager
(app)[source]¶ Bases:
galaxy.managers.base.ModelManager
Business logic for roles.
-
foreign_key_name
= 'role'¶
-
get
(trans, decoded_role_id)[source]¶ Method loads the role from the DB based on the given role id.
Parameters: decoded_role_id (int) – id of the role to load from the DB Returns: the loaded Role object Return type: Role Raises: InconsistentDatabase, RequestParameterInvalidException, InternalServerError
-
group_assoc
¶ alias of
GroupRoleAssociation
-
model_class
¶ alias of
Role
-
user_assoc
¶ alias of
UserRoleAssociation
-
tags
Module¶
Bases:
object
Bases:
object
Manages CRUD operations related to tagging objects.
Apply tags to an item.
Delete tags from an item.
Returns community tags for an item.
Returns item id column in class’ item-tag association table.
Returns tag association class for item class.
Get a Tag object from a tag id.
Get a Tag object from a tag name (string).
Build a string from an item’s tags.
Returns true if item is has a given tag.
Returns a list of raw (tag-name, value) pairs derived from a string; method scrubs tag names and values as well. Return value is a dictionary where tag-names are keys.
Remove a tag from an item.
workflows
Module¶
-
class
galaxy.managers.workflows.
CreatedWorkflow
(stored_workflow, missing_tools)¶ Bases:
tuple
-
missing_tools
¶ Alias for field number 1
-
stored_workflow
¶ Alias for field number 0
-
-
class
galaxy.managers.workflows.
WorkflowContentsManager
[source]¶ Bases:
galaxy.model.item_attrs.UsesAnnotations
-
workflow_to_dict
(trans, stored, style='export')[source]¶ Export the workflow contents to a dictionary ready for JSON-ification and to be sent out via API for instance. There are three styles of export allowed ‘export’, ‘instance’, and ‘editor’. The Galaxy team will do it best to preserve the backward compatibility of the ‘export’ stye - this is the export method meant to be portable across Galaxy instances and over time. The ‘editor’ style is subject to rapid and unannounced changes. The ‘instance’ export option describes the workflow in a context more tied to the current Galaxy instance and includes fields like ‘url’ and ‘url’ and actual unencoded step ids instead of ‘order_index’.
-
-
class
galaxy.managers.workflows.
WorkflowsManager
(app)[source]¶ Bases:
object
Handle CRUD type operaitons related to workflows. More interesting stuff regarding workflow execution, step sorting, etc... can be found in the galaxy.workflow module.