comparison neo4j.py @ 21:c48ea98bd3b2 draft

planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc/tree/master/datatypes/neo4j_datatypes commit 84f212526ffc0d9206dcabc86d214860c2c03db5
author sanbi-uwc
date Sat, 25 Jun 2016 20:03:05 -0400
parents 45b969e6ff9a
children 9a98be1659c7
comparison
equal deleted inserted replaced
20:45b969e6ff9a 21:c48ea98bd3b2
18 """ 18 """
19 base class to use for neostore datatypes 19 base class to use for neostore datatypes
20 derived from html - composite datatype elements 20 derived from html - composite datatype elements
21 stored in extra files path 21 stored in extra files path
22 """ 22 """
23 def __init__(self):
24 Html.__init__( self, **kwd )
23 25
24 def get_mime(self): 26 def get_mime(self):
25 """Returns the mime type of the datatype""" 27 """Returns the mime type of the datatype"""
26 return 'text/html' 28 return 'text/html'
27 29
44 def display_data(self, trans, data, preview=False, filename=None, 46 def display_data(self, trans, data, preview=False, filename=None,
45 to_ext=None, size=None, offset=None, **kwd): 47 to_ext=None, size=None, offset=None, **kwd):
46 """Documented as an old display method, but still gets called via tests etc 48 """Documented as an old display method, but still gets called via tests etc
47 This allows us to format the data shown in the central pane via the "eye" icon. 49 This allows us to format the data shown in the central pane via the "eye" icon.
48 """ 50 """
49 trans.response.set_content_type(data.get_mime()) 51 if preview == False:
50 trans.log_event( "Display dataset id: %s" % str( data.id ) ) 52 trans.response.set_content_type(data.get_mime())
53 trans.log_event( "Display dataset id: %s" % str( data.id ) )
51 54
52 # the target directory name 55 # the target directory name
53 dir_name = str(os.path.dirname( trans.app.object_store.get_filename(data.dataset) )) + '/dataset_{}_files/neo4jdb'.format( data.dataset.id ) 56 dir_name = str(os.path.dirname( trans.app.object_store.get_filename(data.dataset) )) + '/dataset_{}_files/neo4jdb'.format( data.dataset.id )
54 57
55 # generate unique filename for this dataset 58 # generate unique filename for this dataset
56 valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' 59 valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
57 fname = ''.join(c in valid_chars and c or '_' for c in data.name)[0:150] 60 fname = ''.join(c in valid_chars and c or '_' for c in data.name)[0:150]
58 61
59 # zip the target directory (dir_name) using the fname 62 # zip the target directory (dir_name) using the fname
60 shutil.make_archive(fname, 'zip', dir_name) 63 shutil.make_archive(fname, 'zip', dir_name)
61 download_zip = fname + '.zip' 64 download_zip = fname + '.zip'
62 65
63 # setup headers for the download 66 # setup headers for the download
64 trans.response.headers['Content-Length'] = int( os.stat( download_zip ).st_size ) 67 trans.response.headers['Content-Length'] = int( os.stat( download_zip ).st_size )
65 trans.response.set_content_type( "application/octet-stream" ) # force octet-stream so Safari doesn't append mime extensions to filename 68 trans.response.set_content_type( "application/octet-stream" ) # force octet-stream so Safari doesn't append mime extensions to filename
66 trans.response.headers["Content-Disposition"] = 'attachment; filename="Galaxy%s-[%s].%s"' % (data.hid, download_zip , "zip") 69 trans.response.headers["Content-Disposition"] = 'attachment; filename="Galaxy%s-[%s].%s"' % (data.hid, download_zip , "zip")
67 70
68 return open( download_zip ) 71 return open( download_zip )
72 else:
73 rval = [
74 '<html><head><title>Files for Composite Dataset (%s)</title></head><p/>\
75 This composite dataset is composed of the following files:<p/><ul>' % (self.file_ext)]
76 for composite_name, composite_file in self.get_composite_files(dataset=data).iteritems():
77 opt_text = ''
78 if composite_file.optional:
79 opt_text = ' (optional)'
80 rval.append('<li><a href="%s">%s</a>%s' % (composite_name, composite_name, opt_text))
81 rval.append('</ul></html>')
82 return "\n".join(rval)
69 83
70 class Neo4jDB(Neo4j, Data): 84 class Neo4jDB(Neo4j, Data):
71 """Class for neo4jDB database files.""" 85 """Class for neo4jDB database files."""
72 file_ext = 'neostore' 86 file_ext = 'neostore'
73 composite_type = 'basic' 87 composite_type = 'basic'