commit/galaxy-central: greg: Clean up the tool shed api methods.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/353a42c6aa21/ changeset: 353a42c6aa21 user: greg date: 2013-03-20 20:09:43 summary: Clean up the tool shed api methods. affected #: 4 files diff -r fde3df1cfee9e7fdf09ac4ad5e02e47623fb3eab -r 353a42c6aa216db1603d565ec7565d1cae68c050 lib/galaxy/webapps/tool_shed/api/repositories.py --- a/lib/galaxy/webapps/tool_shed/api/repositories.py +++ b/lib/galaxy/webapps/tool_shed/api/repositories.py @@ -1,24 +1,21 @@ +import logging import tool_shed.util.shed_util_common as suc from galaxy import web, util from galaxy.web.base.controller import BaseAPIController -from galaxy.web.framework.helpers import is_true - -import pkg_resources -pkg_resources.require( "Routes" ) -import routes -import logging log = logging.getLogger( __name__ ) + class RepositoriesController( BaseAPIController ): """RESTful controller for interactions with repositories in the Tool Shed.""" + @web.expose_api def index( self, trans, deleted=False, **kwd ): """ - GET /api/repository_revisions + GET /api/repositories Displays a collection (list) of repositories. """ - rval = [] + repository_dicts = [] deleted = util.string_as_bool( deleted ) try: query = trans.sa_session.query( trans.app.model.Repository ) \ @@ -28,30 +25,37 @@ for repository in query: value_mapper={ 'id' : trans.security.encode_id( repository.id ), 'user_id' : trans.security.encode_id( repository.user_id ) } - item = repository.get_api_value( view='collection', value_mapper=value_mapper ) - item[ 'url' ] = web.url_for( 'repository_contents', repository_id=trans.security.encode_id( repository.id ) ) - rval.append( item ) + repository_dict = repository.get_api_value( view='collection', value_mapper=value_mapper ) + repository_dict[ 'url' ] = web.url_for( controller='repository_contents', + action='index', + repository_id=trans.security.encode_id( repository.id ) ) + repository_dicts.append( repository_dict ) + return repository_dicts except Exception, 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 - return rval + @web.expose_api def show( self, trans, id, **kwd ): """ GET /api/repositories/{encoded_repository_id} Displays information about a repository in the Tool Shed. + + :param id: the encoded id of the `Repository` object """ try: repository = suc.get_repository_in_tool_shed( trans, id ) value_mapper={ 'id' : trans.security.encode_id( repository.id ), 'user_id' : trans.security.encode_id( repository.user_id ) } - repository_data = repository.get_api_value( view='element', value_mapper=value_mapper ) - repository_data[ 'contents_url' ] = web.url_for( 'repository_contents', repository_id=id ) + repository_dict = repository.get_api_value( view='element', value_mapper=value_mapper ) + repository_dict[ 'url' ] = web.url_for( controller='repository_contents', + action='index', + repository_id=trans.security.encode_id( repository.id ) ) + return repository_dict except Exception, 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 diff -r fde3df1cfee9e7fdf09ac4ad5e02e47623fb3eab -r 353a42c6aa216db1603d565ec7565d1cae68c050 lib/galaxy/webapps/tool_shed/api/repository_contents.py --- a/lib/galaxy/webapps/tool_shed/api/repository_contents.py +++ b/lib/galaxy/webapps/tool_shed/api/repository_contents.py @@ -3,33 +3,31 @@ from galaxy import web from galaxy.web.base.controller import BaseAPIController -import pkg_resources -pkg_resources.require( "Routes" ) -import routes - log = logging.getLogger( __name__ ) + class RepositoryContentsController( BaseAPIController ): + @web.expose_api def index( self, trans, **kwd ): """ - GET /api/repositories/{encoded_repository_id}/contents + GET /api/repositories/{encoded_repository_id} Displays a collection (dictionary) of repository contents. - :param repository_id: an encoded id string of the `Repository` to inspect + :param repository_id: the encoded id of the `Repository` object """ - rval = [] - repository_id = kwd.get( 'repository_id', None ) try: + repository_id = kwd[ 'repository_id' ] repository = suc.get_repository_in_tool_shed( trans, repository_id ) - value_mapper={ 'id' : repository_id, + value_mapper={ 'id' : trans.security.encode_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 ) + repository_dict[ 'url' ] = web.url_for( controller='repository_contents', + action='index', + repository_id=repository_id ) + return repository_dict except Exception, 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 - return rval diff -r fde3df1cfee9e7fdf09ac4ad5e02e47623fb3eab -r 353a42c6aa216db1603d565ec7565d1cae68c050 lib/galaxy/webapps/tool_shed/api/repository_revision_contents.py --- a/lib/galaxy/webapps/tool_shed/api/repository_revision_contents.py +++ b/lib/galaxy/webapps/tool_shed/api/repository_revision_contents.py @@ -1,14 +1,9 @@ import logging +from galaxy import web from galaxy.web.framework.helpers import time_ago -import tool_shed.util.shed_util_common as suc from tool_shed.util import metadata_util -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 ): @@ -18,25 +13,27 @@ value_mapper[ 'time_last_tested' ] = time_ago( repository_metadata.time_last_tested ) return value_mapper + class RepositoryRevisionContentsController( BaseAPIController ): + @web.expose_api def index( self, trans, **kwd ): """ - GET /api/repository_revisions/{encoded_repository_metadata_id}/contents + GET /api/repository_revisions/{encoded_repository_metadata_id} Displays a collection (dictionary) of repository_metadata contents. - :param repository_metadata_id: an encoded id string of the `RepositoryMetadata` to inspect + :param repository_metadata_id: the encoded id of the `RepositoryMetadata` object """ - rval = [] - repository_metadata_id = kwd.get( 'repository_metadata_id', None ) try: + repository_metadata_id = kwd.get( 'repository_metadata_id', None ) repository_metadata = metadata_util.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 ) + repository_dict[ 'url' ] = web.url_for( controller='repository_revision_contents', + action='index', + repository_metadata_id=repository_metadata_id ) + return repository_dict except Exception, e: - message = "Error in the Tool Shed repository_revision_contents API in index: %s" % str( 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 fde3df1cfee9e7fdf09ac4ad5e02e47623fb3eab -r 353a42c6aa216db1603d565ec7565d1cae68c050 lib/galaxy/webapps/tool_shed/api/repository_revisions.py --- a/lib/galaxy/webapps/tool_shed/api/repository_revisions.py +++ b/lib/galaxy/webapps/tool_shed/api/repository_revisions.py @@ -1,16 +1,9 @@ -import datetime +import datetime, logging from galaxy.web.framework.helpers import time_ago -import tool_shed.util.shed_util_common as suc from tool_shed.util import metadata_util from galaxy import web, util -from galaxy.model.orm import and_, or_ +from galaxy.model.orm import and_ from galaxy.web.base.controller import BaseAPIController -from galaxy.web.framework.helpers import is_true - -import pkg_resources -pkg_resources.require( "Routes" ) -import routes -import logging log = logging.getLogger( __name__ ) @@ -21,15 +14,17 @@ value_mapper[ 'time_last_tested' ] = time_ago( repository_metadata.time_last_tested ) return value_mapper + class RepositoryRevisionsController( BaseAPIController ): """RESTful controller for interactions with tool shed repository revisions.""" + @web.expose_api def index( self, trans, **kwd ): """ GET /api/repository_revisions Displays a collection (list) of repository revisions. """ - rval = [] + repository_metadata_dicts = [] # Build up an anded clause list of filters. clause_list = [] # Filter by downloadable if received. @@ -58,32 +53,40 @@ .order_by( trans.app.model.RepositoryMetadata.table.c.repository_id ) \ .all() for repository_metadata in query: - 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 ) + repository_metadata_dict = repository_metadata.get_api_value( view='collection', + value_mapper=default_value_mapper( trans, repository_metadata ) ) + repository_metadata_dict[ 'url' ] = web.url_for( controller='repository_revision_contents', + action='index', + repository_metadata_id=trans.security.encode_id( repository_metadata.id ) ) + repository_metadata_dicts.append( repository_metadata_dict ) + return repository_metadata_dicts except Exception, e: - rval = "Error in the Tool Shed repository_revisions API in index: " + str( e ) - log.error( rval + ": %s" % str( e ) ) + message = "Error in the Tool Shed repository_revisions API in index: " + str( e ) + log.error( message, exc_info=True ) trans.response.status = 500 - return rval + return message + @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. + + :param id: the encoded id of the `RepositoryMetadata` object """ try: repository_metadata = metadata_util.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 ) + repository_metadata_dict = repository_metadata.as_dict( value_mapper=default_value_mapper( trans, repository_metadata ) ) + repository_metadata_dict[ 'url' ] = web.url_for( controller='repository_revision_contents', + action='index', + repository_metadata_id=trans.security.encode_id( repository_metadata.id ) ) + return repository_metadata_dict 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 ): """ @@ -110,6 +113,8 @@ 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 ] + repository_metadata_dict = repository_metadata.as_dict( value_mapper=default_value_mapper( trans, repository_metadata ) ) + repository_metadata_dict[ 'url' ] = web.url_for( controller='repository_revision_contents', + action='index', + repository_metadata_id=trans.security.encode_id( repository_metadata.id ) ) + return repository_metadata_dict 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