Ejemplo n.º 1
0
    def post(self, request):
        data, errors = RequestSchema().load(request.data)

        errand_boy_transport = UNIXSocketTransport()
        out, err, returncode = errand_boy_transport.run_cmd("wkhtmltopdf -V")

        translified_text = translify(data["text_for_translite"])

        result = {
            "type":
            str(data["type"]),
            "type_value":
            str(data["type"].value),
            "payment_method":
            str(data["payment_method"]),
            "payment_method_value":
            str(data["payment_method"].value),
            "wkhtml":
            out,
            "slug":
            slugify(data["text_for_slug"]),
            "translite":
            translified_text,
            "detranslite":
            detranslify(translified_text),
            "plural_first":
            get_plural(data["int_for_plural"],
                       ("клиенту", "клиентам", "клиентам")),
            "plural_second":
            get_plural(data["int_for_plural"], "секунду,секунды,секунд"),
        }

        return render(request, "test.html", result)
Ejemplo n.º 2
0
def StartErrandBoy():
    """
    Start errand boy.
    """
    errandBoyLogger = logging.getLogger("errand_boy.transports.unixsocket")
    errandBoyLogger.addHandler(logger.streamHandler)
    errandBoyLogger.addHandler(logger.fileHandler)

    if ERRAND_BOY_PROCESS:
        StopErrandBoy()

    if not ERRAND_BOY_TRANSPORT:
        globals()['ERRAND_BOY_TRANSPORT'] = UNIXSocketTransport(
            socket_path='/tmp/errand-boy-%s' % str(uuid.uuid1()))

    def RunErrandBoyServer():
        """
        Run the errand boy server.
        """
        ERRAND_BOY_TRANSPORT.run_server(
            pool_size=ERRAND_BOY_NUM_WORKERS,
            max_accepts=ERRAND_BOY_MAX_ACCEPTS,
            max_child_tasks=ERRAND_BOY_MAX_CHILD_TASKS)
    globals()['ERRAND_BOY_PROCESS'] = \
        multiprocessing.Process(target=RunErrandBoyServer)
    ERRAND_BOY_PROCESS.start()
    count = 0
    while count < 10:
        time.sleep(0.1)
        try:
            ERRAND_BOY_TRANSPORT.run_cmd('test TRUE')
            break
        except IOError:
            pass
Ejemplo n.º 3
0
def _server_fn(socket_path):
    server = UNIXSocketTransport(socket_path=socket_path)
    server.run_server()
Ejemplo n.º 4
0
def get_transport():
    global EB_TRANSPORT
    if EB_TRANSPORT is None:
        EB_TRANSPORT = UNIXSocketTransport(socket_path=cloud.socket_path)
    return EB_TRANSPORT
Ejemplo n.º 5
0
 def subprocess_errand_boy():
     transport = UNIXSocketTransport()
     with transport.get_session() as session:
         yield session.subprocess
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
import re
import sys
from .source import Source
from .configuration import Configuration
from itertools import chain
import io
import codecs
from errand_boy.transports.unixsocket import UNIXSocketTransport


errand_boy_transport = UNIXSocketTransport()


class PDFKit(object):
    """
    Main class that does all generation routine.

    :param url_or_file: str - either a URL, a path to a file or a string containing HTML
                       to convert
    :param type_: str - either 'url', 'file' or 'string'
    :param options: dict (optional) with wkhtmltopdf options, with or w/o '--'
    :param toc: dict (optional) - toc-specific wkhtmltopdf options, with or w/o '--'
    :param cover: str (optional) - url/filename with a cover html page
    :param configuration: (optional) instance of pdfkit.configuration.Configuration()
    """

    class ImproperSourceError(Exception):
        """Wrong source type for stylesheets"""

        def __init__(self, msg):
Ejemplo n.º 7
0
def _server_fn():
    server = UNIXSocketTransport()
    server.run_server()
Ejemplo n.º 8
0
def get_transport():
    global EB_TRANSPORT
    if EB_TRANSPORT is None:
        EB_TRANSPORT = UNIXSocketTransport()
    return EB_TRANSPORT
Ejemplo n.º 9
0
 def subprocess_errand_boy():
     transport = UNIXSocketTransport()
     with transport.get_session() as session:
         yield session.subprocess