comparison ipynb.py @ 1:8e8555ca07f9 draft

Uploaded
author iuc
date Mon, 28 Jul 2014 03:39:07 -0400
parents 7ae1c661a86c
children ed64ded866dd
comparison
equal deleted inserted replaced
0:7ae1c661a86c 1:8e8555ca07f9
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 from galaxy.datatypes.json import Json 3 from galaxy.datatypes.json import Json as JsonClass
4 from galaxy.datatypes.data import get_file_peek 4 from galaxy.datatypes.data import get_file_peek
5 import subprocess 5 import subprocess
6 import tempfile 6 import tempfile
7 import json 7 import json
8 import os 8 import os
9 9
10 class Ipynb( Text ): 10 class Ipynb( JsonClass ):
11 file_ext = "ipynb" 11 file_ext = "ipynb"
12 12
13 def set_peek( self, dataset, is_multi_byte=False ): 13 def set_peek( self, dataset, is_multi_byte=False ):
14 if not dataset.dataset.purged: 14 if not dataset.dataset.purged:
15 dataset.peek = get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte ) 15 dataset.peek = get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
21 def sniff( self, filename ): 21 def sniff( self, filename ):
22 """ 22 """
23 Try to load the string with the json module. If successful it's a json file. 23 Try to load the string with the json module. If successful it's a json file.
24 """ 24 """
25 try: 25 try:
26 json.load( filename ) 26 ipynb = json.load( open(filename) )
27 if a.get('nbformat', False) != False and a.get('metadata', False): 27 if ipynb.get('nbformat', False) != False and ipynb.get('metadata', False):
28 return True 28 return True
29 else: 29 else:
30 return False 30 return False
31 except: 31 except:
32 return False 32 return False