示例#1
0
    def reset_metadata_on_installed_repositories(self, trans, payload, **kwd):
        """
        PUT /api/tool_shed_repositories/reset_metadata_on_installed_repositories

        Resets all metadata on all repositories installed into Galaxy in an "orderly fashion".

        :param key: the API key of the Galaxy admin user.
        """
        start_time = strftime("%Y-%m-%d %H:%M:%S")
        results = dict(start_time=start_time,
                       successful_count=0,
                       unsuccessful_count=0,
                       repository_status=[])
        # Make sure the current user's API key proves he is an admin user in this Galaxy instance.
        if not trans.user_is_admin:
            raise HTTPForbidden(
                detail=
                'You are not authorized to reset metadata on repositories installed into this Galaxy instance.'
            )
        irmm = InstalledRepositoryMetadataManager(self.app)
        query = irmm.get_query_for_setting_metadata_on_repositories(
            order=False)
        # Now reset metadata on all remaining repositories.
        for repository in query:
            try:
                irmm.set_repository(repository)
                irmm.reset_all_metadata_on_installed_repository()
                irmm_invalid_file_tups = irmm.get_invalid_file_tups()
                if irmm_invalid_file_tups:
                    message = generate_message_for_invalid_tools(
                        self.app,
                        irmm_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.owner))
                    results['successful_count'] += 1
            except Exception as e:
                message = "Error resetting metadata on repository %s owned by %s: %s" % \
                    (str(repository.name), str(repository.owner), util.unicodify(e))
                results['unsuccessful_count'] += 1
            results['repository_status'].append(message)
        stop_time = strftime("%Y-%m-%d %H:%M:%S")
        results['stop_time'] = stop_time
        return json.dumps(results, sort_keys=True, indent=4)
示例#2
0
 def reset_metadata_on_selected_repositories(self, user, **kwd):
     """
     Inspect the repository changelog to reset metadata for all appropriate changeset revisions.
     This method is called from both Galaxy and the Tool Shed.
     """
     repository_ids = util.listify(kwd.get('repository_ids', None))
     message = ''
     status = 'done'
     if repository_ids:
         successful_count = 0
         unsuccessful_count = 0
         for repository_id in repository_ids:
             try:
                 repository = get_installed_tool_shed_repository(
                     self.app, repository_id)
                 self.set_repository(repository)
                 self.reset_all_metadata_on_installed_repository()
                 if self.invalid_file_tups:
                     message = generate_message_for_invalid_tools(
                         self.app,
                         self.invalid_file_tups,
                         repository,
                         None,
                         as_html=False)
                     log.debug(message)
                     unsuccessful_count += 1
                 else:
                     log.debug(
                         "Successfully reset metadata on repository %s owned by %s"
                         % (str(repository.name), str(repository.owner)))
                     successful_count += 1
             except Exception:
                 log.exception(
                     "Error attempting to reset metadata on repository %s",
                     str(repository.name))
                 unsuccessful_count += 1
         message = "Successfully reset metadata on %d %s.  " % \
             (successful_count, inflector.cond_plural(successful_count, "repository"))
         if unsuccessful_count:
             message += "Error setting metadata on %d %s - see the paster log for details.  " % \
                 (unsuccessful_count, inflector.cond_plural(unsuccessful_count, "repository"))
     else:
         message = 'Select at least one repository to on which to reset all metadata.'
         status = 'error'
     return message, status