1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/87bf6a0324f3/ Changeset: 87bf6a0324f3 User: greg Date: 2014-04-29 20:58:21 Summary: Enhance the Tool Shed API to provide functions for retrieving and creating categories. Affected #: 3 files diff -r 0fee9a84cec6dd78774f30bd60ab7d41d2efc619 -r 87bf6a0324f3182ccf16ad18b662f80272f187bc lib/galaxy/webapps/tool_shed/api/categories.py --- /dev/null +++ b/lib/galaxy/webapps/tool_shed/api/categories.py @@ -0,0 +1,103 @@ +import logging +import os + +from galaxy import util +from galaxy import web +from galaxy.web.base.controller import BaseAPIController +import tool_shed.util.shed_util_common as suc + +log = logging.getLogger( __name__ ) + + +class CategoriesController( BaseAPIController ): + """RESTful controller for interactions with categories in the Tool Shed.""" + + def __get_value_mapper( self, trans ): + value_mapper = { 'id' : trans.security.encode_id } + return value_mapper + + @web.expose_api + def create_category( self, trans, payload, **kwd ): + """ + POST /api/categories/create_category + Returns a dictionary of information about the created category. + +: param key: the current Galaxy admin user's API key + + The following parameters are included in the payload. + :param name (required): the name of the category + :param description (optional): the description of the category (if not provided, the name will be used) + """ + category_dict = dict( message = '', + status = 'ok' ) + # Make sure the current user's API key proves he is an admin user in this Tool Shed. + if trans.user_is_admin(): + # Get the information about the category to be created from the payload. + name = payload.get( 'name', '' ) + if name: + description = payload.get( 'description', '' ) + if not description: + # Default the description to the name. + description = name + if suc.get_category_by_name( trans, name ): + category_dict[ 'message' ] = 'A category with that name already exists' + category_dict[ 'status' ] = 'error' + else: + # Create the category + category = trans.app.model.Category( name=name, description=description ) + trans.sa_session.add( category ) + trans.sa_session.flush() + category_dict = category.to_dict( view='element', + value_mapper=self.__get_value_mapper( trans ) ) + category_dict[ 'message' ] = "Category '%s' has been created" % str( category.name ) + category_dict[ 'url' ] = web.url_for( controller='categories', + action='show', + id=trans.security.encode_id( category.id ) ) + else: + category_dict[ 'message' ] = "Missing required parameter 'name'." + category_dict[ 'status' ] = 'error' + else: + category_dict[ 'message' ] = 'You are not authorized to create a category in this Tool Shed.' + category_dict[ 'status' ] = 'error' + return category_dict + + @web.expose_api_anonymous + def index( self, trans, deleted=False, **kwd ): + """ + GET /api/categories + Returns a list of dictionaries that contain information about each category. + """ + # Example URL: http://localhost:9009/api/categories + category_dicts = [] + deleted = util.asbool( deleted ) + for category in trans.sa_session.query( trans.app.model.Category ) \ + .filter( trans.app.model.Category.table.c.deleted == deleted ) \ + .order_by( trans.app.model.Category.table.c.name ): + category_dict = category.to_dict( view='collection', + value_mapper=self.__get_value_mapper( trans ) ) + category_dict[ 'url' ] = web.url_for( controller='categories', + action='show', + id=trans.security.encode_id( category.id ) ) + category_dicts.append( category_dict ) + return category_dicts + + @web.expose_api_anonymous + def show( self, trans, id, **kwd ): + """ + GET /api/categories/{encoded_category_id} + Returns a dictionary of information about a category. + + :param id: the encoded id of the Repository object + """ + # Example URL: http://localhost:9009/api/categories/f9cad7b01a472135 + category = suc.get_category( trans, id ) + if category is None: + category_dict = dict( message = 'Unable to locate category record for id %s.' % ( str( id ) ), + status = 'error' ) + return category_dict + category_dict = category.to_dict( view='element', + value_mapper=self.__get_value_mapper( trans ) ) + category_dict[ 'url' ] = web.url_for( controller='categories', + action='show', + id=trans.security.encode_id( category.id ) ) + return category_dict diff -r 0fee9a84cec6dd78774f30bd60ab7d41d2efc619 -r 87bf6a0324f3182ccf16ad18b662f80272f187bc lib/galaxy/webapps/tool_shed/buildapp.py --- a/lib/galaxy/webapps/tool_shed/buildapp.py +++ b/lib/galaxy/webapps/tool_shed/buildapp.py @@ -80,6 +80,13 @@ webapp.add_route( '/repos/*path_info', controller='hg', action='handle_request', path_info='/' ) # Add the web API. # A good resource for RESTful services - http://routes.readthedocs.org/en/latest/restful.html webapp.add_api_controllers( 'galaxy.webapps.tool_shed.api', app ) + webapp.mapper.resource( 'category', + 'categories', + controller='categories', + name_prefix='category_', + path_prefix='/api', + new={ 'create_category' : 'POST' }, + parent_resources=dict( member_name='category', collection_name='categories' ) ) webapp.mapper.resource( 'repository', 'repositories', controller='repositories', diff -r 0fee9a84cec6dd78774f30bd60ab7d41d2efc619 -r 87bf6a0324f3182ccf16ad18b662f80272f187bc lib/tool_shed/util/common_install_util.py --- a/lib/tool_shed/util/common_install_util.py +++ b/lib/tool_shed/util/common_install_util.py @@ -470,9 +470,9 @@ # lists of discovered repository dependencies, but these lists will be empty in the # required_repo_info_dict since dependency discovery has not yet been performed for these # dictionaries. - required_repo_infor_dict_key = required_repo_info_dict.keys()[ 0 ] + required_repo_info_dict_key = required_repo_info_dict.keys()[ 0 ] all_repo_info_dicts_keys = [ d.keys()[ 0 ] for d in all_repo_info_dicts ] - if required_repo_infor_dict_key not in all_repo_info_dicts_keys: + if required_repo_info_dict_key not in all_repo_info_dicts_keys: all_repo_info_dicts.append( required_repo_info_dict ) all_required_repo_info_dict[ 'all_repo_info_dicts' ] = all_repo_info_dicts return all_required_repo_info_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.