Beispiel #1
0
def repackage(r, amo_id, amo_file, target_version=None, sdk_dir=None):
    """Pull amo_id/amo_file.xpi, schedule xpi creation, return hashtag
    """
    # validate entries
    # prepare data
    hashtag = get_random_string(10)
    sdk = SDK.objects.all()[0]
    # if (when?) choosing sdk_dir will be possible
    # sdk = SDK.objects.get(dir=sdk_dir) if sdk_dir else SDK.objects.all()[0]
    sdk_source_dir = sdk.get_source_dir()
    # extract packages
    tasks.repackage.delay(
            amo_id, amo_file, sdk_source_dir, hashtag, target_version)
    # call build xpi task
    # respond with a hashtag which will identify downloadable xpi
    # URL to check if XPI is ready:
    # /xpi/check_download/{hashtag}/
    # URL to download:
    # /xpi/download/{hashtag}/{desired_filename}/
    return HttpResponse('{"hashtag": "%s"}' % hashtag,
            mimetype='application/json')
Beispiel #2
0
def upload_to_amo(rev_pk, hashtag=None):
    """Build XPI and upload to AMO
    Read result and save amo_id
    """
    tstart = time.time()
    if not hashtag:
        hashtag = get_random_string(10)
    revision = PackageRevision.objects.get(pk=rev_pk)
    # save status
    log.debug("[%s] upload - Saving status")
    revision.amo_status = STATUS_UPLOAD_SCHEDULED
    revision.amo_version_name = revision.get_version_name()
    super(PackageRevision, revision).save()
    log.debug("[%s] upload - Building XPI")
    response = revision.build_xpi(
            hashtag=hashtag,
            tstart=tstart)
    # use created XPI
    log.debug("[%s] upload - XPI built - uploading")
    revision.upload_to_amo(hashtag)
    log.debug("[%s] upload finished")
Beispiel #3
0
def upload_to_amo(rev_pk, hashtag=None):
    """Build XPI and upload to AMO
    Read result and save amo_id
    """
    tstart = time.time()
    if not hashtag:
        hashtag = get_random_string(10)
    revision = PackageRevision.objects.get(pk=rev_pk)
    # check if there this Add-on was uploaded with the same version name
    version = revision.get_version_name_only()
    uploaded = (
        PackageRevision.objects.filter(package=revision.package)
        .filter(amo_version_name=version)
        .exclude(amo_status=None)
        .exclude(amo_status=STATUS_UPLOAD_FAILED)
        .exclude(amo_status=STATUS_UPLOAD_SCHEDULED)
    )
    if len(uploaded) > 0:
        log.debug('This Add-on was already uploaded using version "%s"' % version)
        log.debug(revision.amo_status)
        raise SimpleException('This Add-on was already uploaded using version "%s"' % version)
    try:
        PackageRevision.objects.get(
            package=revision.package, amo_version_name=version, amo_status=STATUS_UPLOAD_SCHEDULED
        )
    except:
        pass
    else:
        log.debug("This Add-on is currently scheduled to upload")
        raise SimpleException("This Add-on is currently scheduled to upload")
    # save status
    revision.amo_status = STATUS_UPLOAD_SCHEDULED
    revision.amo_version_name = revision.get_version_name_only()
    super(PackageRevision, revision).save()
    response = revision.build_xpi(hashtag=hashtag, tstart=tstart)
    # use created XPI
    revision.upload_to_amo(hashtag)
Beispiel #4
0
def rebuild(request):
    """Rebuild ``XPI`` file. It can be provided as POST['location']

    :returns: (JSON) contains one field - hashtag it is later used to download
              the xpi using :meth:`xpi.views.check_download` and
              :meth:`xpi.views.get_download`
    """
    # validate entries
    secret = request.POST.get('secret', None)
    if not secret or secret != settings.AMO_SECRET_KEY:
        log.error("Rebuild requested with an invalid key.  Rejecting.")
        return HttpResponseForbidden('Access denied')

    options = request.POST.get('options', None)

    location = request.POST.get('location', None)
    addons = request.POST.get('addons', None)
    upload = request.FILES.get('upload', None)

    if not location and not upload and not addons:
        log.error("Rebuild requested but files weren't specified.  Rejecting.")
        return HttpResponseBadRequest('Please provide XPI files to rebuild')
    if location and upload:
        log.error("Rebuild requested but location and upload provided."
                "Rejecting")
        return HttpResponseBadRequest('Please provide XPI files to rebuild')

    # locate SDK source directory
    sdk_version, sdk_source_dir = _get_sdk_source_dir(
            request.POST.get('sdk_version', None))

    pingback = request.POST.get('pingback', None)
    priority = request.POST.get('priority', None)
    post = request.POST.urlencode()
    if priority and priority == 'high':
        rebuild_task = tasks.high_rebuild
    else:
        rebuild_task = tasks.low_rebuild
    response = {'status': 'success'}
    errors = []
    counter = 0

    if location or upload:
        hashtag = get_random_string(10)
        if location:
            log.debug('[%s] Single rebuild started for location (%s)' %
                    (hashtag, location))
        else:
            log.debug('[%s] Single rebuild started from upload' % hashtag)

        filename = request.POST.get('filename', None)

        try:
            package_overrides = _get_package_overrides(request.POST,
                                                       sdk_version)
        except BadManifestFieldException, err:
            errors.append('[%s] %s' % (hashtag, str(err)))
        else:
            rebuild_task.delay(
                    location, upload, sdk_source_dir, hashtag,
                    package_overrides=package_overrides,
                    filename=filename, pingback=pingback,
                    post=post, options=options)
            counter = counter + 1
Beispiel #5
0
    if priority and priority == 'high':
        rebuild_task = tasks.high_rebuild
    else:
        rebuild_task = tasks.low_rebuild

    response = {'status': 'success'}
    errors = []
    counter = 0
    try:
        addons = simplejson.loads(addons)
    except Exception, err:
        errors.append('[%s] %s' % (hashtag, str(err)))
    else:
        for addon in addons:
            error = False
            hashtag = get_random_string(10)
            try:
                package_overrides = _get_package_overrides(addon, sdk_version)
            except Exception, err:
                errors.append('[%s] %s' % (hashtag, str(err)))
                error = True
            if not error:
                rebuild_task.delay(
                    addon['revision_pk'], hashtag, sdk_version,
                    callback=tasks.rebuild_addon,
                    package_overrides=package_overrides,
                    pingback=pingback,
                    post=post,
                    options=options)
            counter = counter + 1
Beispiel #6
0
def rebuild(request):
    """Rebuild ``XPI`` file. It can be provided as POST['location']

    :returns: (JSON) contains one field - hashtag it is later used to download
              the xpi using :meth:`xpi.views.check_download` and
              :meth:`xpi.views.get_download`
    """
    # log whole request without SECRET
    keys = ('package_key', 'location', 'addons', 'upload', 'priority',
            'options')
    log.debug(("Rebuild request (rebuild):\n - "
        "%s\n") % "\n - ".join(["%s: %s" % (key, request.POST.get(key, 'None'))
            for key in keys]))
    # validate entries
    secret = request.POST.get('secret', None)
    if not secret or secret != settings.AMO_SECRET_KEY:
        log.error("Rebuild requested with an invalid key.  Rejecting.")
        return HttpResponseForbidden('Access denied')

    options = request.POST.get('options', None)

    package_key = request.POST.get('package_key', None)
    location = request.POST.get('location', None)
    addons = request.POST.get('addons', None)
    upload = request.FILES.get('upload', None)

    # validate entry
    if not package_key and not location and not upload and not addons:
        log.error("Rebuild requested but files weren't specified.  Rejecting.")
        return HttpResponseBadRequest('Please provide Add-ons to rebuild')
    if location and upload:
        log.error("Rebuild requested but location and upload provided."
                "Rejecting")
        return HttpResponseBadRequest('location and upload are mutually '
                                      'exclusive')
    if location and package_key:
        log.error("Rebuild requested but location and package_key provided."
                "Rejecting")
        return HttpResponseBadRequest('location and package_key are mutually'
                                      'exclusive')
    if upload and package_key:
        log.error("Rebuild requested but upload and package_key provided."
                "Rejecting")
        return HttpResponseBadRequest('upload and package_key are mutually'
                                      'exclusive')

    # prepare repackage common variables
    # locate SDK source directory
    sdk_version, sdk_source_dir = _get_sdk_source_dir(
            request.POST.get('sdk_version', None))
    pingback = request.POST.get('pingback', None)
    priority = request.POST.get('priority', None)
    if priority and priority == 'high':
        rebuild_task = tasks.high_rebuild
    else:
        rebuild_task = tasks.low_rebuild
    post = request.POST.urlencode()
    response = {'status': 'success'}
    hashtag = get_random_string(10)
    filename = request.POST.get('filename', None)
    errors = []
    counter = 0

    try:
        package_overrides = _get_package_overrides(request.POST,
                                                   sdk_version)
    except BadManifestFieldException, err:
        msg = '[%s] %s' % (hashtag, str(err))
        errors.append(msg)
        log.debug(msg)
Beispiel #7
0
def hashtag(length=10):
    """ return random string """
    return get_random_string(length)