comparison compressed.py @ 0:9e4c4b66b4a0

Imported from capsule None
author cmonjeau
date Tue, 07 Jul 2015 08:49:14 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9e4c4b66b4a0
1
2 """
3 Compressed classes
4 """
5
6 import mimetypes, logging, os, os.path, sys, time, tempfile, shutil, string, glob, re, zipfile, tarfile
7
8 from galaxy.datatypes.data import Data
9 from galaxy.datatypes.sniff import *
10 from cgi import escape
11 from inspect import isclass
12 from galaxy import util
13 from galaxy.datatypes.metadata import MetadataElement #import directly to maintain ease of use in Datatype class definitions
14 from galaxy.util import inflector
15 from galaxy.util.bunch import Bunch
16 from galaxy.util.odict import odict
17 from galaxy.util.sanitize_html import sanitize_html
18 from galaxy.datatypes.checkers import *
19 from galaxy.datatypes import data
20
21
22 log = logging.getLogger(__name__)
23
24 class Zip( Data ):
25 file_ext = "zip"
26
27 def set_peek( self, dataset, is_multi_byte=False ):
28 """Set the peek and blurb text"""
29 if not dataset.dataset.purged:
30 dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
31 else:
32 dataset.peek = 'file does not exist'
33 dataset.blurb = 'file purged from disk'
34
35 def sniff( self, filename ):
36 if (check_zip( filename )):
37 return True
38 return False
39
40
41 class Tgz( Data ):
42 file_ext = "tar.gz"
43
44 def set_peek( self, dataset, is_multi_byte=False ):
45 """Set the peek and blurb text"""
46 if not dataset.dataset.purged:
47 dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
48 else:
49 dataset.peek = 'file does not exist'
50 dataset.blurb = 'file purged from disk'
51
52 def sniff( self, filename ):
53 is_gzipped, is_valid = check_gzip( filename )
54 is_tar = tarfile.is_tarfile( filename )
55 return (is_gzipped and is_valid and is_tar)
56
57
58 class Tbz2( Data ):
59 file_ext = "tar.bz2"
60
61 def set_peek( self, dataset, is_multi_byte=False ):
62 """Set the peek and blurb text"""
63 if not dataset.dataset.purged:
64 dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
65 else:
66 dataset.peek = 'file does not exist'
67 dataset.blurb = 'file purged from disk'
68
69 def sniff( self, filename ):
70 is_bzipped, is_valid = check_bz2( filename )
71 is_tar = tarfile.is_tarfile( filename )
72 return (is_bzipped and is_valid and is_tar)
73
74
75 class Fastqgz( Data ):
76 file_ext = "fastq.gz"
77
78 def set_peek( self, dataset, is_multi_byte=False ):
79 """Set the peek and blurb text"""
80 if not dataset.dataset.purged:
81 dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
82 else:
83 dataset.peek = 'file does not exist'
84 dataset.blurb = 'file purged from disk'
85
86 def sniff( self, filename ):
87 is_gzipped, is_valid = check_gzip( filename )
88 is_tar = tarfile.is_tarfile( filename )
89 return (is_gzipped and is_valid and not is_tar)
90
91 class Fastqbz2( Data ):
92 file_ext = "fastq.bz2"
93
94 def set_peek( self, dataset, is_multi_byte=False ):
95 """Set the peek and blurb text"""
96 if not dataset.dataset.purged:
97 dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
98 else:
99 dataset.peek = 'file does not exist'
100 dataset.blurb = 'file purged from disk'
101
102 def sniff( self, filename ):
103 is_bzipped, is_valid = check_bz2( filename )
104 is_tar = tarfile.is_tarfile( filename )
105 return (is_bzipped and is_valid and not is_tar)