Пример #1
0
def generate_icon(app):
    im = Image.new(
        "RGB", (128, 128),
        "#" + hashlib.md5(unicode(app.name).encode('utf8')).hexdigest()[:6])
    f = StringIO.StringIO()
    im.save(f, 'png')
    save_icon(app, f.getvalue())
Пример #2
0
    def test_hosted_icon(self):
        app_path = os.path.join(self.apps_path, 'mozball.webapp')
        webapp = self.webapp_from_path(app_path)

        img_path = os.path.join(self.apps_path, 'mozball-128.png')
        with open(img_path, 'r') as content:
            tasks.save_icon(webapp, content.read())
        eq_(webapp.icon_type, self.content_type)

        self.check_icons(webapp)
Пример #3
0
    def test_hosted_icon(self):
        app_path = os.path.join(self.apps_path, 'mozball.webapp')
        webapp = self.webapp_from_path(app_path)

        img_path = os.path.join(self.apps_path, 'mozball-128.png')
        with open(img_path, 'r') as content:
            tasks.save_icon(webapp, content.read())
        eq_(webapp.icon_type, self.content_type)

        self.check_icons(webapp)
Пример #4
0
def generate_apps(num):
    # Let's not make production code depend on stuff in the test package --
    # importing it only when called in local dev is fine.
    from amo.tests import app_factory
    for appname, cat_slug in generate_app_data(num):
        app = app_factory(categories=[cat_slug], name=appname, complete=True,
                          rated=True)
        im = Image.new("RGB", (128, 128),
                       "#" + hashlib.md5(appname + cat_slug).hexdigest()[:6])
        f = StringIO.StringIO()
        im.save(f, 'png')
        save_icon(app, f.getvalue())
Пример #5
0
def fetch_icon(pk, version_pk=None, **kw):
    """Take an extension pk and extract 128x128 icon from its zip file, build
    resized PNG copies of it at the dimensions we use, optimize those and store
    them in our public storage.

    When done, `icon_hash` property should be set on the extension."""
    from mkt.extensions.models import Extension

    extension = Extension.objects.get(pk=pk)
    if version_pk:
        version = extension.versions.get(pk=version_pk)
    else:
        version = extension.latest_public_version
    icon_path = version.manifest.get('icons', {}).get('128', '').lstrip('/')
    if not icon_path:
        return
    with private_storage.open(version.file_path) as fd:
        with ZipFile(fd) as zfd:
            icon_contents = zfd.read(icon_path)
    save_icon(extension, icon_contents)
Пример #6
0
@post_request_task
@write
def fetch_icon(pk, icon_url, **kw):
    """
    Downloads a website icon from the location passed to the task.

    Returns False if icon was not able to be retrieved
    """
    website = Website.objects.get(pk=pk)
    log.info(u'[Website:%s] Fetching icon for website', website.name)

    try:
        response = _fetch_content(icon_url)
    except Exception, e:
        log.error(u'[Website:%s] Failed to fetch icon for website: %s'
                  % (website, e))
        # Set the icon type to empty.
        website.update(icon_type='')
        return False

    try:
        content = get_content_and_check_size(
            response, settings.MAX_ICON_UPLOAD_SIZE)
    except ResponseTooLargeException:
        log.warning(u'[Website:%s] Icon exceeds maximum size', website.name)
        return False

    log.info('[Website:%s] Icon fetching completed, saving icon', website.name)
    save_icon(website, content)
Пример #7
0
    except Exception, e:
        log.error(u'[Website:%s] Failed to fetch icon for website: %s'
                  % (website, e))
        # Set the icon type to empty.
        website.update(icon_type='')
        return False

    try:
        content = get_content_and_check_size(
            response, settings.MAX_ICON_UPLOAD_SIZE)
    except ResponseTooLargeException:
        log.warning(u'[Website:%s] Icon exceeds maximum size', website.name)
        return False

    log.info('[Website:%s] Icon fetching completed, saving icon', website.name)
    save_icon(website, content, sizes)
    return True


@task
@use_master
def fetch_promo_imgs(pk, promo_img_url, **kw):
    """
    Downloads a promo image from the location passed to the task.

    Returns False if promo image was not able to be retrieved
    """
    website = Website.objects.get(pk=pk)
    log.info(u'[Website:%s] Fetching promo img for website', website.name)
    try:
        response = _fetch_content(promo_img_url)
Пример #8
0
def generate_icon(app):
    gen = pydenticon.Generator(8, 8, foreground=foreground)
    img = gen.generate(unicode(app.name), 128, 128,
                       output_format="png")
    save_icon(app, img)
Пример #9
0
def generate_icon(app):
    gen = pydenticon.Generator(8, 8, foreground=foreground)
    img = gen.generate(unicode(app.name), 128, 128,
                       output_format="png")
    save_icon(app, img)
Пример #10
0
    except Exception, e:
        log.error(u'[Website:%s] Failed to fetch icon for website: %s' %
                  (website, e))
        # Set the icon type to empty.
        website.update(icon_type='')
        return False

    try:
        content = get_content_and_check_size(response,
                                             settings.MAX_ICON_UPLOAD_SIZE)
    except ResponseTooLargeException:
        log.warning(u'[Website:%s] Icon exceeds maximum size', website.name)
        return False

    log.info('[Website:%s] Icon fetching completed, saving icon', website.name)
    save_icon(website, content, sizes)
    return True


@task
@use_master
def fetch_promo_imgs(pk, promo_img_url, **kw):
    """
    Downloads a promo image from the location passed to the task.

    Returns False if promo image was not able to be retrieved
    """
    website = Website.objects.get(pk=pk)
    log.info(u'[Website:%s] Fetching promo img for website', website.name)
    try:
        response = _fetch_content(promo_img_url)
Пример #11
0
    except Exception, e:
        log.error(u'[Website:%s] Failed to fetch icon for website: %s'
                  % (website, e))
        # Set the icon type to empty.
        website.update(icon_type='')
        return False

    try:
        content = get_content_and_check_size(
            response, settings.MAX_ICON_UPLOAD_SIZE)
    except ResponseTooLargeException:
        log.warning(u'[Website:%s] Icon exceeds maximum size', website.name)
        return False

    log.info('[Website:%s] Icon fetching completed, saving icon', website.name)
    save_icon(website, content)
    return True


@post_request_task
@use_master
def fetch_promo_imgs(pk, promo_img_url, **kw):
    """
    Downloads a promo image from the location passed to the task.

    Returns False if promo image was not able to be retrieved
    """
    website = Website.objects.get(pk=pk)
    log.info(u'[Website:%s] Fetching promo img for website', website.name)
    try:
        response = _fetch_content(promo_img_url)