commit/galaxy-central: 5 new changesets
5 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/82c43e74d316/ Changeset: 82c43e74d316 Branch: jjohnson/allow-jobs-to-be-filtered-by-tool_id-and-1391011677231 User: jjohnson Date: 2014-01-29 17:09:12 Summary: Allow jobs to be filtered by tool_id and history_id as well as by state. The tool_id is compared with the like operator. Affected #: 1 file diff -r 07dceba219c315e2857f105abfdaf030efa1f16c -r 82c43e74d31617ca3efda965d6c069c7e99ae63b lib/galaxy/webapps/galaxy/api/jobs.py --- a/lib/galaxy/webapps/galaxy/api/jobs.py +++ b/lib/galaxy/webapps/galaxy/api/jobs.py @@ -22,7 +22,7 @@ @expose_api def index( self, trans, **kwd ): """ - index( trans, state=None ) + index( trans, state=None, tool_id=None, history_id=None ) * GET /api/jobs: return jobs for current user @@ -31,6 +31,12 @@ Valid Galaxy job states include: 'new', 'upload', 'waiting', 'queued', 'running', 'ok', 'error', 'paused', 'deleted', 'deleted_new' + :type tool_id: string or list + :param tool_id: limit listing of jobs to those that match one of the included tool_ids. If none, all are returned. + + :type history_id: string + :param history_id: limit listing of jobs to those that match the history_id. If none, all are returned. + :rtype: list :returns: list of dictionaries containing summary job information """ @@ -48,6 +54,24 @@ t.append( trans.app.model.Job.state == s ) query = query.filter( or_( *t ) ) + tool_id = kwd.get( 'tool_id', None ) + if tool_id is not None: + if isinstance( tool_id, basestring ): + query = query.filter( trans.app.model.Job.tool_id.like('%' + tool_id + '%') ) + elif isinstance( tool_id, list ): + t = [] + for s in tool_id: + t.append( trans.app.model.Job.tool_id.like('%' + s + '%') ) + query = query.filter( or_( *t ) ) + + history_id = kwd.get( 'history_id', None ) + if history_id is not None: + try: + decoded_history_id = trans.security.decode_id(history_id) + query = query.filter( trans.app.model.Job.history_id == decoded_history_id ) + except: + raise exceptions.ObjectAttributeInvalidException() + out = [] for job in query.order_by( trans.app.model.Job.update_time.desc() https://bitbucket.org/galaxy/galaxy-central/commits/b6cc7ffa9f4c/ Changeset: b6cc7ffa9f4c Branch: jjohnson/allow-jobs-to-be-filtered-by-tool_id-and-1391011677231 User: jmchilton Date: 2014-02-28 16:57:53 Summary: Reduce a little code dup in api/jobs.py. Affected #: 1 file diff -r 82c43e74d31617ca3efda965d6c069c7e99ae63b -r b6cc7ffa9f4c615b0724d5a3a52270ae5087e649 lib/galaxy/webapps/galaxy/api/jobs.py --- a/lib/galaxy/webapps/galaxy/api/jobs.py +++ b/lib/galaxy/webapps/galaxy/api/jobs.py @@ -12,6 +12,7 @@ from galaxy.web.base.controller import UsesHistoryDatasetAssociationMixin from galaxy.web.base.controller import UsesLibraryMixinItems from galaxy import exceptions +from galaxy import util import logging log = logging.getLogger( __name__ ) @@ -45,24 +46,22 @@ query = trans.sa_session.query( trans.app.model.Job ).filter( trans.app.model.Job.user == trans.user ) - if state is not None: - if isinstance( state, basestring ): - query = query.filter( trans.app.model.Job.state == state ) - elif isinstance( state, list ): - t = [] - for s in state: - t.append( trans.app.model.Job.state == s ) - query = query.filter( or_( *t ) ) + + def build_and_apply_filters( query, objects, filter_func ): + if objects is not None: + if isinstance( objects, basestring ): + query = query.filter( filter_func( objects ) ) + elif isinstance( objects, list ): + t = [] + for obj in objects: + t.append( filter_func( obj ) ) + query = query.filter( or_( *t ) ) + return query + + query = build_and_apply_filters( query, state, lambda s: trans.app.model.Job.state == s ) tool_id = kwd.get( 'tool_id', None ) - if tool_id is not None: - if isinstance( tool_id, basestring ): - query = query.filter( trans.app.model.Job.tool_id.like('%' + tool_id + '%') ) - elif isinstance( tool_id, list ): - t = [] - for s in tool_id: - t.append( trans.app.model.Job.tool_id.like('%' + s + '%') ) - query = query.filter( or_( *t ) ) + query = build_and_apply_filters( query, tool_id, lambda t: trans.app.model.Job.tool_id.like('%' + t + '%') ) history_id = kwd.get( 'history_id', None ) if history_id is not None: https://bitbucket.org/galaxy/galaxy-central/commits/7bdfa44e7edc/ Changeset: 7bdfa44e7edc Branch: jjohnson/allow-jobs-to-be-filtered-by-tool_id-and-1391011677231 User: jmchilton Date: 2014-02-28 17:02:29 Summary: Modify jobs index to allow exact or inexact tool id filtering. Discussed this with JJ and Dannon. Formerly this was only inexact matchings, I was a little worried about API users expected exact tool id matches when using a parameter called tool_id. JJ's original intended behavior can be accessed using tool_id_like. Affected #: 1 file diff -r b6cc7ffa9f4c615b0724d5a3a52270ae5087e649 -r 7bdfa44e7edcb7a299dcd31943be7c55babfaedc lib/galaxy/webapps/galaxy/api/jobs.py --- a/lib/galaxy/webapps/galaxy/api/jobs.py +++ b/lib/galaxy/webapps/galaxy/api/jobs.py @@ -60,8 +60,8 @@ query = build_and_apply_filters( query, state, lambda s: trans.app.model.Job.state == s ) - tool_id = kwd.get( 'tool_id', None ) - query = build_and_apply_filters( query, tool_id, lambda t: trans.app.model.Job.tool_id.like('%' + t + '%') ) + query = build_and_apply_filters( query, kwd.get( 'tool_id', None ), lambda t: trans.app.model.Job.tool_id == t ) + query = build_and_apply_filters( query, kwd.get( 'tool_id_like', None ), lambda t: trans.app.model.Job.tool_id.like(t) ) history_id = kwd.get( 'history_id', None ) if history_id is not None: https://bitbucket.org/galaxy/galaxy-central/commits/3981b0070af0/ Changeset: 3981b0070af0 User: jmchilton Date: 2014-02-28 17:08:26 Summary: Merge JJ's pull request #315 (with minor modifications discussed with JJ). Affected #: 1 file diff -r 6a633b37c4c47bba640d05fef72fd73f41ae5086 -r 3981b0070af02af108ce81091866d531e66b8fd1 lib/galaxy/webapps/galaxy/api/jobs.py --- a/lib/galaxy/webapps/galaxy/api/jobs.py +++ b/lib/galaxy/webapps/galaxy/api/jobs.py @@ -12,6 +12,7 @@ from galaxy.web.base.controller import UsesHistoryDatasetAssociationMixin from galaxy.web.base.controller import UsesLibraryMixinItems from galaxy import exceptions +from galaxy import util import logging log = logging.getLogger( __name__ ) @@ -22,7 +23,7 @@ @expose_api def index( self, trans, **kwd ): """ - index( trans, state=None ) + index( trans, state=None, tool_id=None, history_id=None ) * GET /api/jobs: return jobs for current user @@ -31,6 +32,12 @@ Valid Galaxy job states include: 'new', 'upload', 'waiting', 'queued', 'running', 'ok', 'error', 'paused', 'deleted', 'deleted_new' + :type tool_id: string or list + :param tool_id: limit listing of jobs to those that match one of the included tool_ids. If none, all are returned. + + :type history_id: string + :param history_id: limit listing of jobs to those that match the history_id. If none, all are returned. + :rtype: list :returns: list of dictionaries containing summary job information """ @@ -39,14 +46,30 @@ query = trans.sa_session.query( trans.app.model.Job ).filter( trans.app.model.Job.user == trans.user ) - if state is not None: - if isinstance( state, basestring ): - query = query.filter( trans.app.model.Job.state == state ) - elif isinstance( state, list ): - t = [] - for s in state: - t.append( trans.app.model.Job.state == s ) - query = query.filter( or_( *t ) ) + + def build_and_apply_filters( query, objects, filter_func ): + if objects is not None: + if isinstance( objects, basestring ): + query = query.filter( filter_func( objects ) ) + elif isinstance( objects, list ): + t = [] + for obj in objects: + t.append( filter_func( obj ) ) + query = query.filter( or_( *t ) ) + return query + + query = build_and_apply_filters( query, state, lambda s: trans.app.model.Job.state == s ) + + query = build_and_apply_filters( query, kwd.get( 'tool_id', None ), lambda t: trans.app.model.Job.tool_id == t ) + query = build_and_apply_filters( query, kwd.get( 'tool_id_like', None ), lambda t: trans.app.model.Job.tool_id.like(t) ) + + history_id = kwd.get( 'history_id', None ) + if history_id is not None: + try: + decoded_history_id = trans.security.decode_id(history_id) + query = query.filter( trans.app.model.Job.history_id == decoded_history_id ) + except: + raise exceptions.ObjectAttributeInvalidException() out = [] for job in query.order_by( https://bitbucket.org/galaxy/galaxy-central/commits/6d799bd3e8c8/ Changeset: 6d799bd3e8c8 Branch: jjohnson/allow-jobs-to-be-filtered-by-tool_id-and-1391011677231 User: jmchilton Date: 2014-02-28 17:08:46 Summary: Close branch. Affected #: 0 files 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