Exemple #1
0
    def import_new_tools(self, request, queryset):
        """
        Import tools description from Galaxy server
        """
        for galaxy_server in queryset:
            tool_import_report = Tool.import_tools(galaxy_server)

            if tool_import_report['new']:
                self.message_user(request, "%s successfully imported new tools." % (len(tool_import_report['new'])))
            else:
                self.message_user(request, "No new tools imported.",
                                  level=messages.WARNING
                                  )
Exemple #2
0
    def import_tools(self, galaxy_url, query, tool_id, force):
        tools_found = []

        if galaxy_url:
            galaxy_server, created = Server.objects.get_or_create(
                url=galaxy_url)
        else:
            try:
                galaxy_server = Server.objects.get(current=True)
            except Server.DoesNotExist:
                raise CommandError(
                    'Server Galaxy does not exist, please use --galaxyurl')

        tools_url = '%s/%s/%s/' % (galaxy_server.url, 'api', 'tools')
        if tool_id:
            # search specific tool
            tools_url_id = '%s/%s/' % (tools_url, tool_id)
            connection = requests.get(tools_url_id).json()
            if 'traceback' in connection:
                raise CommandError('Tool {} was not found in {}'.format(
                    tool_id, galaxy_server.url))
            tools_found.append(connection.get('id'))
        else:
            # fetch list of tools
            connection = requests.get(tools_url, params={'in_panel': "false"})
            if connection.status_code == 200:
                tools_list = connection.json() or []
            for tool in tools_list:
                _m = [
                    tool.get('id').lower(),
                    tool.get('name').lower(),
                    str(tool.get('panel_section_name')).lower()
                ]
                if query in _m:
                    tools_found.append(tool.get('id'))

        if tools_found:
            self.stdout.write("%s" % ('\n'.join(tools_found)))
            response = 'y' if force else raw_input(
                'Do you want (re)import this tool(s)? [y/N] from {}:'.format(
                    galaxy_server))
            if response.lower() == 'y':
                import_tools_report = Tool.import_tools(galaxy_server,
                                                        tools=tools_found,
                                                        force=force)
                if import_tools_report['new']:
                    self.stdout.write(
                        self.style.SUCCESS(
                            "%s successfully imported new tools." %
                            (len(import_tools_report['new']))))
                    for ti in import_tools_report['new']:
                        self.stdout.write(
                            self.style.SUCCESS("%s %s successfully imported" %
                                               (ti.name, ti.version)))
                else:
                    self.stdout.write(
                        self.style.WARNING("No new tool has been imported"))

                for tool_id in import_tools_report['error']:
                    self.stdout.write(
                        self.style.ERROR("import of %s has failed " %
                                         (tool_id)))
        else:
            self.stdout.write("No result was found for query  %s" % (query))
    def import_tools(self, galaxy_url, query, tool_id, force):
        tools_found = []

        if galaxy_url:
            galaxy_server, created = Server.objects.get_or_create(
                url=galaxy_url)
        else:
            try:
                galaxy_server = Server.objects.get(current=True)
            except Server.DoesNotExist:
                raise CommandError(
                    'Server Galaxy does not exist, please use --galaxyurl')

        tools_url = '%s/%s/%s/' % (galaxy_server.url, 'api', 'tools')
        if tool_id:
            # search specific tool
            tools_url_id = '%s/%s/' % (tools_url, tool_id)
            connection = requests.get(tools_url_id).json()
            if 'traceback' in connection:
                raise CommandError('Tool {} was not found in {}'.format(
                    tool_id, galaxy_server.url))
            tools_found.append(connection.get('id'))
        else:
            # fetch list of tools
            connection = requests.get(tools_url, params={'in_panel': "false"})
            if connection.status_code == 200:
                tools_list = connection.json() or []
                for tool in tools_list:
                    _m = [
                        tool.get('id').lower(),
                        tool.get('name').lower(),
                        str(tool.get('panel_section_name')).lower()
                    ]
                    if query in _m:
                        tools_found.append(tool.get('id'))
            else:
                raise CommandError('Cannot connect to Galaxy server {}'.format(galaxy_server.url))
        if tools_found:
            self.stdout.write("%s" % ('\n'.join(tools_found)))
            response = 'y' if force else raw_input(
                'Do you want (re)import this tool(s)? [y/N] from {}:'.format(galaxy_server))
            if response.lower() == 'y':
                import_tools_report = Tool.import_tools(
                    galaxy_server, tools=tools_found,
                    force=force)
                if import_tools_report['new']:
                    self.stdout.write(
                        self.style.SUCCESS(
                            "%s successfully imported new tools." %
                            (len(import_tools_report['new']))))
                    for ti in import_tools_report['new']:
                        self.stdout.write(
                            self.style.SUCCESS(
                                "%s %s successfully imported" %
                                (ti.name, ti.version))
                        )
                else:
                    self.stdout.write(self.style.WARNING(
                        "No new tool has been imported"))

                for tool_id in import_tools_report['error']:
                    self.stdout.write(
                        self.style.ERROR(
                            "import of %s has failed " % (tool_id))
                    )
        else:
            self.stdout.write("No result was found for query  %s" % (query))