diff --git a/config/datatypes_conf.xml.sample b/config/datatypes_conf.xml.sample index 982f1810ae5f..ff7fe0d43400 100644 --- a/config/datatypes_conf.xml.sample +++ b/config/datatypes_conf.xml.sample @@ -384,6 +384,7 @@ + diff --git a/lib/galaxy/datatypes/binary.py b/lib/galaxy/datatypes/binary.py index 57b1f5223ab8..bff032b9e3df 100644 --- a/lib/galaxy/datatypes/binary.py +++ b/lib/galaxy/datatypes/binary.py @@ -1174,6 +1174,40 @@ def sniff( self, filename ): Binary.register_sniffable_binary_format("xlsx", "xlsx", Xlsx) +class ExcelXls( Binary ): + """Class describing an Excel (xls) file""" + file_ext = "excel.xls" + edam_format = "format_3468" + + def sniff( self, filename ): + mime_type = subprocess.check_output("file --mime-type '{}'".format(filename), shell=True).rstrip() + if mime_type.find("application/vnd.ms-excel") != -1: + return True + else: + return False + + def get_mime( self ): + """Returns the mime type of the datatype""" + return 'application/vnd.ms-excel' + + def set_peek( self, dataset, is_multi_byte=False ): + if not dataset.dataset.purged: + dataset.peek = "Microsoft Excel XLS file" + dataset.blurb = data.nice_size( dataset.get_size() ) + else: + dataset.peek = 'file does not exist' + dataset.blurb = 'file purged from disk' + + def display_peek( self, dataset ): + try: + return dataset.peek + except: + return "Microsoft Excel XLS file (%s)" % ( data.nice_size( dataset.get_size() ) ) + + +Binary.register_sniffable_binary_format("excel.xls", "excel.xls", ExcelXls) + + class Sra( Binary ): """ Sequence Read Archive (SRA) datatype originally from mdshw5/sra-tools-galaxy""" file_ext = 'sra' diff --git a/lib/galaxy/datatypes/sniff.py b/lib/galaxy/datatypes/sniff.py index f2e0ea6e07a6..2214b41cb527 100644 --- a/lib/galaxy/datatypes/sniff.py +++ b/lib/galaxy/datatypes/sniff.py @@ -383,6 +383,9 @@ def guess_ext( fname, sniff_order, is_multi_byte=False ): >>> fname = get_test_fname('diamond_db.dmnd') >>> guess_ext(fname, sniff_order) 'dmnd' + >>> fname = get_test_fname('1.xls') + >>> guess_ext(fname, sniff_order) + 'excel.xls' """ file_ext = None for datatype in sniff_order: diff --git a/lib/galaxy/datatypes/test/1.xls b/lib/galaxy/datatypes/test/1.xls new file mode 100644 index 000000000000..5326aab226cc Binary files /dev/null and b/lib/galaxy/datatypes/test/1.xls differ