本文整理汇总了Python中mkt.developers.tasks.save_icon函数的典型用法代码示例。如果您正苦于以下问题:Python save_icon函数的具体用法?Python save_icon怎么用?Python save_icon使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了save_icon函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_icon
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: test_hosted_icon
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: generate_apps
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())
示例4: fetch_icon
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)
示例5: get_content_and_check_size
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)
示例6: generate_icon
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)