ppf/new: Add parser.py.
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Mon, 22 Aug 2011 11:37:11 +0000 (14:37 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Mon, 22 Aug 2011 11:38:27 +0000 (14:38 +0300)
This is going to be the new parser implementation for libtorrent,
Tribler and other BitTorrent clients.

ppf/new/parser.py [new file with mode: 0644]

diff --git a/ppf/new/parser.py b/ppf/new/parser.py
new file mode 100644 (file)
index 0000000..9e5ae1e
--- /dev/null
@@ -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