commit/galaxy-central: greg: Allow for skipping specified repositories when setting metadata in the tool shed.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/01975234fe5b/ Changeset: 01975234fe5b User: greg Date: 2013-10-17 17:18:05 Summary: Allow for skipping specified repositories when setting metadata in the tool shed. Affected #: 3 files diff -r 329ea7a83af4f389a7c95ee4559d88c6fec0211b -r 01975234fe5b2ea1058dee188b5032155a43499b 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 @@ -230,6 +230,7 @@ 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. + :param encoded_ids_to_skip (optional): a list of encoded repository ids for repositories that should not be processed. """ def handle_repository( trans, repository, results ): repository_id = trans.security.encode_id( repository.id ) @@ -253,6 +254,7 @@ successful_count=0, unsuccessful_count=0 ) handled_repository_ids = [] + encoded_ids_to_skip = payload.get( 'encoded_ids_to_skip', [] ) if trans.user_is_admin(): my_writable = util.asbool( payload.get( 'my_writable', False ) ) else: @@ -260,11 +262,19 @@ query = suc.get_query_for_setting_metadata_on_repositories( trans, my_writable=my_writable, order=False ) # First reset metadata on all repositories of type repository_dependency_definition. for repository in query: - if repository.type == rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids: + encoded_id = trans.security.encode_id( repository.id ) + if encoded_id in encoded_ids_to_skip: + log.debug( "Skipping repository with id %s because it is in encoded_ids_to_skip %s" % \ + ( str( repository_id ), str( encoded_ids_to_skip ) ) ) + elif repository.type == rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids: results = handle_repository( trans, repository, results ) # Now reset metadata on all remaining repositories. for repository in query: - if repository.type != rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids: + encoded_id = trans.security.encode_id( repository.id ) + if encoded_id in encoded_ids_to_skip: + log.debug( "Skipping repository with id %s because it is in encoded_ids_to_skip %s" % \ + ( str( repository_id ), str( encoded_ids_to_skip ) ) ) + elif repository.type != rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids: results = handle_repository( trans, repository, results ) stop_time = strftime( "%Y-%m-%d %H:%M:%S" ) results[ 'stop_time' ] = stop_time diff -r 329ea7a83af4f389a7c95ee4559d88c6fec0211b -r 01975234fe5b2ea1058dee188b5032155a43499b 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 @@ -27,18 +27,29 @@ def main( options ): api_key = options.api + base_tool_shed_url = options.tool_shed_url.rstrip( '/' ) my_writable = options.my_writable one_per_request = options.one_per_request - base_tool_shed_url = options.tool_shed_url.rstrip( '/' ) + skip_file = options.skip_file + encoded_ids_to_skip = [] + if skip_file and os.path.exists( skip_file ): + # Contents of file must be 1 encoded repository id per line. + contents = open( skip_file, 'rb' ).read() + if contents: + encoded_ids_to_skip = contents.split( '\n' ) 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 ) + if repository_id in encoded_ids_to_skip: + print "Skipping repository with id %s because it is in skip file %s" % ( str( repository_id ), str( skip_file ) ) + else: + 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 ) + data = dict( encoded_ids_to_skip=encoded_ids_to_skip, + my_writable=my_writable ) url = '%s/api/repositories/reset_metadata_on_repositories' % base_tool_shed_url submit( url, data, options.api ) @@ -46,7 +57,8 @@ 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( "-o", "--one_per_request", dest="one_per_request", required=False, default='True', help="One repository per request" ) + parser.add_argument( "-s", "--skip_file", dest="skip_file", required=False, help="Name of local file containing encoded repository ids to skip" ) parser.add_argument( "-u", "--url", dest="tool_shed_url", required=True, help="Tool Shed URL" ) options = parser.parse_args() main( options ) diff -r 329ea7a83af4f389a7c95ee4559d88c6fec0211b -r 01975234fe5b2ea1058dee188b5032155a43499b lib/tool_shed/util/shed_util_common.py --- a/lib/tool_shed/util/shed_util_common.py +++ b/lib/tool_shed/util/shed_util_common.py @@ -821,12 +821,12 @@ clause_list = [] for repository in trans.sa_session.query( trans.model.Repository ) \ .filter( trans.model.Repository.table.c.deleted == False ): - allow_push = repository.allow_push( trans.app ) - if not order: - # We've been called from the Tool Shed API, so reset metadata on all repositories of type tool_dependency_definition. - if repository.type == rt_util.TOOL_DEPENDENCY_DEFINITION: - clause_list.append( trans.model.Repository.table.c.id == repository.id ) - elif allow_push: + # Always reset metadata on all repositories of type tool_dependency_definition. + if repository.type == rt_util.TOOL_DEPENDENCY_DEFINITION: + clause_list.append( trans.model.Repository.table.c.id == repository.id ) + else: + allow_push = repository.allow_push( trans.app ) + if allow_push: # Include all repositories that are writable by the current user. allow_push_usernames = allow_push.split( ',' ) if username in allow_push_usernames: 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