annotate taxtastic.py @ 7:b6ece07bec6a draft

planemo upload commit 45906ba522c7c319067e93d5cd5d7161223c3336
author bcclaywell
date Mon, 12 Oct 2015 15:59:59 -0400
parents d4690e65afcd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
1 import os
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
2 import zipfile
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
3 from galaxy.datatypes.binary import Binary
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
4 from galaxy.datatypes.data import Text
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
5
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
6 class Refpkg(Text):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
7 composite_type = "basic"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
8
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
9 def __init__(self, **kwd):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
10 Text.__init__(self, **kwd)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
11 self.add_composite_file("CONTENTS.json")
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
12
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
13 def get_mime(self):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
14 return "application/json"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
15
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
16 class RefpkgZip(Binary):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
17 file_ext = "refpkg.zip"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
18
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
19 def __init__(self, **kwd):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
20 Binary.__init__(self, **kwd)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
21
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
22 def sniff(self, filename):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
23 if not zipfile.is_zipfile(filename):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
24 return False
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
25 contains_contents_file = False
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
26 zip_file = zipfile.ZipFile(filename, "r")
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
27 for name in zip_file.namelist():
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
28 if os.path.basename(name) == "CONTENTS.json":
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
29 contains_contents_file = True
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
30 break
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
31 zip_file.close()
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
32 if not contains_contents_file:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
33 return False
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
34 return True
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
35
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
36 def get_mime(self):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
37 return "application/zip"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
38
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
39 class OfficeXlsx(Binary):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
40 file_ext = "xlsx"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
41
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
42 def __init__(self, **kwd):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
43 Binary.__init__(self, **kwd)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
44
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
45 # TODO: this should check for an xl/ directory also
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
46 def sniff(self, filename):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
47 if not zipfile.is_zipfile(filename):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
48 return False
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
49 contains_contents_file = False
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
50 zip_file = zipfile.ZipFile(filename, "r")
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
51 for name in zip_file.namelist():
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
52 if os.path.basename(name) == "[Content_Types].xml":
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
53 contains_contents_file = True
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
54 break
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
55 zip_file.close()
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
56 if not contains_contents_file:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
57 return False
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
58 return True
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
59
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
60 def get_mime(self):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
61 return "application/zip"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
62
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
63 Binary.register_sniffable_binary_format("refpkg.zip", "refpkg.zip", RefpkgZip)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
64 Binary.register_sniffable_binary_format("xlsx", "xlsx", OfficeXlsx)