Esempio n. 1
0
def get_download(r, hashtag, filename):
    """
    Download XPI (it has to be ready)
    """
    if not validator.is_valid('alphanum', hashtag):
        log.warning('[security] Wrong hashtag provided')
        return HttpResponseForbidden("{'error': 'Wrong hashtag'}")
    path = os.path.join(settings.XPI_TARGETDIR, '%s.xpi' % hashtag)
    log.info('[xpi:%s] Downloading Addon from %s' % (filename, path))

    tend = time.time()
    tkey = xpi_utils.get_queued_cache_key(hashtag, r)
    tqueued = cache.get(tkey)
    if tqueued:
        ttotal = (tend - tqueued) * 1000
        statsd.timing('xpi.build.total', ttotal)
        total = '%dms' % ttotal
    else:
        total = 'n/a'

    log.info('[xpi:%s] Downloading Add-on (%s)' % (hashtag, total))

    response = serve(r, path, '/', show_indexes=False)
    response['Content-Disposition'] = ('attachment; '
            'filename="%s.xpi"' % filename)
    return response
Esempio n. 2
0
def prepare_test(r, revision_id):
    """
    Test XPI from data saved in the database
    """
    revision = _get_addon(r.user, revision_id)
    hashtag = r.POST.get('hashtag')
    if not hashtag:
        log.warning('[security] No hashtag provided')
        return HttpResponseBadRequest('{"error": "No hashtag"}')
    if not validator.is_valid('alphanum', hashtag):
        log.warning('[security] Wrong hashtag provided')
        return HttpResponseBadRequest("{'error': 'Wrong hashtag'}")
    # prepare codes to be sent to the task
    mod_codes = {}
    att_codes = {}
    if r.POST.get('live_data_testing', False):
        for mod in revision.modules.all():
            if r.POST.get(mod.filename, False):
                code = r.POST.get(mod.filename, '')
                if mod.code != code:
                    mod_codes[str(mod.pk)] = code
        for att in revision.attachments.all():
            if r.POST.get(str(att.pk), False):
                code = r.POST.get(str(att.pk))
                att_codes[str(att.pk)] = code
    if mod_codes or att_codes or not os.path.exists('%s.xpi' %
            os.path.join(settings.XPI_TARGETDIR, hashtag)):
        log.info('[xpi:%s] Addon added to queue' % hashtag)
        tqueued = time.time()
        tkey = xpi_utils.get_queued_cache_key(hashtag, r)
        cache.set(tkey, tqueued, 120)
        tasks.xpi_build_task(rev_pk=revision.pk,
                mod_codes=mod_codes, att_codes=att_codes,
                hashtag=hashtag, tqueued=tqueued)
    return HttpResponse('{"delayed": true}')
Esempio n. 3
0
def get_download(r, hashtag, filename):
    """
    Download XPI (it has to be ready)
    """
    if not validator.is_valid('alphanum', hashtag):
        log.warning('[security] Wrong hashtag provided')
        return HttpResponseForbidden("{'error': 'Wrong hashtag'}")
    path = os.path.join(settings.XPI_TARGETDIR, '%s.xpi' % hashtag)
    log.info('[xpi:%s] Downloading Addon from %s' % (filename, path))

    tend = time.time()
    tkey = xpi_utils.get_queued_cache_key(hashtag, r)
    tqueued = cache.get(tkey)
    if tqueued:
        ttotal = (tend - tqueued) * 1000
        statsd.timing('xpi.build.total', ttotal)
        total = '%dms' % ttotal
    else:
        total = 'n/a'

    log.info('[xpi:%s] Downloading Add-on (%s)' % (hashtag, total))

    response = serve(r, path, '/', show_indexes=False)
    response['Content-Disposition'] = ('attachment; '
                                       'filename="%s.xpi"' % filename)
    return response
Esempio n. 4
0
def prepare_download(r, revision_id):
    """
    Prepare download XPI.  This package is built asynchronously and we assume
    it works. It will be downloaded in %``get_download``
    """
    revision = _get_addon(r.user, revision_id)
    hashtag = r.POST.get('hashtag')
    if not hashtag:
        return HttpResponseForbidden('Add-on Builder has been updated!'
                'We have updated this part of the application. Please '
                'empty your cache and reload to get changes.')
    if not validator.is_valid('alphanum', hashtag):
        log.warning('[security] Wrong hashtag provided')
        return HttpResponseBadRequest("{'error': 'Wrong hashtag'}")
    log.info('[xpi:%s] Addon added to queue' % hashtag)
    tqueued = time.time()
    tkey = xpi_utils.get_queued_cache_key(hashtag, r)
    cache.set(tkey, tqueued, 120)
    tasks.xpi_build_task(rev_pk=revision.pk,
            hashtag=hashtag, tqueued=tqueued)
    return HttpResponse('{"delayed": true}')
Esempio n. 5
0
def prepare_download(r, revision_id):
    """
    Prepare download XPI.  This package is built asynchronously and we assume
    it works. It will be downloaded in %``get_download``
    """
    revision = _get_addon(r.user, revision_id)
    hashtag = r.POST.get('hashtag')
    if not hashtag:
        return HttpResponseForbidden(
            'Add-on Builder has been updated!'
            'We have updated this part of the application. Please '
            'empty your cache and reload to get changes.')
    if not validator.is_valid('alphanum', hashtag):
        log.warning('[security] Wrong hashtag provided')
        return HttpResponseBadRequest("{'error': 'Wrong hashtag'}")
    log.info('[xpi:%s] Addon added to queue' % hashtag)
    tqueued = time.time()
    tkey = xpi_utils.get_queued_cache_key(hashtag, r)
    cache.set(tkey, tqueued, 120)
    tasks.xpi_build_task(rev_pk=revision.pk, hashtag=hashtag, tqueued=tqueued)
    return HttpResponse('{"delayed": true}')
Esempio n. 6
0
def prepare_download(r, id_number, revision_number=None):
    """
    Prepare download XPI.  This package is built asynchronously and we assume
    it works. It will be downloaded in ``get_download``
    """
    revision = get_object_with_related_or_404(PackageRevision,
                        package__id_number=id_number, package__type='a',
                        revision_number=revision_number)
    hashtag = r.POST.get('hashtag')
    if not hashtag:
        return HttpResponseForbidden('Add-on Builder has been updated!'
                'We have updated this part of the application. Please '
                'empty your cache and reload to get changes.')
    if not validator.is_valid('alphanum', hashtag):
        log.warning('[security] Wrong hashtag provided')
        return HttpResponseForbidden("{'error': 'Wrong hashtag'}")
    log.info('[xpi:%s] Addon added to queue' % hashtag)
    tqueued = time.time()
    tkey = xpi_utils.get_queued_cache_key(hashtag, r)
    cache.set(tkey, tqueued, 120)
    tasks.xpi_build_from_model.delay(revision.pk, hashtag=hashtag,
            tqueued=tqueued)
    return HttpResponse('{"delayed": true}')
Esempio n. 7
0
def prepare_test(r, revision_id):
    """
    Test XPI from data saved in the database
    """
    revision = _get_addon(r.user, revision_id)
    hashtag = r.POST.get('hashtag')
    if not hashtag:
        log.warning('[security] No hashtag provided')
        return HttpResponseBadRequest('{"error": "No hashtag"}')
    if not validator.is_valid('alphanum', hashtag):
        log.warning('[security] Wrong hashtag provided')
        return HttpResponseBadRequest("{'error': 'Wrong hashtag'}")
    # prepare codes to be sent to the task
    mod_codes = {}
    att_codes = {}
    if r.POST.get('live_data_testing', False):
        for mod in revision.modules.all():
            if r.POST.get(mod.filename, False):
                code = r.POST.get(mod.filename, '')
                if mod.code != code:
                    mod_codes[str(mod.pk)] = code
        for att in revision.attachments.all():
            if r.POST.get(str(att.pk), False):
                code = r.POST.get(str(att.pk))
                att_codes[str(att.pk)] = code
    if mod_codes or att_codes or not os.path.exists(
            '%s.xpi' % os.path.join(settings.XPI_TARGETDIR, hashtag)):
        log.info('[xpi:%s] Addon added to queue' % hashtag)
        tqueued = time.time()
        tkey = xpi_utils.get_queued_cache_key(hashtag, r)
        cache.set(tkey, tqueued, 120)
        tasks.xpi_build_task(rev_pk=revision.pk,
                             mod_codes=mod_codes,
                             att_codes=att_codes,
                             hashtag=hashtag,
                             tqueued=tqueued)
    return HttpResponse('{"delayed": true}')
Esempio n. 8
0
        return HttpResponse('')

    tend = time.time()
    tread = (tend - tfile) * 1000
    log.info('[xpi:%s] Add-on file found and read (%dms)' % (hashtag, tread))
    statsd.timing('xpi.build.fileread', tread)

    # Clean up
    pkg_json = '%s.json' % base
    if os.path.exists(pkg_json):
        try:
            os.remove(pkg_json)
        except OSError, e:
            log.debug('Error trying to cleanup (%s): %s' % (pkg_json, e))

    tkey = xpi_utils.get_queued_cache_key(hashtag, r)
    tqueued = cache.get(tkey)
    if tqueued:
        ttotal = (tend - tqueued) * 1000
        statsd.timing('xpi.build.total', ttotal)
        total = '%dms' % ttotal
    else:
        total = 'n/a'

    log.info('[xpi:%s] Downloading Add-on (%s)' % (hashtag, total))
    return HttpResponse(xpi, mimetype=mimetype)

@csrf_exempt
@require_POST
def prepare_download(r, revision_id):
    """
Esempio n. 9
0
        return HttpResponse('')

    tend = time.time()
    tread = (tend - tfile) * 1000
    log.info('[xpi:%s] Add-on file found and read (%dms)' % (hashtag, tread))
    statsd.timing('xpi.build.fileread', tread)

    # Clean up
    pkg_json = '%s.json' % base
    if os.path.exists(pkg_json):
        try:
            os.remove(pkg_json)
        except OSError, e:
            log.debug('Error trying to cleanup (%s): %s' % (pkg_json, e))

    tkey = xpi_utils.get_queued_cache_key(hashtag, r)
    tqueued = cache.get(tkey)
    if tqueued:
        ttotal = (tend - tqueued) * 1000
        statsd.timing('xpi.build.total', ttotal)
        total = '%dms' % ttotal
    else:
        total = 'n/a'

    log.info('[xpi:%s] Downloading Add-on (%s)' % (hashtag, total))
    return HttpResponse(xpi, mimetype=mimetype)


@csrf_exempt
@require_POST
def prepare_download(r, revision_id):