1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/b681b2aeddbc/ Changeset: b681b2aeddbc User: greg Date: 2013-10-16 22:29:00 Summary: Enhance the Tool Shed API feature supporting resetting metadata on certain repositories to allow for individual repositories per request. Affected #: 3 files diff -r 2a4f4be3c377de638ee280b7a3ae83c62af6038a -r b681b2aeddbc52c3d953abcb431688df6fb8a005 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 @@ -177,6 +177,42 @@ return message @web.expose_api + def repository_ids_for_setting_metadata( self, trans, my_writable=False, **kwd ): + """ + GET /api/get_repository_ids_for_setting_metadata + + Displays a collection (list) of repository ids ordered for setting metadata. + + :param key: the API key of the Tool Shed user. + :param my_writable (optional): if the API key is associated with an admin user in the Tool Shed, setting this param value + to True will restrict resetting metadata to only repositories that are writable by the user + in addition to those repositories of type tool_dependency_definition. This param is ignored + if the current user is not an admin user, in which case this same restriction is automatic. + """ + try: + if trans.user_is_admin(): + my_writable = util.asbool( my_writable ) + else: + my_writable = True + handled_repository_ids = [] + repository_ids = [] + query = suc.get_query_for_setting_metadata_on_repositories( trans, my_writable=my_writable, order=False ) + # Make sure repositories of type tool_dependency_definition are first in the list. + for repository in query: + if repository.type == rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids: + repository_ids.append( trans.security.encode_id( repository.id ) ) + # Now add all remaining repositories to the list. + for repository in query: + if repository.type != rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids: + repository_ids.append( trans.security.encode_id( repository.id ) ) + return repository_ids + except Exception, e: + message = "Error in the Tool Shed repositories API in repository_ids_for_setting_metadata: %s" % str( e ) + log.error( message, exc_info=True ) + trans.response.status = 500 + return message + + @web.expose_api def reset_metadata_on_repositories( self, trans, payload, **kwd ): """ PUT /api/repositories/reset_metadata_on_repositories @@ -239,6 +275,48 @@ trans.response.status = 500 return message + @web.expose_api + def reset_metadata_on_repository( self, trans, payload, **kwd ): + """ + PUT /api/repositories/reset_metadata_on_repository + + Resets all metadata on a specified repository in the Tool Shed. + + :param key: the API key of the Tool Shed user. + + The following parameters must be included in the payload. + :param repository_id: the encoded id of the repository on which metadata is to be reset. + """ + def handle_repository( trans, start_time, repository ): + results = dict( start_time=start_time, + repository_status=[] ) + try: + invalid_file_tups, metadata_dict = metadata_util.reset_all_metadata_on_repository_in_tool_shed( trans, + trans.security.encode_id( repository.id ) ) + if invalid_file_tups: + message = tool_util.generate_message_for_invalid_tools( trans, invalid_file_tups, repository, None, as_html=False ) + else: + message = "Successfully reset metadata on repository %s" % str( repository.name ) + except Exception, e: + message = "Error resetting metadata on repository %s: %s" % ( str( repository.name ), str( e ) ) + + results[ 'repository_status' ].append( message ) + return results + try: + repository_id = payload.get( 'repository_id', None ) + if repository_id is not None: + repository = suc.get_repository_in_tool_shed( trans, repository_id ) + start_time = strftime( "%Y-%m-%d %H:%M:%S" ) + results = handle_repository( trans, start_time, repository ) + stop_time = strftime( "%Y-%m-%d %H:%M:%S" ) + results[ 'stop_time' ] = stop_time + return json.to_json_string( results, sort_keys=True, indent=4 * ' ' ) + except Exception, e: + message = "Error in the Tool Shed repositories API in reset_metadata_on_repositories: %s" % str( e ) + log.error( message, exc_info=True ) + trans.response.status = 500 + return message + @web.expose_api_anonymous def show( self, trans, id, **kwd ): """ diff -r 2a4f4be3c377de638ee280b7a3ae83c62af6038a -r b681b2aeddbc52c3d953abcb431688df6fb8a005 lib/galaxy/webapps/tool_shed/buildapp.py --- a/lib/galaxy/webapps/tool_shed/buildapp.py +++ b/lib/galaxy/webapps/tool_shed/buildapp.py @@ -85,7 +85,9 @@ controller='repositories', collection={ 'get_repository_revision_install_info' : 'GET', 'get_ordered_installable_revisions' : 'GET', - 'reset_metadata_on_repositories' : 'POST' }, + 'repository_ids_for_setting_metadata' : 'GET', + 'reset_metadata_on_repositories' : 'POST', + 'reset_metadata_on_repository' : 'POST' }, name_prefix='repository_', path_prefix='/api', parent_resources=dict( member_name='repository', collection_name='repositories' ) ) diff -r 2a4f4be3c377de638ee280b7a3ae83c62af6038a -r b681b2aeddbc52c3d953abcb431688df6fb8a005 lib/tool_shed/scripts/api/reset_metadata_on_repositories.py --- a/lib/tool_shed/scripts/api/reset_metadata_on_repositories.py +++ b/lib/tool_shed/scripts/api/reset_metadata_on_repositories.py @@ -16,20 +16,37 @@ import os import sys sys.path.insert( 0, os.path.dirname( __file__ ) ) +from common import get from common import submit +def string_as_bool( string ): + if str( string ).lower() in [ 'true' ]: + return True + else: + return False + def main( options ): api_key = options.api my_writable = options.my_writable + one_per_request = options.one_per_request base_tool_shed_url = options.tool_shed_url.rstrip( '/' ) - data = dict( my_writable=my_writable ) - url = '%s/api/repositories/reset_metadata_on_repositories' % base_tool_shed_url - submit( url, data, options.api ) + if string_as_bool( one_per_request ): + url = '%s/api/repositories/repository_ids_for_setting_metadata?key=%s&my_writable=%s' % ( base_tool_shed_url, api_key, str( my_writable ) ) + repository_ids = get( url, api_key ) + for repository_id in repository_ids: + data = dict( repository_id=repository_id ) + url = '%s/api/repositories/reset_metadata_on_repository' % base_tool_shed_url + submit( url, data, options.api ) + else: + data = dict( my_writable=my_writable ) + url = '%s/api/repositories/reset_metadata_on_repositories' % base_tool_shed_url + submit( url, data, options.api ) if __name__ == '__main__': parser = argparse.ArgumentParser( description='Reset metadata on certain repositories in the Tool Shed via the Tool Shed API.' ) parser.add_argument( "-a", "--api", dest="api", required=True, help="API Key" ) parser.add_argument( "-m", "--my_writable", dest="my_writable", required=False, default='False', help="Restrict to my writable repositories" ) + parser.add_argument( "-o", "--one_per_request", dest="one_per_request", required=False, default='False', help="One repository per request" ) parser.add_argument( "-u", "--url", dest="tool_shed_url", required=True, help="Tool Shed URL" ) options = parser.parse_args() main( options ) 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.