Exemple #1
0
def compute_all(converter_name, request):
    converter = ConverterRegistry.get(converter_name)

    sha = compute_sha(request.data)

    if converter.__format__ == 'json':
        if request.json is not None:
            information = request.json
        else:
            raise Exception("No data for a JSON Converter")
    elif converter.__format__ == 'native':
        information = dict(connection=dict(), data=request.data)

    return (
        sha,
        information,
    )
Exemple #2
0
def compute_all(converter_name, request):
    converter = ConverterRegistry.get(converter_name)

    sha = compute_sha(request.data)

    if converter.__format__ == 'json':
        if request.json is not None:
            information = request.json
        else:
            raise Exception("No data for a JSON Converter")
    elif converter.__format__ == 'native':
        information = dict(
            connection=dict(),
            data=request.data
        )

    return (sha, information,)
Exemple #3
0
def call_converter(converter_name):
    """
    :param converter_name: The Converter name
    """

    sync = 'sync' in request.args

    if converter_name not in ConverterRegistry.converters():
        raise UnknownConverter()

    if request.method == 'POST':
        sha, information = compute_all(converter_name, request)

        try:
            log_request(converter_name, sha, information)
        except IntegrityError:
            return jsonify(result='job already done'), 200

        # store in the Redis Queue
        job = current_app.queue.enqueue(run_converter,
                                        converter_name,
                                        information['connection'],
                                        information['data'])

        if sync:
            while job.result is None:
                time.sleep(0.1)

        return jsonify(result='job accepted'), 200
    else:
        query = Converter.query.filter_by(name=converter_name)
        converter = query.first()

        if not converter:
            messages = []
        else:
            messages = converter.messages

        return render_template(
            'converter_show.html',
            converter=converter_name,
            messages=messages
        )
Exemple #4
0
def call_converter(converter_name):
    """
    :param converter_name: The Converter name
    """

    sync = 'sync' in request.args

    if converter_name not in ConverterRegistry.converters():
        raise UnknownConverter()

    if request.method == 'POST':
        sha, information = compute_all(converter_name, request)

        try:
            log_request(converter_name, sha, information)
        except IntegrityError:
            return jsonify(result='job already done'), 200

        # store in the Redis Queue
        job = current_app.queue.enqueue(run_converter, converter_name,
                                        information['connection'],
                                        information['data'])

        if sync:
            while job.result is None:
                time.sleep(0.1)

        return jsonify(result='job accepted'), 200
    else:
        query = Converter.query.filter_by(name=converter_name)
        converter = query.first()

        if not converter:
            messages = []
        else:
            messages = converter.messages

        return render_template('converter_show.html',
                               converter=converter_name,
                               messages=messages)
Exemple #5
0
def index():
    return render_template('index.html',
                           converters=ConverterRegistry.converters())
Exemple #6
0
def index():
    return render_template(
        'index.html',
        converters=ConverterRegistry.converters()
    )