Exemplo n.º 1
0
	def handler(self, message):
		command = message.get('command')
		print 'Handling notebook command %s %s'%(command, datetime.datetime.now().strftime("%H:%M:%S.%f"))
		if command in ('plot', 'head', 'code'):
			print command.title()
			exec('obj = %s(self.resource)'%(command.title()))
			result = obj.handler(message)

		elif command in ('save', 'html', 'tar', 'zip', 'latex', 'markdown'):
			fn = message.get('file')
			folder = notebook_folder(fn)
			result = self.save_notebook(message, fn)
			
			if command in ('html'):
				result = save_html(fn.replace('.note', '.html'), message.get('docmain'))
			elif command in ('tar'):
				result = Tar(self.resource).tar_notebook(fn, folder, fn.replace('.note', '.tgz'))
			elif command in ('zip'):
				result = Zip(self.resource).zip_notebook(fn, folder, fn.replace('.note', '.zip'))
			elif command in ('latex'): 
				result = Latex(self.resource).process_note(fn)
			elif command in ('markdown'): 
				result = Markdown(self.resource).process_note(fn)
				
		elif command in ('render_docmain'):
			result = self.render_docmain(message.get('address'))
			
		else:
			result = {'success': 'undefined command: %s'%(command)}
			
		print 'Returning from notebook command %s %s'%(command, datetime.datetime.now().strftime("%H:%M:%S.%f"))
		return result
Exemplo n.º 2
0
	def parse_bibliography(self, fn):
		data = get_notebook(fn, new_note=self.resource.new_bibliography)
		header_str = '<tr><th>#</th>'
		header_str += ''.join(['<th>%s</th>'%(elem.title()) for elem in self.resource.bibliography_nothon_header])
		header_str += '</tr>'
		note = {'table_header' : header_str}
		note['full_bibliography'] = simplejson.dumps(data)
		note['extra_data'] = simplejson.dumps({'separator': os.sep, 'folder': notebook_folder(fn)})
		return note