1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/5f10f61335fb/ changeset: 5f10f61335fb user: greg date: 2013-02-22 20:35:34 summary: Enhancements to the tool shed api to enable the curretnly most important updates for repository_metadata records. affected #: 7 files diff -r 8019917d7c309b2e9d4ca25078a6bda15569f94f -r 5f10f61335fbcfb7982a879edc80325f5a73402f lib/galaxy/webapps/community/api/repositories.py --- a/lib/galaxy/webapps/community/api/repositories.py +++ b/lib/galaxy/webapps/community/api/repositories.py @@ -32,7 +32,7 @@ item[ 'url' ] = web.url_for( 'repository_contents', repository_id=trans.security.encode_id( repository.id ) ) rval.append( item ) except Exception, e: - message = "Error in the Tool Shed API at index: %s" % str( e ) + message = "Error in the Tool Shed repositories API in index: %s" % str( e ) log.error( message, exc_info=True ) trans.response.status = 500 return message @@ -50,8 +50,8 @@ repository_data = repository.get_api_value( view='element', value_mapper=value_mapper ) repository_data[ 'contents_url' ] = web.url_for( 'repository_contents', repository_id=id ) except Exception, e: - message = "Error in the Tool Shed API at show: %s" % str( e ) + message = "Error in the Tool Shed repositories API in show: %s" % str( e ) log.error( message, exc_info=True ) trans.response.status = 500 return message - return repository_data \ No newline at end of file + return repository_data diff -r 8019917d7c309b2e9d4ca25078a6bda15569f94f -r 5f10f61335fbcfb7982a879edc80325f5a73402f lib/galaxy/webapps/community/api/repository_contents.py --- a/lib/galaxy/webapps/community/api/repository_contents.py +++ b/lib/galaxy/webapps/community/api/repository_contents.py @@ -11,21 +11,24 @@ class RepositoryContentsController( BaseAPIController ): @web.expose_api - def index( self, trans, repository_id, **kwd ): + def index( self, trans, **kwd ): """ - GET /api/repositories/{encoded_repsository_id}/contents - Displays a collection (list) of repository contents. + GET /api/repositories/{encoded_repository_id}/contents + Displays a collection (dictionary) of repository contents. :param repository_id: an encoded id string of the `Repository` to inspect """ rval = [] + repository_id = kwd.get( 'repository_id', None ) try: repository = suc.get_repository_in_tool_shed( trans, repository_id ) - repository_dict = repository.as_dict( trans ) + value_mapper={ 'id' : repository_id, + 'user_id' : trans.security.encode_id( repository.user_id ) } + repository_dict = repository.as_dict( value_mapper ) repository_dict[ 'url' ] = web.url_for( 'repository_contents', repository_id=repository_id ) rval.append( repository_dict ) except Exception, e: - message = "Error in repository_contents API: %s" % str( e ) + message = "Error in the Tool Shed repository_contents API in index: %s" % str( e ) log.error( message, exc_info=True ) trans.response.status = 500 return message diff -r 8019917d7c309b2e9d4ca25078a6bda15569f94f -r 5f10f61335fbcfb7982a879edc80325f5a73402f lib/galaxy/webapps/community/api/repository_revision_contents.py --- /dev/null +++ b/lib/galaxy/webapps/community/api/repository_revision_contents.py @@ -0,0 +1,39 @@ +import logging +from galaxy.web.framework.helpers import time_ago +import galaxy.util.shed_util_common as suc +from galaxy import web +from galaxy.web.base.controller import BaseAPIController + +import pkg_resources +pkg_resources.require( "Routes" ) +import routes + +log = logging.getLogger( __name__ ) + +def default_value_mapper( trans, repository_metadata ): + return { 'id' : trans.security.encode_id( repository_metadata.id ), + 'repository_id' : trans.security.encode_id( repository_metadata.repository_id ), + 'time_last_tested' : time_ago( repository_metadata.time_last_tested ) } + +class RepositoryRevisionContentsController( BaseAPIController ): + @web.expose_api + def index( self, trans, **kwd ): + """ + GET /api/repository_revisions/{encoded_repository_metadata_id}/contents + Displays a collection (dictionary) of repository_metadata contents. + + :param repository_metadata_id: an encoded id string of the `RepositoryMetadata` to inspect + """ + rval = [] + repository_metadata_id = kwd.get( 'repository_metadata_id', None ) + try: + repository_metadata = suc.get_repository_metadata_by_id( trans, repository_metadata_id ) + repository_dict = repository_metadata.as_dict( value_mapper=default_value_mapper( trans, repository_metadata ) ) + repository_dict[ 'url' ] = web.url_for( 'repository_revision_contents', repository_metadata_id=repository_metadata_id ) + rval.append( repository_dict ) + except Exception, e: + message = "Error in the Tool Shed repository_revision_contents API in index: %s" % str( e ) + log.error( message, exc_info=True ) + trans.response.status = 500 + return message + return rval diff -r 8019917d7c309b2e9d4ca25078a6bda15569f94f -r 5f10f61335fbcfb7982a879edc80325f5a73402f lib/galaxy/webapps/community/api/repository_revisions.py --- a/lib/galaxy/webapps/community/api/repository_revisions.py +++ b/lib/galaxy/webapps/community/api/repository_revisions.py @@ -1,3 +1,5 @@ +import datetime +from galaxy.web.framework.helpers import time_ago import galaxy.util.shed_util_common as suc from galaxy import web, util from galaxy.web.base.controller import BaseAPIController @@ -10,6 +12,11 @@ log = logging.getLogger( __name__ ) +def default_value_mapper( trans, repository_metadata ): + return { 'id' : trans.security.encode_id( repository_metadata.id ), + 'repository_id' : trans.security.encode_id( repository_metadata.repository_id ), + 'time_last_tested' : time_ago( repository_metadata.time_last_tested ) } + class RepositoryRevisionsController( BaseAPIController ): """RESTful controller for interactions with tool shed repository revisions.""" @web.expose_api @@ -26,13 +33,56 @@ .order_by( trans.app.model.RepositoryMetadata.table.c.repository_id ) \ .all() for repository_metadata in query: - value_mapper={ 'id' : trans.security.encode_id( repository_metadata.id ), - 'repository_id' : trans.security.encode_id( repository_metadata.repository_id ) } - item = repository_metadata.get_api_value( view='collection', value_mapper=value_mapper ) + item = repository_metadata.get_api_value( view='collection', value_mapper=default_value_mapper( trans, repository_metadata ) ) item[ 'url' ] = web.url_for( 'repository_revision', id=trans.security.encode_id( repository_metadata.id ) ) rval.append( item ) except Exception, e: - rval = "Error in repository_revisions API at index: " + str( e ) + rval = "Error in the Tool Shed repository_revisions API in index: " + str( e ) log.error( rval + ": %s" % str( e ) ) trans.response.status = 500 return rval + @web.expose_api + def show( self, trans, id, **kwd ): + """ + GET /api/repository_revisions/{encoded_repository_metadata_id} + Displays information about a repository_metadata record in the Tool Shed. + """ + try: + repository_metadata = suc.get_repository_metadata_by_id( trans, id ) + repository_data = repository_metadata.get_api_value( view='element', value_mapper=default_value_mapper( trans, repository_metadata ) ) + repository_data[ 'contents_url' ] = web.url_for( 'repository_revision_contents', repository_metadata_id=id ) + except Exception, e: + message = "Error in the Tool Shed repository_revisions API in show: %s" % str( e ) + log.error( message, exc_info=True ) + trans.response.status = 500 + return message + return repository_data + @web.expose_api + def update( self, trans, payload, **kwd ): + """ + PUT /api/repository_revisions/{encoded_repository_metadata_id}/{payload} + Updates the value of specified columns of the repository_metadata table based on the key / value pairs in payload. + """ + repository_metadata_id = kwd.get( 'id', None ) + try: + repository_metadata = suc.get_repository_metadata_by_id( trans, repository_metadata_id ) + flush_needed = False + for key, new_value in payload.items(): + if hasattr( repository_metadata, key ): + old_value = getattr( repository_metadata, key ) + setattr( repository_metadata, key, new_value ) + if key in [ 'tools_functionally_correct', 'time_last_tested' ]: + # Automatically update repository_metadata.time_last_tested. + repository_metadata.time_last_tested = datetime.datetime.utcnow() + flush_needed = True + if flush_needed: + trans.sa_session.add( repository_metadata ) + trans.sa_session.flush() + except Exception, e: + message = "Error in the Tool Shed repository_revisions API in update: %s" % str( e ) + log.error( message, exc_info=True ) + trans.response.status = 500 + return message + item = repository_metadata.as_dict( value_mapper=default_value_mapper( trans, repository_metadata ) ) + item[ 'url' ] = web.url_for( 'repository_revision', id=repository_metadata_id ) + return [ item ] diff -r 8019917d7c309b2e9d4ca25078a6bda15569f94f -r 5f10f61335fbcfb7982a879edc80325f5a73402f lib/galaxy/webapps/community/buildapp.py --- a/lib/galaxy/webapps/community/buildapp.py +++ b/lib/galaxy/webapps/community/buildapp.py @@ -77,6 +77,12 @@ name_prefix='repository_', path_prefix='/api/repositories/:repository_id', parent_resources=dict( member_name='repository', collection_name='repositories' ) ) + webapp.api_mapper.resource( 'content', + 'contents', + controller='repository_revision_contents', + name_prefix='repository_revision_', + path_prefix='/api/repository_revisions/:repository_metadata_id', + parent_resources=dict( member_name='repository_revision', collection_name='repository_revisions' ) ) webapp.api_mapper.resource( 'repository', 'repositories', path_prefix='/api' ) webapp.api_mapper.resource( 'repository_revision', 'repository_revisions', path_prefix='/api' ) webapp.finalize_config() diff -r 8019917d7c309b2e9d4ca25078a6bda15569f94f -r 5f10f61335fbcfb7982a879edc80325f5a73402f lib/galaxy/webapps/community/model/__init__.py --- a/lib/galaxy/webapps/community/model/__init__.py +++ b/lib/galaxy/webapps/community/model/__init__.py @@ -133,11 +133,8 @@ self.email_alerts = email_alerts self.times_downloaded = times_downloaded self.deprecated = deprecated - def as_dict( self, trans ): - value_mapper={ 'id' : trans.security.encode_id( self.id ), - 'user_id' : trans.security.encode_id( self.user_id ) } - repository_dict = self.get_api_value( view='element', value_mapper=value_mapper ) - return repository_dict + def as_dict( self, value_mapper=None ): + return self.get_api_value( view='element', value_mapper=value_mapper ) def get_api_value( self, view='collection', value_mapper=None ): if value_mapper is None: value_mapper = {} @@ -194,10 +191,13 @@ fp.close() class RepositoryMetadata( object, APIItem ): - api_collection_visible_keys = ( 'id', 'repository_id', 'changeset_revision', 'malicious', 'downloadable' ) - api_element_visible_keys = ( 'id', 'repository_id', 'changeset_revision', 'malicious', 'downloadable' ) - def __init__( self, repository_id=None, changeset_revision=None, metadata=None, tool_versions=None, malicious=False, downloadable=False, + api_collection_visible_keys = ( 'id', 'repository_id', 'changeset_revision', 'malicious', 'downloadable', 'tools_functionally_correct', + 'do_not_test', 'time_last_tested', 'tool_test_errors' ) + api_element_visible_keys = ( 'id', 'repository_id', 'changeset_revision', 'malicious', 'downloadable', 'tools_functionally_correct', + 'do_not_test', 'time_last_tested', 'tool_test_errors' ) + def __init__( self, id=None, repository_id=None, changeset_revision=None, metadata=None, tool_versions=None, malicious=False, downloadable=False, tools_functionally_correct=False, do_not_test=False, time_last_tested=None, tool_test_errors=None ): + self.id = id self.repository_id = repository_id self.changeset_revision = changeset_revision self.metadata = metadata or dict() @@ -208,6 +208,8 @@ self.do_not_test = do_not_test self.time_last_tested = time_last_tested self.tool_test_errors = tool_test_errors + def as_dict( self, value_mapper=None ): + return self.get_api_value( view='element', value_mapper=value_mapper ) def get_api_value( self, view='collection', value_mapper=None ): if value_mapper is None: value_mapper = {} diff -r 8019917d7c309b2e9d4ca25078a6bda15569f94f -r 5f10f61335fbcfb7982a879edc80325f5a73402f scripts/api/tool_shed_repository_revision_update.py --- /dev/null +++ b/scripts/api/tool_shed_repository_revision_update.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +""" +PUT/update script to update appropriate values in a repository_metadata table record in the Tool Shed. + +usage: tool_shed_repository_revision_update.py key url key1=value1 key2=value2 ... +""" + +import os, sys +sys.path.insert( 0, os.path.dirname( __file__ ) ) +from common import update + +import pkg_resources +pkg_resources.require( "simplejson" ) + +import simplejson + +to_json_string = simplejson.dumps +from_json_string = simplejson.loads + +data = {} +for key, value in [ kwarg.split( '=', 1 ) for kwarg in sys.argv[ 3: ] ]: + """ + This example script will properly handle updating the value of one or more of the following RepositoryMetadata attributes: + tools_functionally_correct, do_not_test, tool_test_errors + """ + if key in [ 'tools_functionally_correct', 'do_not_test' ]: + if str( value ).lower() in [ 'true', 'yes', 'on' ]: + new_value = True + else: + new_value = False + elif key in [ 'tool_test_errors' ]: + new_value = from_json_string( value ) + else: + new_value = str( value ) + data[ key ] = new_value + +update( sys.argv[ 1 ], sys.argv[ 2 ], data ) 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.