Ejemplo n.º 1
0
def GET_v1_compile_job_id_src(job_id):
    """Download a completed compile job.
    """
    job = get_job_metadata(job_id)
    if not job:
        return error("Compile job not found", 404)

    if job['result']['firmware']:
        source_zip = qmk_storage.get_fd('%(id)s/%(source_archive)s' % job['result'])
        return send_file(source_zip, mimetype='application/octet-stream', as_attachment=True, attachment_filename=job['result']['source_archive'])

    return error("Compile job not finished or other error.", 422)
Ejemplo n.º 2
0
def GET_v1_compile_job_id_bin(job_id):
    """Download a compiled firmware.

    New clients should prefer the `/download` URL. `/hex` is deprecated and will be removed in a future version.
    """
    job = get_job_metadata(job_id)
    if not job:
        return error("Compile job not found", 404)

    if 'firmware_filename' in job['result']:
        firmware = qmk_storage.get_fd('%(id)s/%(firmware_filename)s' % job['result'])
        return send_file(firmware, mimetype='application/octet-stream', as_attachment=True, attachment_filename=job['result']['firmware_filename'])

    return error("Compile job not finished or other error.", 422)
Ejemplo n.º 3
0
def test_get_fd():
    """Make sure we can get a file with a file-like interface
    """
    test_key = 'qmk_compiler_test_unique_key_name'

    # Make sure our test key doesn't exist
    try:
        qmk_storage.get(test_key)
        raise RuntimeError('%s exists on S3 when it should not!' % test_key)
    except Exception as e:
        if e.__class__.__name__ != 'NoSuchKey':
            raise

    # Create it on S3
    qmk_storage.put(test_key, 'hello')

    # Make sure we can retrieve it
    fd = qmk_storage.get_fd(test_key)
    saved_file = fd.read()
    fd.close()
    qmk_storage.delete(test_key)
    assert saved_file == b'hello'