From: Razvan Deaconescu Date: Mon, 22 Aug 2011 11:37:11 +0000 (+0300) Subject: ppf/new: Add parser.py. X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=4dcb166e27117b4f898949a08cd36975304c8775;p=cs-p2p-next.git ppf/new: Add parser.py. This is going to be the new parser implementation for libtorrent, Tribler and other BitTorrent clients. --- diff --git a/ppf/new/parser.py b/ppf/new/parser.py new file mode 100644 index 0000000..9e5ae1e --- /dev/null +++ b/ppf/new/parser.py @@ -0,0 +1,86 @@ +""" +Storage class for P2P logging information. + +Built on previous work by Adriana Draghici, Marius Sandu-Popa, Razvan +Deaconescu and Mariana Marasoiu. + +2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro +""" + +import os +import os.path +import re +import datetime +import logging + +import storage # Use *Message classes. + +# +# Logging code heavily inspired by Logging HOWTO documentation: +# http://docs.python.org/dev/howto/logging.html#configuring-logging +# + +# Create logger; default logging level is DEBUG. +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + +# Create console handler and set level to ERROR. +ch = logging.StreamHandler() +ch.setLevel(logging.DEBUG) + +# Create formatter. +formatter = logging.Formatter('%(filename)s:%(lineno)s - %(levelname)s: %(message)s') + +# Add formatter to console handler. +ch.setFormatter(formatter) + +# Add console handler to logger. +logger.addHandler(ch) + +class SessionLogParser(object): + """ + Top-level class for parsing log file(s) for a given BitTorrent session. + """ + + def __init__(self, path): + self.path = path + + def get_next_message(self): + """ + Find next message in log file/folder. May be status, peer status + or verbose message. + Return None when all logs have been parsed. + """ + return None + +class LibtorrentLogParser(object): + """ + libtorrent-rasterbar log folder parser. + """ + + def __init__(self, path): + super(LibtorrrentLogParser, self).__init__(path) + + def get_next_message(self): + """ + Go through all files in libtorrent log folder and parse them. + Return the next message available or None when all logs have + been parsed. + """ + return None + +class TriblerLogParser(object): + """ + Tribler log file parser. + """ + + def __init__(self, path): + super(LibtorrrentLogParser, self).__init__(path) + + def get_next_message(self): + """ + Go through all files in libtorrent log folder and parse them. + Return the next message available or None when all logs have + been parsed. + """ + return None