Mercurial > repos > iuc > datatyp_ipynb
comparison ipynb.py @ 0:7ae1c661a86c draft
Uploaded
| author | iuc |
|---|---|
| date | Mon, 28 Jul 2014 03:21:07 -0400 |
| parents | |
| children | 8e8555ca07f9 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:7ae1c661a86c |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 | |
| 3 from galaxy.datatypes.json import Json | |
| 4 from galaxy.datatypes.data import get_file_peek | |
| 5 import subprocess | |
| 6 import tempfile | |
| 7 import json | |
| 8 import os | |
| 9 | |
| 10 class Ipynb( Text ): | |
| 11 file_ext = "ipynb" | |
| 12 | |
| 13 def set_peek( self, dataset, is_multi_byte=False ): | |
| 14 if not dataset.dataset.purged: | |
| 15 dataset.peek = get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte ) | |
| 16 dataset.blurb = "IPython Notebook" | |
| 17 else: | |
| 18 dataset.peek = 'file does not exist' | |
| 19 dataset.blurb = 'file purged from disc' | |
| 20 | |
| 21 def sniff( self, filename ): | |
| 22 """ | |
| 23 Try to load the string with the json module. If successful it's a json file. | |
| 24 """ | |
| 25 try: | |
| 26 json.load( filename ) | |
| 27 if a.get('nbformat', False) != False and a.get('metadata', False): | |
| 28 return True | |
| 29 else: | |
| 30 return False | |
| 31 except: | |
| 32 return False | |
| 33 | |
| 34 def display_data(self, trans, dataset, preview=False, filename=None, to_ext=None, chunk=None, **kwd): | |
| 35 preview = util.string_as_bool( preview ) | |
| 36 if chunk: | |
| 37 return self.get_chunk(trans, dataset, chunk) | |
| 38 elif to_ext or not preview: | |
| 39 return self._serve_raw(trans, dataset, to_ext) | |
| 40 else: | |
| 41 ofile_handle = tempfile.NamedTemporaryFile(delete=False) | |
| 42 ofilename = file_handle.name | |
| 43 ofile_handle.close() | |
| 44 try: | |
| 45 cmd = 'ipython nbconvert --to html --template basic %s %s' % (dataset.file_name, ofilename) | |
| 46 subprocess.call(cmd) | |
| 47 ofilename = '%s.html' % ofilename | |
| 48 except: | |
| 49 ofilename = dataset.file_name | |
| 50 log.exception( 'Command "%s" failed. Could not convert the IPython Notebook to HTML, defaulting to plain text.' % cmd ) | |
| 51 return open( ofilename ) | |
| 52 """return trans.fill_template( "/dataset/tabular_chunked.mako", | |
| 53 dataset = dataset, | |
| 54 chunk = self.get_chunk(trans, dataset, 0), | |
| 55 column_number = column_number, | |
| 56 column_names = column_names, | |
| 57 column_types = column_types )""" | |
| 58 | |
| 59 def set_meta( self, dataset, **kwd ): | |
| 60 """ | |
| 61 Set the number of models in dataset. | |
| 62 """ | |
| 63 pass | |
| 64 | |
| 65 |
