예제 #1
0
def create_tool(slug, title, abbrev, description):
  try:
    tool = Tool.objects.get(tool_slug=slug)
    print "  Updating Tool: " + slug 
    tool.title        = title
    tool.abbrev       = abbrev
    tool.description  = description
    updated_editor     = editor
  except ObjectDoesNotExist:
    print "  Creating Tool: " + slug 
    tool = Tool(tool_slug=slug, title=title, abbrev=abbrev, description=description, updated_editor=editor)
  tool.save()
  return tool
예제 #2
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
                                  )
예제 #3
0
파일: forms.py 프로젝트: jsm91/toolcontrol
 def save(self, force_insert=False, force_update=False, commit=True):
     zeros = len(self.cleaned_data['start_index']) - 1
     if not self.cleaned_data['price']:
         price = self.cleaned_data['model'].price
         service_interval = self.cleaned_data['model'].service_interval
     else:
         price = self.cleaned_data['price']
         service_interval = self.cleaned_data['service_interval']
     for n in range(int(self.cleaned_data['start_index']),
                    self.cleaned_data['end_index']+1):
         name = (self.cleaned_data['prefix'] + 
                 self.get_zeros(n, zeros) + str(n))
         tool = Tool(name = name, 
                     price = price, 
                     service_interval = service_interval,
                     model = self.cleaned_data['model'],
                     invoice_number = self.cleaned_data['invoice_number'],
                     secondary_name = self.cleaned_data['secondary_name'],
                     buy_date = self.cleaned_data['buy_date'],
                     container = self.cleaned_data['container'])
         tool.save()
         event = Event(event_type = "Oprettelse", tool = tool)
         event.save()
예제 #4
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))
예제 #5
0
파일: views.py 프로젝트: matthanger/ngpoc
    def form_valid(self, form):
        f = form.save(commit=False)
        f.owner = self.request.user
        f.slug = slugify_unique(f.name)
        while Integration.objects.filter(slug=f.slug).exists():
            f.slug = slugify_unique(f.name)        

        if form.cleaned_data['bundle_code']:
            bundle_code = form.cleaned_data['bundle_code']
            url = 'https://tpi.bb.pearsoncmg.com/highlander/api/v1/bundles/{}?direct=true'.format(bundle_code)
            req = requests.get(url)
            data = json.loads(req.text)
            bundle_links = data['basicLtiLinkBundle']['links']
            bundle = []

            for link in bundle_links:
                title = link['title']
                custom_params = []
                for param in link['customParameters']:
                    param_name = param['name']
                    param_value = param['value']
                    custom_params.append(
                        '{}={}'.format(param_name, param_value))
                bundle.append({
                    'title': title,
                    'custom_params': custom_params})

            bundle_tool = Tool()
            bundle_tool.owner = self.request.user
            bundle_tool.vendor = Vendor.objects.get(name='Pearson')
            bundle_tool.is_bundle = True
            bundle_tool.bundle_data = json.dumps(bundle, indent=4)
            bundle_tool.launch_url = bundle_links[0]['launchUrl']
            bundle_tool.name = '[bundle] ' + form.cleaned_data['bundle_name']
            bundle_tool.key = form.cleaned_data['bundle_key']
            bundle_tool.secret = form.cleaned_data['bundle_secret']
            bundle_tool.protocol = 'LTI 1'
            bundle_tool.tool_type = 'Provider'
            bundle_tool.save()
            f.tool_provider = bundle_tool

        f.save()
        return super(IntegrationCreate,self).form_valid(form)
예제 #6
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'))
            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))