ppf/new: Add top level functions and scripts design proposal.
[cs-p2p-next.git] / ppf / new / top-design-proposal.txt
1 == top.py ==
2
3 parse_store_session(SwarmWriter sw, LogParser p, int session_id)
4 {
5         while True:
6                 msg = parser.get_next_message()
7                 # In case of no more messages, exit loop.
8                 if msg == None:
9                         break
10
11                 msg.set_client_session_id(session_id)
12                 sw.add_message(msg)
13 }
14
15 enhance_swarm_description(SwarmDescription sd, SwarmWriter sw)
16 {
17         sw.add_swarm(sd.get_swarm())
18
19         for section in sd.get_section_list()
20                 session = get_session_from_section(section)
21                 session_id = sw.add_session(session)
22                 sd.update_section_with_session_id(section, session_id)
23 }
24
25 # se is a sesssion section in swarm description file.
26 retrieve_log(SessionEntry se)
27 {
28         rsync, scp, whatever
29         uncompress
30
31         return log_location
32 }
33
34 parse_session_log(SessionEntry se, SwarmWriter sw)
35 {
36         location = retrieve_logs(se)
37
38         p = LogParser.create_parser_by_type(se.get_client_type(), location)
39         sid = se.get_session_id()
40
41         parse_store_session(sw, p, sid)
42 }
43
44 parse_swarm_log(SwarmDescription sd, SwarmWriter sw)
45 {
46         for section in sd.get_section_list()
47                 se = SwarmDescription.get_session_entry(section)
48                 parse_session_log(se, sw)
49 }
50
51 = "Executable" Scripts (use main()) =
52
53 == enhance_swarm_description.py ==
54
55 main()
56 {
57         # arguments are swarm_description_file and access_config_file
58         sd = SwarmDescription.load(swarm_description_file)
59         ac = AccessConfig.load(access_config_file)
60         sw = get_swarm_writer(ac)
61
62         top.enhance_swarm_description(sd, sw)
63
64         sd.store(swarm_description_file)
65 }
66
67 == parse_session_log.py ==
68
69 main()
70 {
71         # arguments are swarm_description_file, access_config_file and section
72         sd = SwarmDescription.load(swarm_description_file)
73         ac = AccessConfig.load(access_config_file)
74         sw = get_swarm_writer(ac)
75
76         se = SwarmDescription.get_session_entry(section)
77         top.parse_session_log(se, ac)
78 }
79
80 == parse_swarm_log.py ==
81
82 main()
83 {
84         # arguments are swarm_description_file and access_config_file
85         sd = SwarmDescription.load(swarm_description_file)
86         ac = AccessConfig.load(access_config_file)
87         sw = get_swarm_writer(ac)
88
89         # Enhance swarm description with session id. Store enhanced file.
90         top.enhance_swarm_description(sd, sw)
91         sd.store(swarm_description_file)
92
93         top.parse_swarm(sd, sw)
94 }