Ejemplo n.º 1
0
class PDFBackend(Backend):
    MAPPING = "pdf"

    def __init__(self, template, **kwargs):
        super(PDFBackend, self).__init__(template, **kwargs)
        self.markdown = MarkdownBackend(
            template,
            html=True,
            file=os.path.join(mkdtemp(prefix="veles-pdf-publish-"), "report.html"),
            image_format="png",
        )
        self.file = kwargs["file"]

    @property
    def file(self):
        return self._file

    @file.setter
    def file(self, value):
        if value is None:
            self._file = None
            return
        if not isinstance(value, string_types) and not hasattr(value, "write"):
            raise TypeError("file must either a path or a file-like object (got %s)" % type(value))
        self._file = value

    def render(self, info):
        try:
            self.markdown.render(info)
            HTML(self.markdown.file).write_pdf(self.file)
            self.info("%s is ready", self.file)
        finally:
            rmtree(os.path.dirname(self.markdown.file))
Ejemplo n.º 2
0
class PDFBackend(Backend):
    MAPPING = "pdf"

    def __init__(self, template, **kwargs):
        super(PDFBackend, self).__init__(template, **kwargs)
        self.markdown = MarkdownBackend(
            template,
            html=True,
            file=os.path.join(mkdtemp(prefix="veles-pdf-publish-"),
                              "report.html"),
            image_format="png")
        self.file = kwargs["file"]

    @property
    def file(self):
        return self._file

    @file.setter
    def file(self, value):
        if value is None:
            self._file = None
            return
        if not isinstance(value, string_types) and not hasattr(value, "write"):
            raise TypeError(
                "file must either a path or a file-like object (got %s)" %
                type(value))
        self._file = value

    def render(self, info):
        try:
            self.markdown.render(info)
            HTML(self.markdown.file).write_pdf(self.file)
            self.info("%s is ready", self.file)
        finally:
            rmtree(os.path.dirname(self.markdown.file))
Ejemplo n.º 3
0
 def __init__(self, template, **kwargs):
     super(PDFBackend, self).__init__(template, **kwargs)
     self.markdown = MarkdownBackend(
         template,
         html=True,
         file=os.path.join(mkdtemp(prefix="veles-pdf-publish-"),
                           "report.html"),
         image_format="png")
     self.file = kwargs["file"]
Ejemplo n.º 4
0
 def __init__(self, template, **kwargs):
     super(PDFBackend, self).__init__(template, **kwargs)
     self.markdown = MarkdownBackend(
         template,
         html=True,
         file=os.path.join(mkdtemp(prefix="veles-pdf-publish-"), "report.html"),
         image_format="png",
     )
     self.file = kwargs["file"]