Module object_to_moowheel
[hide private]
[frames] | no frames]

Source Code for Module object_to_moowheel

 1  #! /usr/local/bin/python 
 2  #-*- coding: utf-8 -*- 
 3   
 4  """object_to_moowheel.py 
 5   
 6  Visualize data using Javascript and the <canvas> object. 
 7   
 8  http://code.google.com/p/moowheel/ 
 9  """ 
10   
11  __author__ = "Jerome Hussenet, Cedric Bonhomme" 
12  __version__ = "$Revision: 0.1 $" 
13  __date__ = "$Date: 2009/03/26 $" 
14  __copyright__ = "Copyright (c) 2009 Jerome Hussenet, Copyright (c) 2009 Cedric Bonhomme" 
15  __license__ = "Python" 
16   
17  import os 
18  import sys 
19   
20  import pickle 
21   
22   
23 -def object_to_moowheel(obj_file, moo_file):
24 """Generate MooWheel file.""" 25 dic_obj = open(obj_file, "r") 26 if options.verbose: 27 print "Loading dictionary..." 28 dic_ip = pickle.load(dic_obj) 29 30 if options.verbose: 31 print "Creating MooWheel file..." 32 33 wheel_data = '<html>\n\t<head>\n\t<title>IP-Link - MooWheel</title>\n\n' + \ 34 '\t<style type="text/css" media="screen">\n' + \ 35 '\thtml, body { padding: 0; margin: 0;}\n' + \ 36 '\tbody {text-align: left; background-color: #000;\n' + \ 37 '\tpadding: 10px 0 0 10px;}\n' + \ 38 '\tdiv#canvas {display: block; border: 1px solid #fff;\n' + \ 39 '\tbackground-color: #000;\n' + \ 40 '\tfont: 12px Verdana, Tahoma, Arial, sans-serif;' + \ 41 '\tcolor: #fff;}\n\t</style>\n\n' + \ 42 '\t<script type="text/javascript" src="./excanvas.js"></script>\n' + \ 43 '\t<script type="text/javascript" src="./canvastext.js"></script>\n' + \ 44 '\t<script type="text/javascript" src="./mootools-1.2-core-nc.js"></script>\n' + \ 45 '\t<script type="text/javascript" src="./mootools-1.2-more.js"></script>\n' + \ 46 '\t<script type="text/javascript" src="./moowheel.js"></script>\n\n' + \ 47 '\t<script type="text/javascript">\n' + \ 48 '\twindow.onload = function() {\n' + \ 49 '\tvar wheelData = ' 50 51 wheel_data += '[' 52 for ip_src in dic_ip: 53 wheel_data += '\t{"id":"' + ip_src + '", "text":" ' + ip_src + '"' 54 wheel_data += ', "connections":[' 55 56 for ip_dst in dic_ip[ip_src]: 57 wheel_data += '"' + ip_dst + '",\n\t\t' 58 59 wheel_data = wheel_data[:-4] 60 wheel_data += ']},\n' 61 62 wheel_data = wheel_data[:-2] + ']' 63 64 wheel_data += "\n\n\tvar wheel = new MooWheel(wheelData, $('canvas'));" + \ 65 '};\n\t</script>\n\t</head>\n\t<body>\n\t\t<div id="canvas"></div>\n\t</body>\n</html>' 66 67 if options.verbose: 68 print "Writting file." 69 mw = open(moo_file, "w") 70 mw.write(wheel_data) 71 mw.close()
72 73 74 if __name__ == "__main__": 75 # Point of entry in execution mode. 76 from optparse import OptionParser 77 parser = OptionParser() 78 parser.add_option("-i", "--input", dest="obj_file", 79 help="Python serialized object") 80 parser.add_option("-o", "--output", dest="moo_file", 81 help="MooWheel HTML file") 82 parser.add_option("-q", "--quiet", 83 action="store_false", dest="verbose", 84 help="be vewwy quiet (I'm hunting wabbits)") 85 parser.set_defaults(obj_file = './data/dic.pyobj', 86 moo_file = './moowheel/moowheel.html', 87 verbose = True) 88 89 (options, args) = parser.parse_args() 90 91 object_to_moowheel(options.obj_file, options.moo_file) 92