Mercurial > repos > sanbi-uwc > neo4j_datatypes
changeset 19:2287178087eb draft
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc/tree/master/datatypes/neo4j_datatypes commit 0f90b9e2eae026ccea40bcc164f142313af7d397
author | sanbi-uwc |
---|---|
date | Thu, 09 Jun 2016 05:52:56 -0400 |
parents | 3472a853df10 |
children | 45b969e6ff9a |
files | neo4j.py |
diffstat | 1 files changed, 32 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/neo4j.py Wed May 18 10:13:46 2016 -0400 +++ b/neo4j.py Thu Jun 09 05:52:56 2016 -0400 @@ -3,11 +3,12 @@ """ import logging import sys -import os from galaxy.datatypes.images import Html from galaxy.datatypes.data import Data, Text -#from galaxy.datatypes.metadata import MetadataElement +from galaxy.datatypes.metadata import MetadataElement +import shutil +import os gal_Log = logging.getLogger(__name__) verbose = True @@ -19,6 +20,16 @@ derived from html - composite datatype elements stored in extra files path """ + MetadataElement( name='neostore', default=None, desc='Neo4j NeoStore File', readonly=True, visible=True, set_in_upload=True, no_value=None ) + MetadataElement( name='neostore_count_file', default=None, desc='Neo4j Count File', readonly=True, visible=True, set_in_upload=True, no_value=None ) + MetadataElement( name="neostore_labeltokenstore_db_file", default=None, desc="Neostore LabelTokenStore File", readonly=True, visible=True, no_value=None ) + MetadataElement( name="neostore_nodestore_file", default=None, desc="Neostore NodeStore File", readonly=True, visible=True, no_value=None) + MetadataElement( name="neostore_propertystore_file", default=None, desc="Neostore Property Store File", readonly=True, visible=True, no_value=None) + MetadataElement( name="neostore_relationship_group_file", default=None, desc="Neostore Relationship Group File", readonly=True, visible=True, no_value=None) + MetadataElement( name="neostore_relationship_file", default=None, desc="Neostore Relationship File", readonly=True, visible=True, no_value=None) + MetadataElement( name="neostore_relationship_type_file", default=None, desc="Neostore Relationship Type File", readonly=True, visible=True, no_value=None) + MetadataElement( name="neostore_schema_store_file", default=None, desc="Neostore Schema Store File", readonly=True, visible=True, no_value=None) + MetadataElement( name="neostore_transaction_db_file", default=None, desc="Neostore Transaction File", readonly=True, visible=True, no_value=None) def get_mime(self): """Returns the mime type of the datatype""" @@ -45,25 +56,26 @@ """Documented as an old display method, but still gets called via tests etc This allows us to format the data shown in the central pane via the "eye" icon. """ - if filename is not None and filename != "index": - # Change nothing - important for the unit tests to access child files: - return Data.display_data(self, trans, data, preview, filename, - to_ext, size, offset, **kwd) - if self.file_ext == "neostore": - title = "This is a NEO4J database" - msg = "" - try: - # Try to use any text recorded in the dummy index file: - handle = open(data.file_name, "rU") - msg = handle.read().strip() - handle.close() - except Exception: - pass - if not msg: - msg = title - # Galaxy assumes HTML for the display of composite datatypes, - return "<html><head><title>%s</title></head><body><pre>%s</pre></body></html>" % (title, msg) + trans.response.set_content_type(data.get_mime()) + trans.log_event( "Display dataset id: %s" % str( data.id ) ) + + # the target directory name + dir_name = str(os.path.dirname( trans.app.object_store.get_filename(data.dataset) )) + '/dataset_{}_files/neo4jdb'.format( data.dataset.id ) + + # generate unique filename for this dataset + valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + fname = ''.join(c in valid_chars and c or '_' for c in data.name)[0:150] + # zip the target directory (dir_name) using the fname + shutil.make_archive(fname, 'zip', dir_name) + download_zip = fname + '.zip' + + # setup headers for the download + trans.response.headers['Content-Length'] = int( os.stat( download_zip ).st_size ) + trans.response.set_content_type( "application/octet-stream" ) # force octet-stream so Safari doesn't append mime extensions to filename + trans.response.headers["Content-Disposition"] = 'attachment; filename="Galaxy%s-[%s].%s"' % (data.hid, download_zip , "zip") + + return open( download_zip ) class Neo4jDB(Neo4j, Data): """Class for neo4jDB database files."""