2010-11-18 20:44:30 +03:00
|
|
|
import json
|
2010-09-15 00:22:33 +04:00
|
|
|
import logging
|
2010-11-18 20:44:30 +03:00
|
|
|
import os
|
2010-09-15 00:22:33 +04:00
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
|
2010-11-18 20:44:30 +03:00
|
|
|
from django.core import management
|
|
|
|
|
2010-09-15 00:22:33 +04:00
|
|
|
from celeryutils import task
|
|
|
|
|
|
|
|
from amo.decorators import write
|
2010-11-12 03:39:18 +03:00
|
|
|
from amo.utils import resize_image
|
2010-09-15 00:22:33 +04:00
|
|
|
from files.models import FileUpload
|
|
|
|
|
|
|
|
log = logging.getLogger('z.devhub.task')
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
@write
|
|
|
|
def validator(upload_id, **kw):
|
|
|
|
log.info('VALIDATING: %s' % upload_id)
|
|
|
|
upload = FileUpload.objects.get(pk=upload_id)
|
|
|
|
try:
|
|
|
|
result = _validator(upload)
|
|
|
|
upload.update(validation=result)
|
|
|
|
except:
|
|
|
|
# Store the error with the FileUpload job, then raise
|
|
|
|
# it for normal logging.
|
|
|
|
tb = traceback.format_exception(*sys.exc_info())
|
|
|
|
upload.update(task_error=''.join(tb))
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
def _validator(upload):
|
2010-11-23 21:57:39 +03:00
|
|
|
|
2010-12-10 03:32:22 +03:00
|
|
|
# TODO(Kumar) remove this once we sort
|
|
|
|
# out the js environment. See bug 614574
|
|
|
|
from validator.testcases import scripting
|
|
|
|
scripting.SPIDERMONKEY = None
|
|
|
|
|
2010-12-10 21:46:13 +03:00
|
|
|
# TODO(Kumar) remove this when there is
|
|
|
|
# an easier way. See bug 618364
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import validator
|
|
|
|
with open(os.path.join(os.path.dirname(validator.__file__),
|
|
|
|
'app_versions.json')) as f:
|
|
|
|
from validator.testcases import targetapplication
|
|
|
|
targetapplication.APPROVED_APPLICATIONS = json.loads(f.read())
|
|
|
|
|
2010-09-18 04:06:00 +04:00
|
|
|
# TODO(basta): this should be two lines.
|
|
|
|
# from addon_validator import validate
|
|
|
|
# return validate(path, format='json')
|
|
|
|
from cStringIO import StringIO
|
|
|
|
import validator.main as addon_validator
|
|
|
|
from validator.errorbundler import ErrorBundle
|
|
|
|
from validator.constants import PACKAGE_ANY
|
|
|
|
output = StringIO()
|
2010-12-10 00:27:44 +03:00
|
|
|
|
|
|
|
# determined=True
|
|
|
|
# continue validating each tier even if one has an error
|
|
|
|
# listed=True
|
|
|
|
# the add-on is hosted on AMO
|
|
|
|
eb = ErrorBundle(pipe=output, no_color=True,
|
|
|
|
determined=True, listed=True)
|
2010-09-18 04:06:00 +04:00
|
|
|
addon_validator.prepare_package(eb, upload.path, PACKAGE_ANY)
|
|
|
|
eb.print_json()
|
|
|
|
return output.getvalue()
|
2010-11-12 03:39:18 +03:00
|
|
|
|
|
|
|
|
2010-12-10 03:36:00 +03:00
|
|
|
@task(queue='images')
|
2010-11-12 03:39:18 +03:00
|
|
|
def resize_icon(src, dst, size, **kw):
|
|
|
|
"""Resizes addon icons."""
|
|
|
|
log.info('[1@None] Resizing icon: %s' % dst)
|
|
|
|
|
|
|
|
try:
|
2010-12-10 03:36:00 +03:00
|
|
|
if isinstance(size, list):
|
|
|
|
for s in size:
|
|
|
|
resize_image(src, '%s-%s.png' % (dst, s), (s, s),
|
|
|
|
remove_src=False)
|
|
|
|
os.remove(src)
|
|
|
|
else:
|
|
|
|
resize_image(src, dst, (size, size), remove_src=True)
|
|
|
|
|
2010-11-12 03:39:18 +03:00
|
|
|
except Exception, e:
|
|
|
|
log.error("Error saving addon icon: %s" % e)
|