Пример #1
0
    def cmd_getautourls(self, *params, **options):

        from linkstop.threadpool import ThreadPool
        thread_pool = ThreadPool(100, 100)

        try:
            count = int(params[0])
        except IndexError:
            count = 10

        got_urls = set(fi[0].split('://', 1)[-1] for fi in FavIcon.objects.all().values_list('url'))

        try:
            for auto_url in AutoUrl.objects.all().exclude(url__in=got_urls).order_by('rank'):
                url = 'http://' + auto_url.url
                thread_pool.job(self.cmd_get, url)
        finally:
            thread_pool.flush_quit()
Пример #2
0
    def cmd_render(self, *params, **options):

        icon_sizes = ','.join(str(s) for s in sorted(settings.DESKTOP_FORCE_ICON_SIZES))
        num_rendered = 0

        from linkstop.threadpool import ThreadPool
        thread_pool = ThreadPool(3, 6)

        try:
            max_renders = int(params[0])
        except IndexError:
            max_renders = None

        qs = FavIcon.objects.filter(rendered=False).order_by('pk')

        media_fs = OSFS(settings.MEDIA_ROOT)
        media_fs.makedir('favicons', allow_recreate=True)

        try:
            for favicon in qs:

                original_sizes = favicon.get_original_sizes()
                if not original_sizes:
                    continue

                remaining_sizes = sorted(set(settings.DESKTOP_FORCE_ICON_SIZES).difference(favicon.get_sizes()))

                for size in remaining_sizes:

                    print "Rendering %ix%i icon" % (size, size)

                    image_path = os.path.join( settings.MEDIA_ROOT,
                                               url_to_path(favicon.url), 'icon%i.png' % original_sizes[-1] )

                    output_path = get_size_path(favicon.url, size)

                    thread_pool.job( render,
                                     (size, size),
                                     image_path,
                                     output_path,
                                     settings.FAVICON_POV_SCENE )

                favicon.sizes = icon_sizes
                favicon.rendered = True
                favicon.save()


                #favicon_path = url_to_path(favicon.url)
                #favicon_fs = media_fs.makeopendir(favicon_path, recursive=True)

                favicon_fs = OSFS(get_icon_directory(favicon.url), create=True)
                favicon.export(favicon_fs.open('scan.pik', 'w'))
                #pickle_path = favicon_fs.getsyspath('scan.pik')

                num_rendered += 1

                if max_renders is not None and num_rendered >= max_renders:
                    break

        finally:
            thread_pool.flush_quit()

        print "%i icon sets rendered" % num_rendered