Unverified Commit 89b9a50d authored by John Davis's avatar John Davis Committed by GitHub
Browse files

Merge pull request #20827 from arash77/add-pptx-datatype

[25.0] Fix DOCX detection and add PPTX support
parents c47bb0c4 98fae115
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -695,6 +695,9 @@
    <datatype extension="docx" type="galaxy.datatypes.binary:Docx" display_in_upload="true" decription="DOCX is an XML-based file format that is natively used for Microsoft Word documents" description_url="https://www.iso.org/standard/71691.html">
        <infer_from suffix="docx" />
    </datatype>
    <datatype extension="pptx" type="galaxy.datatypes.binary:Pptx" display_in_upload="true" decription="PPTX is an XML-based file format that is natively used for Microsoft PowerPoint presentations" description_url="https://www.iso.org/standard/71691.html">
        <infer_from suffix="pptx" />
    </datatype>
    <datatype extension="btwisted" type="galaxy.datatypes.data:Text" subclass="true"/>
    <datatype extension="cai" type="galaxy.datatypes.data:Text" subclass="true"/>
    <datatype extension="cat_db" type="galaxy.datatypes.data:Text" subclass="true"/>
@@ -1270,6 +1273,8 @@
    <sniffer type="galaxy.datatypes.binary:Edr"/>
    <sniffer type="galaxy.datatypes.binary:Vel"/>
    <sniffer type="galaxy.datatypes.binary:Xlsx"/>
    <sniffer type="galaxy.datatypes.binary:Docx"/>
    <sniffer type="galaxy.datatypes.binary:Pptx"/>
    <sniffer type="galaxy.datatypes.binary:Numpy"/>
    <sniffer type="galaxy.datatypes.qiime2:QIIME2Metadata"/>
    <sniffer type="galaxy.datatypes.qiime2:QIIME2Artifact"/>
+17 −0
Original line number Diff line number Diff line
@@ -3184,6 +3184,7 @@ class Docx(Binary):

    file_ext = "docx"
    compressed = True
    display_behavior = "download"  # Office documents trigger downloads

    def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
        # Docx is compressed in zip format and must not be uncompressed in Galaxy.
@@ -3206,6 +3207,22 @@ class Xlsx(Binary):
        return file_prefix.compressed_mime_type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"


@build_sniff_from_prefix
class Pptx(Binary):
    """Class for PowerPoint 2007 (pptx) files"""

    file_ext = "pptx"
    compressed = True
    display_behavior = "download"  # Office documents trigger downloads

    def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
        # Pptx is compressed in zip format and must not be uncompressed in Galaxy.
        return (
            file_prefix.compressed_mime_type
            == "application/vnd.openxmlformats-officedocument.presentationml.presentation"
        )


@build_sniff_from_prefix
class ExcelXls(Binary):
    """Class describing an Excel (xls) file"""
+6 −1
Original line number Diff line number Diff line
@@ -52,7 +52,12 @@ if TYPE_CHECKING:
log = logging.getLogger(__name__)

SNIFF_PREFIX_BYTES = int(os.environ.get("GALAXY_SNIFF_PREFIX_BYTES", None) or 2**20)
BINARY_MIMETYPES = {"application/pdf", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}
BINARY_MIMETYPES = {
    "application/pdf",
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    "application/vnd.openxmlformats-officedocument.presentationml.presentation",
}


def get_test_fname(fname):