2 Top level functions for parsing and storing information.
4 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
11 def parse_store_session(swarm_writer, parser, session_id):
12 """Parse and store information for a BitTorrent session.
14 swarm_writer is an instance of storage.SwarmWriter.
15 parser is an instance of parsing.LogParser (may be
16 LibtorrentLogParser, TriblerLogParser or some other).
17 session_id is the client session id.
21 msg = parser.get_next_message()
22 # In case of no more messages, exit loop.
26 msg.set_client_session_id(session_id)
27 writer.add_message(msg)
29 def enhance_swarm_description(swarm_description, swarm_writer):
30 """Enhance swarm description with client session.
32 Client sessions are determined by writing in swarm database. This
33 is accomplished through the use of the swarm_writer.
35 swarm_description is an instance of config.SwarmDescription.
36 swarm_writer is an instance of storage.SwarmWriter.
38 swarm = swarm_description.get_swarm()
39 swarm_id = swarm_writer.add_swarm(swarm)
41 for session_entry in swarm_description.get_session_entries():
42 session = session_entry.get_session()
43 # Add swarm_id to session
44 session.swarm_id = swarm_id
45 session_id = swarm_writer.add_client_session(session)
46 # Update session_id in swarm_description list.
47 swarm_description.update_session_entry_id(session_entry, session_id)
49 def retrieve_log(session_entry):
50 """Retrieve and unpack logs.
52 Retrival may involve copying it from another folder or another
53 system (through SFTP, HTTP, rsync, etc.). If logs are a compressed
54 file that will be unpacked.
56 session_entry is an instance of config.SessionEntry.
57 Return local file location of uncompressed logs.
60 # TODO: Retrieve logs from remote systems (rsync, HTTP, SFTP, etc.).
62 # TODO: Unpack in case of compressed files.
66 def parse_session(session_entry, swarm_writer):
67 """Top-level function for parsing a BitTorrent client session log.
69 Log files are retrieved from remote locations and unpacked then
70 processed through a parser and stored through a swarm writer.
72 session_entry is an instance of config.SessionEntry.
73 swarm_writer is an instance of storage.SwarmWriter.
76 location = retrieve_logs(session_entry)
77 parser = LogParser.create_parser_by_type(session_entry.get_client_type(),
79 session_id = session_entry.get_session_id()
80 parse_store_session(swarm_writer, parser, session_id)
82 def parse_swarm(swarm_description, swarm_writer):
83 """Top-level function for parsing logs for an entire BitTorrent swarm.
85 Swarm description file is enanched, such that swarm and client
86 session information are already stored in the database.
88 session_entry is an instance of config.SessionEntry.
89 swarm_writer is an instance of storage.SwarmWriter.
92 for session_entry in swarm_description.get_session_entries():
93 parse_session_log(session_entry, swarm_writer)