Exemplo n.º 1
0
    def handle(self, *args, **options):
        # get the username argument
        username = options['username']

        # get ICE authentication configured via EDD's config files (secrets.env and / or
        # settings/local.py)
        auth = HmacAuth(key_id=settings.ICE_KEY_ID, username=username)
        ice = IceApi(auth, verify_ssl_cert=settings.VERIFY_ICE_CERT)
        ice.timeout = settings.ICE_REQUEST_TIMEOUT

        try:
            print('Contacting ICE at %s' % ice.base_url)

            part_id = options.get('part_id')

            if part_id:
                print('Requesting part "%s"' % part_id)
                entry = ice.get_entry(part_id)
                if entry:
                    print('Found the part!')
                else:
                    print('Part "%s" was not found in ICE' % part_id)
            else:

                entries_results_page = ice.search_entries()
                if entries_results_page:
                    self.stdout.write(
                        'Successfully searched ICE for entries.\nICE reports %(total_entries)d '
                        'total entries and returned the first page of  %(returned_entries)d'
                        % {
                            'total_entries':
                            entries_results_page.total_result_count,
                            'returned_entries':
                            entries_results_page.current_result_count,
                        })
                else:
                    print(
                        "No known error occurred, but also didn't find any entries in ICE. If "
                        "user %s has any ICE entries visible to him/her, you might want to "
                        "look into this." % username)
        except Exception as e:
            raise CommandError(e)
Exemplo n.º 2
0
    def handle(self, *args, **options):
        # get the username argument
        username = options["username"]

        # get ICE authentication configured via EDD's config files (secrets.env and / or
        # settings/local.py)
        auth = HmacAuth(key_id=settings.ICE_KEY_ID, username=username)
        ice = IceApi(auth, verify_ssl_cert=settings.ICE_VERIFY_CERT)
        ice.timeout = settings.ICE_REQUEST_TIMEOUT

        try:
            self.stdout.write("Contacting ICE at %s" % ice.base_url)

            part_id = options.get("part_id")

            if part_id:
                self.stdout.write('Requesting part "%s"' % part_id)
                entry = ice.get_entry(part_id)
                if entry:
                    self.stdout.write("Found the part!")
                else:
                    self.stdout.write(f'Part "{part_id}" was not found in ICE')
            else:
                search_term = options.get("term", "")
                if options.get("advanced", False):
                    self.stdout.write(
                        f'Searching ICE for term "{search_term}" (advanced search)'
                    )
                    results_page = ice.search_entries(search_term)
                    self.print_advanced_search(results_page, username)

                else:
                    self.stdout.write(
                        f'Searching ICE for term "{search_term}" '
                        f"(simple UI-facing search)")
                    entry_info = ice.search(search_term)
                    self.print_simple_search(entry_info)
        except Exception as e:
            raise CommandError(e)