Detect pdf files on upload [Brad Chapman]. Resolves #357

This commit is contained in:
Kanwei Li
2010-07-02 18:10:45 -04:00
parent 57521e88cf
commit 810c2291de
3 changed files with 22 additions and 2 deletions
+2 -1
View File
@@ -79,7 +79,7 @@
<datatype extension="mafcustomtrack" type="galaxy.datatypes.sequence:MafCustomTrack">
<display file="ucsc/maf_customtrack.xml" />
</datatype>
<datatype extension="pdf" type="galaxy.datatypes.images:Image" mimetype="application/pdf"/>
<datatype extension="pdf" type="galaxy.datatypes.images:Pdf" mimetype="application/pdf"/>
<datatype extension="pileup" type="galaxy.datatypes.tabular:Pileup" display_in_upload="true" />
<datatype extension="png" type="galaxy.datatypes.images:Image" mimetype="image/png"/>
<datatype extension="qual" type="galaxy.datatypes.qualityscore:QualityScore" />
@@ -260,6 +260,7 @@
<sniffer type="galaxy.datatypes.sequence:Fastq"/>
<sniffer type="galaxy.datatypes.interval:Wiggle"/>
<sniffer type="galaxy.datatypes.images:Html"/>
<sniffer type="galaxy.datatypes.images:Pdf"/>
<sniffer type="galaxy.datatypes.sequence:Axt"/>
<sniffer type="galaxy.datatypes.interval:Bed"/>
<sniffer type="galaxy.datatypes.interval:CustomTrack"/>
+13
View File
@@ -23,6 +23,19 @@ class Image( data.Data ):
dataset.peek = 'file does not exist'
dataset.blurb = 'file purged from disk'
class Pdf( Image ):
def sniff(self, filename):
"""Determine if the file is in pdf format.
"""
headers = get_headers(filename, None, 1)
try:
if headers[0][0].startswith("%PDF"):
return True
else:
return False
except IndexError:
return False
def create_applet_tag_peek( class_name, archive, params ):
text = """
<!--[if !IE]>-->
+7 -1
View File
@@ -10,6 +10,7 @@ from galaxy import eggs
import galaxy.model
from galaxy.datatypes import sniff
from galaxy.datatypes.binary import *
from galaxy.datatypes.images import Pdf
from galaxy.datatypes.registry import Registry
from galaxy import util
from galaxy.util.json import *
@@ -85,6 +86,8 @@ def check_bam( temp_name ):
return Bam().sniff( temp_name )
def check_sff( temp_name ):
return Sff().sniff( temp_name )
def check_pdf( temp_name ):
return Pdf().sniff( temp_name )
def check_gzip( temp_name ):
# This method returns a tuple of booleans representing ( is_gzipped, is_valid )
# Make sure we have a gzipped file
@@ -160,6 +163,9 @@ def add_file( dataset, json_file, output_path ):
elif check_sff( dataset.path ):
ext = 'sff'
data_type = 'sff'
elif check_pdf( dataset.path ):
ext = 'pdf'
data_type = 'pdf'
else:
# See if we have a gzipped file, which, if it passes our restrictions, we'll uncompress
is_gzipped, is_valid = check_gzip( dataset.path )
@@ -215,7 +221,7 @@ def add_file( dataset, json_file, output_path ):
return
if not data_type:
if check_binary( dataset.path ):
# We have a binary dataset, but it is not Bam or Sff
# We have a binary dataset, but it is not Bam, Sff or Pdf
data_type = 'binary'
#binary_ok = False
parts = dataset.name.split( "." )