ppf/new: Add top.py.
[cs-p2p-next.git] / ppf / new / top.py
1 """
2 Top level functions for parsing and storing information.
3
4 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
5 """
6
7 import storage
8 import parsing
9
10 def parse_store_session(writer, parser, session_id):
11     """
12     Parse and store information for a BitTorrent session.
13
14     writer is an instance of the storage.SwarmWriter class.
15     parser is an instance of the parsing.LogParser class (may be
16         LibtorrentLogParser, TriblerLogParser or some other).
17     session_id is the client session id.
18     """
19
20     while True:
21         msg = parser.get_next_message()
22         # In case of no more messages, exit loop.
23         if msg == None:
24             break
25
26         msg.set_client_session_id(session_id)
27         writer.add_message(msg)