Ejemplo n.º 1
0
 def handle(self, singlename, *args, **options):
     name_query = (Name.objects.filter(
         duns_count__isnull=False,
         autocomplete_candidate=True).order_by('-duns_count'))
     if singlename is None:
         names = name_query
     else:
         names = name_query.filter(name=singlename)
     self.spinner = ProgressCounter(0, len(names), sys.stdout)
     self.main(names)
Ejemplo n.º 2
0
class Command(BaseCommand):
    help = "Generates a table of auto-complete names."
    option_list = BaseCommand.option_list + (make_option('--singlename',
                                                         action='store',
                                                         dest='singlename',
                                                         type='string',
                                                         default=None), )

    def __init__(self, *args, **kwargs):
        super(BaseCommand, self).__init__(*args, **kwargs)

    def handle(self, singlename, *args, **options):
        name_query = (Name.objects.filter(
            duns_count__isnull=False,
            autocomplete_candidate=True).order_by('-duns_count'))
        if singlename is None:
            names = name_query
        else:
            names = name_query.filter(name=singlename)
        self.spinner = ProgressCounter(0, len(names), sys.stdout)
        self.main(names)

    def main(self, names):
        for pass_number in itertools.count(1):
            print "[%s] Pass %d, names left: %d" % (time.strftime('%H:%M:%S'),
                                                    pass_number, len(names))

            for name in names:
                name1 = Name.objects.get(name=name.name)
                if name1.autocomplete_candidate == True:
                    revocation_set = self.find_revocation_set(name)
                    num_revoked = self.revoke_names(revocation_set)
                self.spinner.tick()
                try:
                    sys.stdout.write(
                        "%s: revoked %d of %d" %
                        (name.name, num_revoked, len(revocation_set)))
                except UnicodeEncodeError, e:
                    print str(e)
                sys.stdout.flush()