'PUT /api/repositories/reset_metadata_on_repositories
Resets all metadata on all repositories in the Tool Shed in an "orderly fashion".  Since there are currently only two
repository types (tool_dependecy_definition and unrestricted), the order in which metadata is reset is repositories of
type tool_dependecy_definition first followed by repositories of type unrestricted, and only one pass is necessary.  If
a new repository type is introduced, the process will undoubtedly need to be revisited.  To facilitate this order, an
in-memory list of repository ids that have been processed is maintained.
:param key: the API key of the Tool Shed user.
The following parameters can optionally be included in the payload.
: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.
:param encoded_ids_to_skip (optional): a list of encoded repository ids for repositories that should not be processed.
:param skip_file (optional): A local file name that contains the encoded repository ids associated with repositories to skip.
This param can be used as an alternative to the above encoded_ids_to_skip.'

@web.expose_api
def reset_metadata_on_repositories(self, trans, payload, **kwd):

    def handle_repository(trans, rmm, repository, results):
        log.debug(('Resetting    metadata    on    repository    %s' % str(repository.name)))
        try:
            rmm.set_repository(repository)
            rmm.reset_all_metadata_on_repository_in_tool_shed()
            rmm_invalid_file_tups = rmm.get_invalid_file_tups()
            if rmm_invalid_file_tups:
                message = tool_util.generate_message_for_invalid_tools(self.app, rmm_invalid_file_tups, repository, None, as_html=False)
                results['unsuccessful_count'] += 1
            else:
                message = ('Successfully    reset    metadata    on    repository    %s    owned    by    %s' % (str(repository.name), str(repository.user.username)))
                results['successful_count'] += 1
        except Exception as e:
            message = ('Error    resetting    metadata    on    repository    %s    owned    by    %s:    %s' % (str(repository.name), str(repository.user.username), str(e)))
            results['unsuccessful_count'] += 1
        status = ('%s    :    %s' % (str(repository.name), message))
        results['repository_status'].append(status)
        return results
    rmm = repository_metadata_manager.RepositoryMetadataManager(app=self.app, user=trans.user, resetting_all_metadata_on_repository=True, updating_installed_repository=False, persist=False)
    start_time = strftime('%Y-%m-%d    %H:%M:%S')
    results = dict(start_time=start_time, repository_status=[], successful_count=0, unsuccessful_count=0)
    handled_repository_ids = []
    encoded_ids_to_skip = payload.get('encoded_ids_to_skip', [])
    skip_file = payload.get('skip_file', None)
    if (skip_file and os.path.exists(skip_file) and (not encoded_ids_to_skip)):
        lines = open(skip_file, 'rb').readlines()
        for line in lines:
            if line.startswith('#'):
                continue
            encoded_ids_to_skip.append(line.rstrip('\n'))
    if trans.user_is_admin():
        my_writable = util.asbool(payload.get('my_writable', False))
    else:
        my_writable = True
    query = rmm.get_query_for_setting_metadata_on_repositories(my_writable=my_writable, order=False)
    for repository in query:
        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, rmm, repository, results)
    for repository in query:
        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, rmm, repository, results)
    stop_time = strftime('%Y-%m-%d    %H:%M:%S')
    results['stop_time'] = stop_time
    return json.dumps(results, sort_keys=True, indent=4)
