Пример #1
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}')
Пример #2
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}')
Пример #3
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}')
Пример #4
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}')