theme checksum migration, with hashbang (bug 641644)

This commit is contained in:
Kevin Ngo 2013-05-15 14:05:43 -07:00
Родитель 9f75f28d92
Коммит 4089bb10f7
2 изменённых файлов: 44 добавлений и 40 удалений

Просмотреть файл

@ -1,41 +1,2 @@
from celeryutils import task
import commonware.log
from PIL import Image
from addons.forms import make_checksum
from addons.models import Persona
from amo.decorators import write
from amo.utils import chunked
log = commonware.log.getLogger('z.addons')
@task
@write
def calc_checksum(theme_id, **kw):
theme = Persona.objects.get(id=theme_id)
header = theme.header_path
footer = theme.footer_path
# Delete invalid themes that are not images (e.g. PDF, EXE).
try:
Image.open(header)
Image.open(footer)
except IOError:
theme.addon.delete()
theme.delete()
return
# Calculate checksum and save.
try:
theme.checksum = make_checksum(header, footer)
theme.save()
except Exception as e:
log.error(str(e))
def run():
"""Calculate checksums for all themes."""
pks = Persona.objects.filter(checksum='').values_list('id', flat=True)
for chunk in chunked(pks, 1000):
[calc_checksum.delay(pk) for pk in chunk]
pass

Просмотреть файл

@ -0,0 +1,43 @@
#!/usr/bin/env python
from celeryutils import task
import commonware.log
from PIL import Image
from addons.forms import make_checksum
from addons.models import Persona
from amo.decorators import write
from amo.utils import chunked
log = commonware.log.getLogger('z.addons')
@task
@write
def calc_checksum(theme_id, **kw):
theme = Persona.objects.get(id=theme_id)
header = theme.header_path
footer = theme.footer_path
# Delete invalid themes that are not images (e.g. PDF, EXE).
try:
Image.open(header)
Image.open(footer)
except IOError:
theme.addon.delete()
theme.delete()
return
# Calculate checksum and save.
try:
theme.checksum = make_checksum(header, footer)
theme.save()
except Exception as e:
log.error(str(e))
def run():
"""Calculate checksums for all themes."""
pks = Persona.objects.filter(checksum='').values_list('id', flat=True)
for chunk in chunked(pks, 1000):
[calc_checksum.delay(pk) for pk in chunk]