Module serializedList_to_object
|
|
1
2
3
4 """serializedList_to_object
5
6 Reads the data from the serialized list object to generate a serialized graph.
7 """
8
9 __author__ = "Jerome Hussenet, Cedric Bonhomme"
10 __version__ = "$Revision: 0.1 $"
11 __date__ = "$Date: 2009/02/22 $"
12 __copyright__ = "Copyright (c) 2009 Jerome Hussenet, Copyright (c) 2009 Cedric Bonhomme"
13 __license__ = "Python"
14
15 import pickle
16
19 liste_obj = open(objlist_file, "r")
20 liste_ip = pickle.load(liste_obj)
21
22 dic_ip = {}
23 print "Creating graph object..."
24 for tts, ip_src, ip_dst in liste_ip:
25 if ip_src not in dic_ip:
26 dic_ip[ip_src] = {}
27 dic_ip[ip_src][ip_dst] = 1
28 else:
29 if ip_dst not in dic_ip[ip_src]:
30 dic_ip[ip_src][ip_dst] = 1
31 else:
32 dic_ip[ip_src][ip_dst] += 1
33
34 print "Serialization..."
35 dic_obj = open(objgraph_file, "w")
36 pickle.dump(dic_ip, dic_obj)
37 dic_obj.close()
38
39
40 if __name__ == "__main__":
41
42 from optparse import OptionParser
43 parser = OptionParser()
44 parser.add_option("-i", "--input", dest="objlist_file",
45 help="Python serialized list object")
46 parser.add_option("-o", "--output", dest="objgraph_file",
47 help="Python serialized graph object")
48 parser.add_option("-r", "--request", dest="request_type",
49 help="type of the request")
50 parser.add_option("-p", "--parameter", dest="parameter",
51 help="parameter of the request")
52 parser.add_option("-q", "--quiet",
53 action="store_false", dest="verbose",
54 help="be vewwy quiet (I'm hunting wabbits)")
55 parser.set_defaults(objlist_file = './data/list.pyobj',
56 objgraph_file = './data/dic.pyobj',
57 request_type = 'all',
58 parameter = '',
59 verbose = True)
60
61 (options, args) = parser.parse_args()
62
63 if options.request_type != 'all' and options.parameter == '':
64 parser.error("Request parameter needed")
65
66 serializedList_to_object(options.objlist_file, options.objgraph_file,
67 options.request_type, options.parameter)
68