commit/galaxy-central: 5 new changesets
5 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/340d626da27a/ changeset: 340d626da27a user: dannon date: 2013-03-05 21:39:22 summary: Base controller import cleanup, remove unused variables. affected #: 1 file diff -r 0a6a4752493eacfac2fb7a537d30be0333a58977 -r 340d626da27af28fab27115c0329ea1a2069048b lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -1,28 +1,29 @@ """ Contains functionality needed in every web interface """ -import os, time, logging, re, string, sys, glob, shutil, tempfile, subprocess, operator -from datetime import date, datetime, timedelta -from time import strftime -from galaxy import config, tools, web, util -from galaxy.util import inflector -from galaxy.util.hash_util import * +import logging +import operator +import os +import re +import pkg_resources +pkg_resources.require("SQLAlchemy >= 0.4") + +from sqlalchemy import func, and_, select +from paste.httpexceptions import HTTPBadRequest, HTTPInternalServerError, HTTPNotImplemented, HTTPRequestRangeNotSatisfiable + +from galaxy import util, web +from galaxy.datatypes.interval import ChromatinInteractions +from galaxy.exceptions import ItemAccessibilityException, ItemDeletionException, ItemOwnershipException, MessageException +from galaxy.security.validate_user_input import validate_publicname from galaxy.util.sanitize_html import sanitize_html -from galaxy.web import error, form, url_for -from galaxy.model.orm import * -from galaxy.workflow.modules import * -from galaxy.web.framework import simplejson +from galaxy.visualization.genome.visual_analytics import get_tool_def +from galaxy.web import error, url_for from galaxy.web.form_builder import AddressField, CheckboxField, SelectField, TextArea, TextField -from galaxy.web.form_builder import WorkflowField, WorkflowMappingField, HistoryField, PasswordField, build_select_field -from galaxy.visualization.genome.visual_analytics import get_tool_def -from galaxy.security.validate_user_input import validate_publicname -from paste.httpexceptions import * -from galaxy.exceptions import * -from galaxy.model import NoConverterException, ConverterDependencyException -from galaxy.datatypes.interval import ChromatinInteractions +from galaxy.web.form_builder import build_select_field, HistoryField, PasswordField, WorkflowField, WorkflowMappingField +from galaxy.workflow.modules import module_factory +from galaxy.model.orm import eagerload, eagerload_all from galaxy.datatypes.data import Text -from Cheetah.Template import Template log = logging.getLogger( __name__ ) @@ -100,6 +101,7 @@ log.exception( "Invalid %s id ( %s ) specified" % ( class_name, id ) ) raise MessageException( "Invalid %s id ( %s ) specified" % ( class_name, id ), type="error" ) if check_ownership or check_accessible: + #DBTODO bug: encoded_id is id self.security_check( trans, item, check_ownership, check_accessible, encoded_id ) if deleted == True and not item.deleted: raise ItemDeletionException( '%s "%s" is not deleted' % ( class_name, getattr( item, 'name', id ) ), type="warning" ) @@ -134,7 +136,7 @@ def get_object( self, trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None ): try: return BaseController.get_object( self, trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None ) - except MessageException, e: + except MessageException: raise # handled in the caller except: log.exception( "Execption in get_object check for %s %s:" % ( class_name, str( id ) ) ) @@ -228,7 +230,7 @@ # encoded id? dataset_id = trans.security.decode_id( dataset_id ) - except ( AttributeError, TypeError ), err: + except ( AttributeError, TypeError ): # unencoded id dataset_id = int( dataset_id ) @@ -684,6 +686,7 @@ step.state = None # Error dict if step.tool_errors: + #DBTODO BUG: errors doesn't exist in this scope, intent? errors[step.id] = step.tool_errors else: ## Non-tool specific stuff? @@ -943,9 +946,7 @@ def edit_template( self, trans, cntrller, item_type, form_type, **kwd ): # Edit the template itself, keeping existing field contents, if any. params = util.Params( kwd ) - form_id = params.get( 'form_id', 'none' ) message = util.restore_text( params.get( 'message', '' ) ) - status = params.get( 'status', 'done' ) edited = util.string_as_bool( params.get( 'edited', False ) ) action = '' # form_type must be one of: RUN_DETAILS_TEMPLATE, LIBRARY_INFO_TEMPLATE @@ -995,8 +996,6 @@ rtra = item.run_details info_association = rtra.run template = info_association.template - info = info_association.info - form_values = trans.sa_session.query( trans.app.model.FormValues ).get( info.id ) if edited: # The form on which the template is based has been edited, so we need to update the # info_association with the current form @@ -1052,7 +1051,6 @@ sample_id = params.get( 'sample_id', None ) sample = trans.sa_session.query( trans.model.Sample ).get( trans.security.decode_id( sample_id ) ) message = util.restore_text( params.get( 'message', '' ) ) - status = params.get( 'status', 'done' ) try: if in_library: item, item_desc, action, id = self.get_item_and_stuff( trans, @@ -1250,7 +1248,6 @@ sample_id = params.get( 'sample_id', None ) #id = params.get( 'id', None ) message = util.restore_text( params.get( 'message', '' ) ) - status = params.get( 'status', 'done' ) try: if in_library: item, item_desc, action, id = self.get_item_and_stuff( trans, @@ -1282,7 +1279,6 @@ info_association = item.run_details if not info_association: message = "There is no template for this %s" % item_type - status = 'error' else: if in_library: info_association.deleted = True @@ -1292,7 +1288,6 @@ trans.sa_session.delete( info_association ) trans.sa_session.flush() message = 'The template for this %s has been deleted.' % item_type - status = 'done' new_kwd = dict( action=action, cntrller=cntrller, id=id, @@ -1449,9 +1444,6 @@ def get_item_and_stuff( self, trans, item_type, **kwd ): # Return an item, description, action and an id based on the item_type. Valid item_types are # library, folder, ldda, request_type, sample. - is_admin = kwd.get( 'is_admin', False ) - #message = None - current_user_roles = trans.get_current_user_roles() if item_type == 'library': library_id = kwd.get( 'library_id', None ) id = library_id https://bitbucket.org/galaxy/galaxy-central/commits/1daf0cefe5be/ changeset: 1daf0cefe5be user: dannon date: 2013-03-05 21:41:22 summary: Fix bug introduced in 6028 -- encoded_id should be just 'id' affected #: 1 file diff -r 340d626da27af28fab27115c0329ea1a2069048b -r 1daf0cefe5bed7f972f3e8aeec0d2577811d005c lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -101,8 +101,7 @@ log.exception( "Invalid %s id ( %s ) specified" % ( class_name, id ) ) raise MessageException( "Invalid %s id ( %s ) specified" % ( class_name, id ), type="error" ) if check_ownership or check_accessible: - #DBTODO bug: encoded_id is id - self.security_check( trans, item, check_ownership, check_accessible, encoded_id ) + self.security_check( trans, item, check_ownership, check_accessible, id ) if deleted == True and not item.deleted: raise ItemDeletionException( '%s "%s" is not deleted' % ( class_name, getattr( item, 'name', id ) ), type="warning" ) elif deleted == False and item.deleted: https://bitbucket.org/galaxy/galaxy-central/commits/94272d25279e/ changeset: 94272d25279e user: dannon date: 2013-03-05 21:43:40 summary: Kill unused step error dict - this is handled elsewhere. affected #: 1 file diff -r 1daf0cefe5bed7f972f3e8aeec0d2577811d005c -r 94272d25279e96b866be313c222e9e3a9af57b9d lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -683,10 +683,6 @@ step.upgrade_messages = "Unknown Tool ID" step.module = None step.state = None - # Error dict - if step.tool_errors: - #DBTODO BUG: errors doesn't exist in this scope, intent? - errors[step.id] = step.tool_errors else: ## Non-tool specific stuff? step.module = module_factory.from_workflow_step( trans, step ) https://bitbucket.org/galaxy/galaxy-central/commits/3b4596096549/ changeset: 3b4596096549 user: dannon date: 2013-03-05 21:44:03 summary: Trim whitespace. affected #: 1 file diff -r 94272d25279e96b866be313c222e9e3a9af57b9d -r 3b459609654976c8908a2c3104a080db8f550b61 lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -194,7 +194,7 @@ self.mimetype = mimetype self.display_in_upload = display_in_upload -# +# # -- Mixins for working with Galaxy objects. -- # @@ -221,7 +221,7 @@ class UsesHistoryDatasetAssociationMixin: """ Mixin for controllers that use HistoryDatasetAssociation objects. """ - + def get_dataset( self, trans, dataset_id, check_ownership=True, check_accessible=False, check_state=True ): """ Get an HDA object by id. """ # DEPRECATION: We still support unencoded ids for backward compatibility @@ -256,13 +256,13 @@ return trans.show_error_message( "Please wait until this dataset finishes uploading " + "before attempting to view it." ) return data - + def get_history_dataset_association( self, trans, history, dataset_id, check_ownership=True, check_accessible=False, check_state=False ): """Get a HistoryDatasetAssociation from the database by id, verifying ownership.""" self.security_check( trans, history, check_ownership=check_ownership, check_accessible=check_accessible ) hda = self.get_object( trans, dataset_id, 'HistoryDatasetAssociation', check_ownership=False, check_accessible=False, deleted=False ) - + if check_accessible: if not trans.app.security_agent.can_access_dataset( trans.get_current_user_roles(), hda.dataset ): error( "You are not allowed to access this dataset" ) @@ -270,7 +270,7 @@ if check_state and hda.state == trans.model.Dataset.states.UPLOAD: error( "Please wait until this dataset finishes uploading before attempting to view it." ) return hda - + def get_data( self, dataset, preview=True ): """ Gets a dataset's data. """ @@ -290,7 +290,7 @@ # For now, cannot get data from non-text datasets. dataset_data = None return truncated, dataset_data - + def check_dataset_state( self, trans, dataset ): """ Returns a message if dataset is not ready to be used in visualization. @@ -302,7 +302,7 @@ if dataset.state != trans.app.model.Job.states.OK: return dataset.conversion_messages.PENDING return None - + class UsesLibraryMixin: def get_library( self, trans, id, check_ownership=False, check_accessible=True ): @@ -319,10 +319,10 @@ def get_library_dataset( self, trans, id, check_ownership=False, check_accessible=True ): return self.get_object( trans, id, 'LibraryDataset', check_ownership=False, check_accessible=check_accessible ) -class UsesVisualizationMixin( UsesHistoryDatasetAssociationMixin, +class UsesVisualizationMixin( UsesHistoryDatasetAssociationMixin, UsesLibraryMixinItems ): """ Mixin for controllers that use Visualization objects. """ - + viz_types = [ "trackster" ] def create_visualization( self, trans, type, title="Untitled Genome Vis", slug=None, dbkey=None, annotation=None, config={}, save=True ): @@ -339,26 +339,26 @@ session.flush() return visualization - + def save_visualization( self, trans, config, type, id=None, title=None, dbkey=None, slug=None, annotation=None ): session = trans.sa_session - - # Create/get visualization. + + # Create/get visualization. if not id: # Create new visualization. vis = self._create_visualization( trans, title, type, dbkey, slug, annotation ) else: decoded_id = trans.security.decode_id( id ) vis = session.query( trans.model.Visualization ).get( decoded_id ) - + # Create new VisualizationRevision that will be attached to the viz vis_rev = trans.model.VisualizationRevision() vis_rev.visualization = vis vis_rev.title = vis.title vis_rev.dbkey = dbkey - + # -- Validate config. -- - + if vis.type == 'trackster': def unpack_track( track_json ): """ Unpack a track from its json. """ @@ -436,12 +436,12 @@ # Unpack Trackster config. latest_revision = visualization.latest_revision bookmarks = latest_revision.config.get( 'bookmarks', [] ) - + def pack_track( track_dict ): dataset_id = track_dict['dataset_id'] hda_ldda = track_dict.get('hda_ldda', 'hda') if hda_ldda == 'ldda': - # HACK: need to encode library dataset ID because get_hda_or_ldda + # HACK: need to encode library dataset ID because get_hda_or_ldda # only works for encoded datasets. dataset_id = trans.security.encode_id( dataset_id ) dataset = self.get_hda_or_ldda( trans, hda_ldda, dataset_id ) @@ -452,10 +452,10 @@ prefs = {} track_type, _ = dataset.datatype.get_track_type() - track_data_provider = trans.app.data_provider_registry.get_data_provider( trans, - original_dataset=dataset, + track_data_provider = trans.app.data_provider_registry.get_data_provider( trans, + original_dataset=dataset, source='data' ) - + return { "track_type": track_type, "name": track_dict['name'], @@ -467,7 +467,7 @@ "tool": get_tool_def( trans, dataset ), "tool_state": track_dict.get( 'tool_state', {} ) } - + def pack_collection( collection_dict ): drawables = [] for drawable_dict in collection_dict[ 'drawables' ]: @@ -482,10 +482,10 @@ 'prefs': collection_dict.get( 'prefs', [] ), 'filters': collection_dict.get( 'filters', {} ) } - + def encode_dbkey( dbkey ): - """ - Encodes dbkey as needed. For now, prepends user's public name + """ + Encodes dbkey as needed. For now, prepends user's public name to custom dbkey keys. """ encoded_dbkey = dbkey @@ -493,7 +493,7 @@ if 'dbkeys' in user.preferences and dbkey in user.preferences[ 'dbkeys' ]: encoded_dbkey = "%s:%s" % ( user.username, dbkey ) return encoded_dbkey - + # Set tracks. tracks = [] if 'tracks' in latest_revision.config: @@ -506,12 +506,12 @@ tracks.append( pack_track( drawable_dict ) ) else: tracks.append( pack_collection( drawable_dict ) ) - - config = { "title": visualization.title, + + config = { "title": visualization.title, "vis_id": trans.security.encode_id( visualization.id ), - "tracks": tracks, - "bookmarks": bookmarks, - "chrom": "", + "tracks": tracks, + "bookmarks": bookmarks, + "chrom": "", "dbkey": encode_dbkey( visualization.dbkey ) } if 'viewport' in latest_revision.config: @@ -522,7 +522,7 @@ config = latest_revision.config return config - + def get_new_track_config( self, trans, dataset ): """ Returns track configuration dict for a dataset. @@ -530,13 +530,13 @@ # Get data provider. track_type, _ = dataset.datatype.get_track_type() track_data_provider = trans.app.data_provider_registry.get_data_provider( trans, original_dataset=dataset ) - - + + if isinstance( dataset, trans.app.model.HistoryDatasetAssociation ): hda_ldda = "hda" elif isinstance( dataset, trans.app.model.LibraryDatasetDatasetAssociation ): hda_ldda = "ldda" - + # Get track definition. return { "track_type": track_type, @@ -548,16 +548,16 @@ "tool": get_tool_def( trans, dataset ), "tool_state": {} } - + def get_hda_or_ldda( self, trans, hda_ldda, dataset_id ): """ Returns either HDA or LDDA for hda/ldda and id combination. """ if hda_ldda == "hda": return self.get_dataset( trans, dataset_id, check_ownership=False, check_accessible=True ) else: return self.get_library_dataset_dataset_association( trans, dataset_id ) - + # -- Helper functions -- - + def _create_visualization( self, trans, title, type, dbkey=None, slug=None, annotation=None, save=True ): """ Create visualization but not first revision. Returns Visualization object. """ user = trans.get_user() @@ -573,7 +573,7 @@ if title_err or slug_err: return { 'title_err': title_err, 'slug_err': slug_err } - + # Create visualization visualization = trans.model.Visualization( user=user, title=title, dbkey=dbkey, type=type ) @@ -616,13 +616,13 @@ if isinstance( dataset.datatype, ChromatinInteractions ): source = 'data' - data_provider = trans.app.data_provider_registry.get_data_provider( trans, - original_dataset=dataset, + data_provider = trans.app.data_provider_registry.get_data_provider( trans, + original_dataset=dataset, source=source ) - # HACK: pass in additional params which are used for only some - # types of data providers; level, cutoffs used for summary tree, + # HACK: pass in additional params which are used for only some + # types of data providers; level, cutoffs used for summary tree, # num_samples for BBI, and interchromosomal used for chromatin interactions. - rval = data_provider.get_genome_data( chroms_info, + rval = data_provider.get_genome_data( chroms_info, level=4, detail_cutoff=0, draw_cutoff=0, num_samples=150, interchromosomal=True ) @@ -635,7 +635,7 @@ Returns highest priority message from a list of messages. """ return_message = None - + # For now, priority is: job error (dict), no converter, pending. for message in message_list: if message is not None: @@ -714,14 +714,14 @@ def get_hda_state_counts( self, trans, history, include_deleted=False, include_hidden=False ): """ - Returns a dictionary with state counts for history's HDAs. Key is a + Returns a dictionary with state counts for history's HDAs. Key is a dataset state, value is the number of states in that count. """ # Build query to get (state, count) pairs. - cols_to_select = [ trans.app.model.Dataset.table.c.state, func.count( '*' ) ] + cols_to_select = [ trans.app.model.Dataset.table.c.state, func.count( '*' ) ] from_obj = trans.app.model.HistoryDatasetAssociation.table.join( trans.app.model.Dataset.table ) - + conditions = [ trans.app.model.HistoryDatasetAssociation.table.c.history_id == history.id ] if not include_deleted: # Only count datasets that have not been deleted. @@ -729,7 +729,7 @@ if not include_hidden: # Only count datasets that are visible. conditions.append( trans.app.model.HistoryDatasetAssociation.table.c.visible == True ) - + group_by = trans.app.model.Dataset.table.c.state query = select( columns=cols_to_select, from_obj=from_obj, @@ -740,7 +740,7 @@ state_count_dict = {} for k, state in trans.app.model.Dataset.states.items(): state_count_dict[ state ] = 0 - + # Process query results, adding to count dict. for row in trans.sa_session.execute( query ): state, count = row @@ -1501,13 +1501,13 @@ class SharableMixin: """ Mixin for a controller that manages an item that can be shared. """ - + # -- Implemented methods. -- def _is_valid_slug( self, slug ): """ Returns true if slug is valid. """ return _is_valid_slug( slug ) - + @web.expose @web.require_login( "share Galaxy items" ) def set_public_username( self, trans, id, username, **kwargs ): @@ -1526,7 +1526,7 @@ item = self.get_item( trans, id ) if item: # Only update slug if slug is not already in use. - if trans.sa_session.query( item.__class__ ).filter_by( user=item.user, slug=new_slug, importable=True ).count() == 0: + if trans.sa_session.query( item.__class__ ).filter_by( user=item.user, slug=new_slug, importable=True ).count() == 0: item.slug = new_slug trans.sa_session.flush() @@ -1534,15 +1534,15 @@ def _make_item_accessible( self, sa_session, item ): """ Makes item accessible--viewable and importable--and sets item's slug. - Does not flush/commit changes, however. Item must have name, user, + Does not flush/commit changes, however. Item must have name, user, importable, and slug attributes. """ item.importable = True self.create_item_slug( sa_session, item ) - + def create_item_slug( self, sa_session, item ): - """ 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. + """ 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. """ cur_slug = item.slug @@ -1563,7 +1563,7 @@ else: slug_base = cur_slug - # Using slug base, find a slug that is not taken. If slug is taken, + # Using slug base, find a slug that is not taken. If slug is taken, # add integer to end. new_slug = slug_base count = 1 @@ -1572,13 +1572,13 @@ # handle numerous items with the same name gracefully. new_slug = '%s-%i' % ( slug_base, count ) count += 1 - + # Set slug and return. item.slug = new_slug return item.slug == cur_slug - - # -- Abstract methods. -- - + + # -- Abstract methods. -- + @web.expose @web.require_login( "share Galaxy items" ) def sharing( self, trans, id, **kwargs ): @@ -1595,19 +1595,19 @@ def display_by_username_and_slug( self, trans, username, slug ): """ Display item by username and slug. """ raise "Unimplemented Method" - + @web.json @web.require_login( "get item name and link" ) def get_name_and_link_async( self, trans, id=None ): """ Returns item's name and link. """ raise "Unimplemented Method" - + @web.expose @web.require_login("get item content asynchronously") def get_item_content_async( self, trans, id ): """ Returns item content in HTML format. """ raise "Unimplemented Method" - + def get_item( self, trans, id ): """ Return item based on id. """ raise "Unimplemented Method" https://bitbucket.org/galaxy/galaxy-central/commits/6bc53fd15c62/ changeset: 6bc53fd15c62 user: dannon date: 2013-03-05 21:52:09 summary: Fix spacing between methods in base controller. affected #: 1 file Diff not available. Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org