galaxy.web.base package

Submodules

galaxy.web.base.controller module

Contains functionality needed in every web interface

class galaxy.web.base.controller.BaseController(app)[source]

Bases: object

Base class for Galaxy web application controllers.

__init__(app)[source]

Initialize an interface for application ‘app’

get_toolbox()[source]

Returns the application toolbox

get_class(class_name)[source]

Returns the class object that a string denotes. Without this method, we’d have to do eval(<class_name>).

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.

get_user(trans, id, check_ownership=False, check_accessible=False, deleted=None)[source]
get_group(trans, id, check_ownership=False, check_accessible=False, deleted=None)[source]
get_role(trans, id, check_ownership=False, check_accessible=False, deleted=None)[source]
decode_id(id)[source]
encode_all_ids(trans, rval, recursive=False)[source]

Encodes all integer values in the dict rval whose keys are ‘id’ or end with ‘_id’

It might be useful to turn this in to a decorator

parse_filter_params(qdict, filter_attr_key='q', filter_value_key='qv', attr_op_split_char='-')[source]
parse_limit_offset(qdict)[source]
galaxy.web.base.controller.Root

alias of BaseController

class galaxy.web.base.controller.BaseUIController(app)[source]

Bases: galaxy.web.base.controller.BaseController

get_object(trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None)[source]
class galaxy.web.base.controller.BaseAPIController(app)[source]

Bases: galaxy.web.base.controller.BaseController

get_object(trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None)[source]
validate_in_users_and_groups(trans, payload)[source]

For convenience, in_users and in_groups can be encoded IDs or emails/group names in the API.

not_implemented(trans, **kwd)[source]
class galaxy.web.base.controller.JSAppLauncher(app)[source]

Bases: galaxy.web.base.controller.BaseUIController

A controller that launches JavaScript web applications.

JS_APP_MAKO_FILEPATH = '/js-app.mako'

path to js app template

DEFAULT_ENTRY_FN = 'app'

window-scoped js function to call to start the app (will be passed options, bootstrapped)

USER_BOOTSTRAP_KEYS = ('id', 'email', 'username', 'is_admin', 'tags_used', 'requests', 'total_disk_usage', 'nice_total_disk_usage', 'quota_percent', 'preferences')

keys used when serializing current user for bootstrapped data

__init__(app)[source]
template(trans, app_name, entry_fn='app', options=None, bootstrapped_data=None, masthead=True, **additional_options)[source]

Render and return the single page mako template that starts the app.

app_name (string): the first portion of the webpack bundle to as the app. entry_fn (string): the name of the window-scope function that starts the

app. Defaults to ‘app’.
bootstrapped_data (dict): (optional) update containing any more data
the app may need.
masthead (boolean): (optional, default=True) include masthead elements in
the initial page dom.

additional_options (kwargs): update to the options sent to the app.

class galaxy.web.base.controller.Datatype(extension, dtype, type_extension, mimetype, display_in_upload)[source]

Bases: object

Used for storing in-memory list of datatypes currently in the datatypes registry.

__init__(extension, dtype, type_extension, mimetype, display_in_upload)[source]
class galaxy.web.base.controller.CreatesUsersMixin[source]

Mixin centralizing logic for user creation between web and API controller.

Web controller handles additional features such e-mail subscription, activation, user forms, etc.... API created users are much more vanilla for the time being.

create_user(trans, email, username, password)[source]
class galaxy.web.base.controller.CreatesApiKeysMixin[source]

Mixing centralizing logic for creating API keys for user objects.

Deprecated - please use api_keys.ApiKeyManager for new development.

create_api_key(trans, user)[source]
class galaxy.web.base.controller.SharableItemSecurityMixin[source]

Mixin for handling security for sharable items.

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.

class galaxy.web.base.controller.ExportsHistoryMixin[source]
serve_ready_history_export(trans, jeha)[source]
queue_history_export(trans, history, gzip=True, include_hidden=False, include_deleted=False)[source]
class galaxy.web.base.controller.ImportsHistoryMixin[source]
queue_history_import(trans, archive_type, archive_source)[source]
class galaxy.web.base.controller.UsesLibraryMixin[source]
get_library(trans, id, check_ownership=False, check_accessible=True)[source]
class galaxy.web.base.controller.UsesLibraryMixinItems[source]

Bases: galaxy.web.base.controller.SharableItemSecurityMixin

get_library_folder(trans, id, check_ownership=False, check_accessible=True)[source]
get_library_dataset_dataset_association(trans, id, check_ownership=False, check_accessible=True)[source]
get_library_dataset(trans, id, check_ownership=False, check_accessible=True)[source]
can_current_user_add_to_library_item(trans, item)[source]
check_user_can_add_to_library_item(trans, item, check_accessible=True)[source]

Raise exception if user cannot add to the specified library item (i.e. Folder). Can set check_accessible to False if folder was loaded with this check.

copy_hda_to_library_folder(trans, hda, library_folder, roles=None, ldda_message='', element_identifier=None)[source]
class galaxy.web.base.controller.UsesVisualizationMixin[source]

Bases: galaxy.web.base.controller.UsesLibraryMixinItems

Mixin for controllers that use Visualization objects.

viz_types = ['trackster']
get_visualization(trans, id, check_ownership=True, check_accessible=False)[source]

Get a Visualization from the database by id, verifying ownership.

get_visualizations_by_user(trans, user, order_by=None, query_only=False)[source]

Return query or query results of visualizations filtered by a user.

Set order_by to a column or list of columns to change the order returned. Defaults to DEFAULT_ORDER_BY. Set query_only to return just the query for further filtering or processing.

get_visualizations_shared_with_user(trans, user, order_by=None, query_only=False)[source]

Return query or query results for visualizations shared with the given user.

Set order_by to a column or list of columns to change the order returned. Defaults to DEFAULT_ORDER_BY. Set query_only to return just the query for further filtering or processing.

get_published_visualizations(trans, exclude_user=None, order_by=None, query_only=False)[source]

Return query or query results for published visualizations optionally excluding the user in exclude_user.

Set order_by to a column or list of columns to change the order returned. Defaults to DEFAULT_ORDER_BY. Set query_only to return just the query for further filtering or processing.

get_visualization_summary_dict(visualization)[source]

Return a set of summary attributes for a visualization in dictionary form. NOTE: that encoding ids isn’t done here should happen at the caller level.

get_visualization_dict(visualization)[source]

Return a set of detailed attributes for a visualization in dictionary form. The visualization’s latest_revision is returned in its own sub-dictionary. NOTE: that encoding ids isn’t done here should happen at the caller level.

get_visualization_revision_dict(revision)[source]

Return a set of detailed attributes for a visualization in dictionary form. NOTE: that encoding ids isn’t done here should happen at the caller level.

import_visualization(trans, id, user=None)[source]

Copy the visualization with the given id and associate the copy with the given user (defaults to trans.user).

Raises ItemAccessibilityException if user is not passed and the current user is anonymous, and if the visualization is not importable. Raises ItemDeletionException if the visualization has been deleted.

create_visualization(trans, type, title='Untitled Visualization', slug=None, dbkey=None, annotation=None, config={}, save=True)[source]

Create visualiation and first revision.

add_visualization_revision(trans, visualization, config, title, dbkey)[source]

Adds a new VisualizationRevision to the given visualization with the given parameters and set its parent visualization’s latest_revision to the new revision.

save_visualization(trans, config, type, id=None, title=None, dbkey=None, slug=None, annotation=None)[source]
get_tool_def(trans, hda)[source]

Returns definition of an interactive tool for an HDA.

get_visualization_config(trans, visualization)[source]

Returns a visualization’s configuration. Only works for trackster visualizations right now.

get_new_track_config(trans, dataset)[source]

Returns track configuration dict for a dataset.

get_hda_or_ldda(trans, hda_ldda, dataset_id)[source]

Returns either HDA or LDDA for hda/ldda and id combination.

get_hda(trans, dataset_id, check_ownership=True, check_accessible=False, check_state=True)[source]

Get an HDA object by id performing security checks using the current transaction.

class galaxy.web.base.controller.UsesStoredWorkflowMixin[source]

Bases: galaxy.web.base.controller.SharableItemSecurityMixin, galaxy.model.item_attrs.UsesAnnotations

Mixin for controllers that use StoredWorkflow objects.

get_stored_workflow(trans, id, check_ownership=True, check_accessible=False)[source]

Get a StoredWorkflow from the database by id, verifying ownership.

get_stored_workflow_steps(trans, stored_workflow)[source]

Restores states for a stored workflow’s steps.

class galaxy.web.base.controller.UsesFormDefinitionsMixin[source]

Mixin for controllers that use Galaxy form objects.

get_all_forms(trans, all_versions=False, filter=None, form_type='All')[source]

Return all the latest forms from the form_definition_current table if all_versions is set to True. Otherwise return all the versions of all the forms from the form_definition table.

get_all_forms_by_type(trans, cntrller, form_type)[source]
add_template(trans, cntrller, item_type, form_type, **kwd)[source]
edit_template(trans, cntrller, item_type, form_type, **kwd)[source]
edit_template_info(trans, cntrller, item_type, form_type, **kwd)[source]
delete_template(trans, cntrller, item_type, form_type, **kwd)[source]
widget_fields_have_contents(widgets)[source]
clean_field_contents(widgets, **kwd)[source]
field_param_values_ok(widget_name, widget_type, **kwd)[source]
save_widget_field(trans, field_obj, widget_name, **kwd)[source]
get_form_values(trans, user, form_definition, **kwd)[source]

Returns the name:value dictionary containing all the form values

populate_widgets_from_kwd(trans, widgets, **kwd)[source]
get_item_and_stuff(trans, item_type, **kwd)[source]
build_form_id_select_field(trans, forms, selected_value='none')[source]
class galaxy.web.base.controller.SharableMixin[source]

Mixin for a controller that manages an item that can be shared.

set_public_username(trans, *args, **kwargs)[source]

Set user’s public username and delegate to sharing()

set_slug_async(trans, *args, **kwargs)[source]
create_item_slug(sa_session, item)[source]

Create/set item slug. Slug is unique among user’s importable items for item’s class. Returns true if item’s slug was set/changed; false otherwise.

sharing(trans, *args, **kwargs)[source]

Handle item sharing.

share(trans, *args, **kwargs)[source]

Handle sharing an item with a particular user.

display_by_username_and_slug(trans, username, slug)[source]

Display item by username and slug.

Returns item’s name and link.

get_item_content_async(trans, *args, **kwargs)[source]

Returns item content in HTML format.

get_item(trans, id)[source]

Return item based on id.

class galaxy.web.base.controller.UsesQuotaMixin[source]

Bases: object

get_quota(trans, id, check_ownership=False, check_accessible=False, deleted=None)[source]
class galaxy.web.base.controller.UsesTagsMixin[source]

Bases: galaxy.web.base.controller.SharableItemSecurityMixin

get_tag_handler(trans)[source]
set_tags_from_list(trans, item, new_tags_list, user=None)[source]
get_user_tags_used(trans, user=None)[source]

Return a list of distinct ‘user_tname:user_value’ strings that the given user has used.

user defaults to trans.user. Returns an empty list if no user is given and trans.user is anonymous.

class galaxy.web.base.controller.UsesExtendedMetadataMixin[source]

Bases: galaxy.web.base.controller.SharableItemSecurityMixin

Mixin for getting and setting item extended metadata.

get_item_extended_metadata_obj(trans, item)[source]

Given an item object (such as a LibraryDatasetDatasetAssociation), find the object of the associated extended metadata

set_item_extended_metadata_obj(trans, item, extmeta_obj, check_writable=False)[source]
unset_item_extended_metadata_obj(trans, item, check_writable=False)[source]
create_extended_metadata(trans, extmeta)[source]

Create/index an extended metadata object. The returned object is not associated with any items

delete_extended_metadata(trans, item)[source]
exception galaxy.web.base.controller.ControllerUnavailable[source]

Bases: exceptions.Exception

Deprecated: BaseController used to be available under the name Root

galaxy.web.base.controller.sort_by_attr(seq, attr)[source]

Sort the sequence of objects by object’s attribute Arguments: seq - the list or any sequence (including immutable one) of objects to sort. attr - the name of attribute to sort by

galaxy.web.base.interactive_environments module

class galaxy.web.base.interactive_environments.InteractiveEnvironmentRequest(trans, plugin)[source]

Bases: object

__init__(trans, plugin)[source]
load_allowed_images()[source]
load_deploy_config(default_dict={})[source]
load_container_interface()[source]
get_conf_dict()[source]

Build up a configuration dictionary that is standard for ALL IEs.

TODO: replace hashed password with plaintext.

generate_hex(length)[source]
generate_password(length)[source]

Generate a random alphanumeric password

javascript_boolean(python_boolean)[source]

Convenience function to convert boolean for use in JS

url_template(url_template)[source]

Process a URL template

There are several variables accessible to the user:

  • ${PROXY_URL} will be replaced with the dynamically create proxy’s url
  • ${PROXY_PREFIX} will be replaced with the prefix that may occur
volume(host_path, container_path, **kwds)[source]
docker_cmd(image, env_override=None, volumes=None)[source]

Generate and return the docker command to execute

use_volumes
container_run_args(image, env_override=None, volumes=None)[source]
launch(image=None, additional_ids=None, env_override=None, volumes=None)[source]

Launch a docker image.

Parameters:
  • image (str) – Optional image name. If not provided, self.default_image is used, which is the first image listed in the allowed_images.yml{,.sample} file.
  • additional_ids (str) – comma separated list of encoded HDA IDs. These are transformed into Volumes and added to that argument
  • env_override (dict) – dictionary of environment variables to add.
  • volumes (list of galaxy.tools.deps.docker_util.DockerVolume) – dictionary of docker volume mounts
inspect_container(container_id)[source]

Runs docker inspect on a container and returns json response as python dictionary inspect_data.

Parameters:container_id (str) – a docker container ID
Returns:inspect_data, a dict of docker inspect output
get_container_host(inspect_data)[source]

Determine the ip address on the container. If inspect_data contains Node.IP return that (e.g. running in Docker Swarm). If the hostname is “localhost”, look for NetworkSettings.Gateway. Otherwise, just return the configured docker_hostname.

Parameters:inspect_data (dict) – output of docker inspect
Returns:IP address or hostname of the node the conatainer is running on.
get_container_port_mapping(inspect_data)[source]
Parameters:inspect_data (dict) – output of docker inspect
Returns:a list of triples containing (internal_port, external_ip, external_port), of which the ports are probably the only useful information.

Someday code that calls this should be refactored whenever we get containers with multiple ports working.

galaxy.web.base.pluginframework module

Base class for plugins - frameworks or systems that may:
  • add code at startup
  • allow hooks to be called
and base class for plugins that:
  • serve static content
  • serve templated html
  • have some configuration at startup
exception galaxy.web.base.pluginframework.PluginManagerException[source]

Bases: exceptions.Exception

Base exception for plugin frameworks.

exception galaxy.web.base.pluginframework.PluginManagerConfigException[source]

Bases: galaxy.web.base.pluginframework.PluginManagerException

Exception for plugin framework configuration errors.

class galaxy.web.base.pluginframework.PluginManager(app, directories_setting=None, skip_bad_plugins=True, **kwargs)[source]

Bases: object

Plugins represents an section of code that is not tracked in the Galaxy repository, allowing the addition of custom code to a Galaxy installation without changing the code base.

A PluginManager discovers and manages these plugins.

This is an non-abstract class but its usefulness is limited and is meant to be inherited.

__init__(app, directories_setting=None, skip_bad_plugins=True, **kwargs)[source]

Set up the manager and load all plugins.

Parameters:
  • app (UniverseApplication) – the application (and its configuration) using this manager
  • directories_setting (string (default: None)) – the filesystem path (or paths) to search for plugins. Can be CSV string of paths. Will be treated as absolute if a path starts with ‘/’, relative otherwise.
  • skip_bad_plugins (boolean (default: True)) – whether to skip plugins that cause exceptions when loaded or to raise that exception
load_configuration()[source]

Override to load some framework/plugin specifc configuration.

load_plugins()[source]

Search self.directories for potential plugins, load them, and cache in self.plugins. :rtype: odict :returns: self.plugins

find_plugins()[source]

Return the directory paths of plugins within self.directories.

Paths are considered a plugin path if they pass self.is_plugin. :rtype: string generator :returns: paths of valid plugins

is_plugin(plugin_path)[source]

Determines whether the given filesystem path contains a plugin.

In this base class, all sub-directories are considered plugins.

Parameters:plugin_path (string) – relative or absolute filesystem path to the potential plugin
Return type:bool
Returns:True if the path contains a plugin
load_plugin(plugin_path)[source]

Create, load, and/or initialize the plugin and return it.

Plugin bunches are decorated with:
  • name : the plugin name
  • path : the plugin path
Parameters:plugin_path (string) – relative or absolute filesystem path to the plugin
Return type:util.bunch.Bunch
Returns:the loaded plugin object
class galaxy.web.base.pluginframework.HookPluginManager(app, directories_setting=None, skip_bad_plugins=True, **kwargs)[source]

Bases: galaxy.web.base.pluginframework.PluginManager

A hook plugin is a directory containing python modules or packages that:
  • allow creating, including, and running custom code at specific ‘hook’

    points/events

  • are not tracked in the Galaxy repository and allow adding custom code

    to a Galaxy installation

A HookPluginManager imports the plugin code needed and calls the plugin’s hook functions at the specified time.

loading_point_filename = 'plugin.py'

the python file that will be imported - hook functions should be contained here

hook_fn_prefix = 'hook_'
is_plugin(plugin_path)[source]

Determines whether the given filesystem path contains a hookable plugin.

All sub-directories that contain loading_point_filename are considered plugins.

Parameters:plugin_path (string) – relative or absolute filesystem path to the potential plugin
Return type:bool
Returns:True if the path contains a plugin
load_plugin(plugin_path)[source]

Import the plugin loading_point_filename and attach to the plugin bunch.

Plugin bunches are decorated with:
  • name : the plugin name
  • path : the plugin path
  • module : the plugin code
Parameters:plugin_path (string) – relative or absolute filesystem path to the plugin
Return type:util.bunch.Bunch
Returns:the loaded plugin object
import_plugin_module(loading_point_name, plugin, import_as=None)[source]

Import the plugin code and cache the module in the plugin object.

Parameters:
  • loading_point_name (string) – name of the python file to import (w/o extension)
  • plugin (util.bunch.Bunch) – the plugin containing the template to render
  • import_as (string) – namespace to use for imported module This will be prepended with the __name__ of this file. Defaults to plugin.name
Return type:

util.bunch.Bunch

Returns:

the loaded plugin object

run_hook(hook_name, *args, **kwargs)[source]

Search all plugins for a function named hook_fn_prefix + hook_name and run it passing in args and kwargs.

Return values from each hook are returned in a dictionary keyed with the plugin names.

Parameters:hook_name (string) – name (suffix) of the hook to run
Return type:dictionary
Returns:where keys are plugin.names and values return values from the hooks
filter_hook(hook_name, hook_arg, *args, **kwargs)[source]

Search all plugins for a function named hook_fn_prefix + hook_name and run the first with hook_arg and every function after with the return value of the previous.

..note:
This makes plugin load order very important.
Parameters:
  • hook_name (string) – name (suffix) of the hook to run
  • hook_arg (any) – the arg to be passed between hook functions
Return type:

any

Returns:

the modified hook_arg

exception galaxy.web.base.pluginframework.PluginManagerStaticException[source]

Bases: galaxy.web.base.pluginframework.PluginManagerException

Exception for plugin framework static directory set up errors.

exception galaxy.web.base.pluginframework.PluginManagerTemplateException[source]

Bases: galaxy.web.base.pluginframework.PluginManagerException

Exception for plugin framework template directory and template rendering errors.

class galaxy.web.base.pluginframework.PageServingPluginManager(app, base_url='', template_cache_dir=None, **kwargs)[source]

Bases: galaxy.web.base.pluginframework.PluginManager

Page serving plugins are files/directories that:
  • are not tracked in the Galaxy repository and allow adding custom code

    to a Galaxy installation

  • serve static files (css, js, images, etc.),

  • render templates

A PageServingPluginManager sets up all the above components.

DEFAULT_BASE_URL = ''

default static url base

serves_static = True

does the class need static files served?

serves_templates = True

does the class need template files served?

DEFAULT_TEMPLATE_COLLECTION_SIZE = 10

default number of templates to search for plugin template lookup

DEFAULT_TEMPLATE_ENCODING = 'utf-8'

default encoding of plugin templates

additional_template_paths_config_filename = 'additional_template_paths.xml'

name of files to search for additional template lookup directories

__init__(app, base_url='', template_cache_dir=None, **kwargs)[source]

Set up the manager and load all plugins.

Parameters:
  • app (UniverseApplication) – the application (and its configuration) using this manager
  • base_url (string) – url to prefix all plugin urls with
  • template_cache_dir (string) – filesytem path to the directory where cached templates are kept
load_configuration()[source]
Load framework wide configuration, including:
additional template lookup directories
parse_additional_template_paths(config_filepath, base_directory)[source]

Parse an XML config file at config_filepath for template paths (relative to base_directory) to add to each plugin’s template lookup.

Allows having a set of common templates for import/inheritance in plugin templates.

Parameters:
  • config_filepath (string) – filesystem path to the config file
  • base_directory (string) – path prefixed to new, relative template paths
is_plugin(plugin_path)[source]

Determines whether the given filesystem path contains a plugin.

If the manager serves_templates and a sub-directory contains another sub-directory named ‘templates’ it’s considered valid. If the manager serves_static and a sub-directory contains another sub-directory named ‘static’ it’s considered valid.

Parameters:plugin_path (string) – relative or absolute filesystem path to the potential plugin
Return type:bool
Returns:True if the path contains a plugin
load_plugin(plugin_path)[source]

Create the plugin and decorate with static and/or template paths and urls.

Plugin bunches are decorated with:
  • name : the plugin name
  • path : the plugin path
  • base_url : a url to the plugin
Parameters:plugin_path (string) – relative or absolute filesystem path to the plugin
Return type:util.bunch.Bunch
Returns:the loaded plugin object
get_static_urls_and_paths()[source]

For each plugin, return a 2-tuple where the first element is a url path to the plugin’s static files and the second is a filesystem path to those same files.

Meant to be passed to a Static url map.

Return type:list of 2-tuples
Returns:all urls and paths for each plugin serving static content
build_plugin_template_lookup(plugin)[source]

Builds the object that searches for templates (cached or not) when rendering.

Parameters:plugin (util.bunch.Bunch) – the plugin containing the templates
Return type:Mako.lookup.TemplateLookup
Returns:template lookup for this plugin
fill_template(trans, plugin, template_filename, **kwargs)[source]

Pass control over to trans and render template_filename.

Parameters:
  • trans (galaxy.web.framework.webapp.GalaxyWebTransaction) – transaction doing the rendering
  • plugin (util.bunch.Bunch) – the plugin containing the template to render
  • template_filename (string) – the path of the template to render relative to plugin.template_path
Returns:

rendered template

class galaxy.web.base.pluginframework.Plugin(app, path, name, config, context=None, **kwargs)[source]

Bases: object

Plugin as object/class.

__init__(app, path, name, config, context=None, **kwargs)[source]