How to use the paperwork-backend.paperwork_backend.docimport.BaseImporter function in paperwork-backend

To help you get started, we’ve selected a few paperwork-backend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpaperwork / paperwork / paperwork-backend / paperwork_backend / docimport.py View on Github external
def get_select_mime_types():
        return [
            (_("PDF folder"), "inode/directory"),
        ]

    @staticmethod
    def get_mime_types():
        return [
            ("PDF", "application/pdf"),
        ]

    def __str__(self):
        return _("Import each PDF in the folder as a new document")


class ImageDirectoryImporter(BaseImporter):
    """
    Import many PDF files as many documents
    """

    def __init__(self, fs):
        super().__init__(fs, ImgDoc.IMPORT_IMG_EXTENSIONS)

    def can_import(self, file_uris, current_doc=None):
        """
        Check that the specified file looks like a directory containing many
        pdf files
        """
        if len(file_uris) <= 0:
            return False

        for file_uri in file_uris:
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / docimport.py View on Github external
def check_file_type(self, file_uri):
        # TODO(Jflesch): should use fs.py
        lfile_uri = file_uri.lower()
        for extension in self.file_extensions:
            if lfile_uri.endswith(extension):
                return True
        gfile = Gio.File.new_for_uri(file_uri)
        info = gfile.query_info(
            "standard::content-type", Gio.FileQueryInfoFlags.NONE
        )
        mime = info.get_content_type()
        return mime in [m[1] for m in self.get_mime_types()]


class PdfImporter(BaseImporter):
    """
    Import a single PDF file as a document
    """

    def __init__(self, fs):
        super().__init__(fs, [".pdf"])

    def can_import(self, file_uris, current_doc=None):
        """
        Check that the specified file looks like a PDF
        """
        if len(file_uris) <= 0:
            return False
        for uri in file_uris:
            uri = self.fs.safe(uri)
            if not self.check_file_type(uri):
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / docimport.py View on Github external
def get_mime_types():
        return IMG_MIME_TYPES

    @staticmethod
    def get_select_mime_types():
        return [
            (_("Image folder"), "inode/directory"),
        ]

    def __str__(self):
        return (
            _("Import all image files in the folder in the current document")
        )


class ImageImporter(BaseImporter):
    """
    Import a single image file (in a format supported by PIL). It is either
    added to a document (if one is specified) or as a new document (--> with a
    single page)
    """

    def __init__(self, fs):
        super().__init__(fs, ImgDoc.IMPORT_IMG_EXTENSIONS)

    def can_import(self, file_uris, current_doc=None):
        """
        Check that the specified file looks like an image supported by PIL
        """
        if len(file_uris) <= 0:
            return False
        for file_uri in file_uris:
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / docimport.py View on Github external
def get_select_mime_types():
        return [
            ("PDF", "application/pdf"),
        ]

    @staticmethod
    def get_mime_types():
        return [
            ("PDF", "application/pdf"),
        ]

    def __str__(self):
        return _("Import PDF")


class PdfDirectoryImporter(BaseImporter):
    """
    Import a directory containing many PDF files as many documents
    """

    def __init__(self, fs):
        super().__init__(fs, [".pdf"])

    def can_import(self, file_uris, current_doc=None):
        """
        Check that the specified file looks like a directory containing many
        pdf files
        """
        if len(file_uris) <= 0:
            return False

        for file_uri in file_uris: