From: Adriana Draghici Date: Sun, 8 Nov 2009 19:53:40 +0000 (+0000) Subject: Tribler: LogParser parses BT_Request messages and writes them to DB. X-Git-Tag: getopt_long~262 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=82ce3898f9141d7ad674b8d7ab2e622dcfe5c43f;p=cs-p2p-next.git Tribler: LogParser parses BT_Request messages and writes them to DB. --- diff --git a/log-parser/tribler/LogParser.py b/log-parser/tribler/LogParser.py index af26310..51527f7 100644 --- a/log-parser/tribler/LogParser.py +++ b/log-parser/tribler/LogParser.py @@ -1,9 +1,13 @@ #!/usr/bin/env python - +# # Parser for verbose messages +# author: Adriana Draghici +# import sys -#from DatabaseWriter import DatabaseWriter +from DatabaseWriter import DatabaseWriter +from DatabaseCommander import DatabaseCommander +import julian import datetime import getopt import re @@ -102,9 +106,13 @@ def tribler_parse_status_file(dbw, client_session_id, filename): if result == None: continue + (timestamp, peer_ip, peer_port, msg_type, index, begin, length, listen_port) = result if DEBUG == True: print result - + + dbw.add_verbose_message(client_session_id, timestamp, peer_ip, peer_port, msg_type, + index, begin, length, listen_port) + except IOError: print "Error processing file %s." %filename @@ -113,8 +121,94 @@ def main_just_parse(): client_session_id = 1 tribler_parse_status_file(None, 1, filename) +def main_with_DB(): + + try: + opts, args = getopt.getopt(sys.argv[1:], "hi:f:", ["help", + "id=", "file="]) + except getopt.GetoptError, err: + print str(err) + usage() + sys.exit(2) + + client_session_id = None + filename = None + database = None + + for o, a in opts: + if o in ("-h", "--help"): + usage() + sys.exit(0) + elif o in ("-i", "--id"): + client_session_id = int(a) + elif o in ("-f", "--file"): + filename = a + else: + assert False, "unhandled option" + + if client_session_id == None: + print "Error: no client session id." + sys.exit(2) + + if filename == None: + print "Error: no status file." + sys.exit(2) + + # no database passed as argument + if len(args) != 1: + print "Error: no database file passed as argument." + sys.exit(2) + database = args[0] + + dbc = DatabaseCommander(database) + + # check for client_session_id, swarm_id, btclient_id + cursor = dbc.select_client_sessions_by_id(client_session_id) + if cursor == None: + print "Error: no client session id (%d) in database." % client_session_id + sys.exit(2) + for session_row in cursor: + pass + + swarm_id = session_row[1] + btclient_id = session_row[2] + + cursor = dbc.select_swarms(swarm_id) + if cursor == None: + print "Error: no swarm id (%d) in database." % swarm_id + sys.exit(2) + for swarm_row in cursor: + pass + + cursor = dbc.select_btclients(btclient_id) + if cursor == None: + print "Error: no client id (%d) in database." % btclient_id + sys.exit(2) + for btclient_row in cursor: + pass + + print "Client session row is: " + print " ", session_row + print "Swarm row is: " + print " ", swarm_row + print "Client row is: " + print " ", btclient_row + print "\nContinue parsing on file %s? (y/n) " % filename, + try: + ans = sys.stdin.readline().strip() + if ans != "y": + sys.exit(0) + except IOError: + print "Error reading standard input." + sys.exit(2) + print "" + + # parse status file + dbw = DatabaseWriter(database) + tribler_parse_status_file(dbw, client_session_id, filename) + if __name__ == "__main__": - sys.exit(main_just_parse()) + sys.exit(main_with_DB()) diff --git a/log-parser/tribler/run_sample_verbose b/log-parser/tribler/run_sample_verbose new file mode 100755 index 0000000..ce20741 --- /dev/null +++ b/log-parser/tribler/run_sample_verbose @@ -0,0 +1,9 @@ +#!/bin/bash + +if test $# -lt 1 + then + echo "Usage: $0 " +else + PYTHONPATH=PYTHONPATH:../../auto/db/ python LogParser.py -i 1 -f $1 ../../auto/db/p2p-next.db; +fi +