add timestamp support to libtorrent status parser
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 30 Apr 2010 10:08:10 +0000 (13:08 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 30 Apr 2010 10:08:13 +0000 (13:08 +0300)
ppf/log-parser/generic/LibtorrentStatusParser.py

index bc84044..572d2c5 100644 (file)
@@ -10,14 +10,18 @@ from GenericStatusParser import GenericStatusParser
 # configure logging (change to logging.ERROR when no DEBUG required)
 logging.basicConfig(level=logging.ERROR)
 
+ONE_SECOND = datetime.timedelta(0, 1)
+
 class LibtorrentStatusParser(GenericStatusParser):
     """
     Abstract-like parser class used for parsing BitTorrent log messages.
     Inherited by client-specific classes
     """
 
-    def __init__(self, filename):
+    def __init__(self, filename, start_time):
         GenericStatusParser.__init__(self, filename)
+        self.start_time = start_time
+        self.timestamp = start_time
 
     # return boolean
     #
@@ -107,7 +111,9 @@ class LibtorrentStatusParser(GenericStatusParser):
             if pair[0] == "eta":
                 eta_seconds = self.timedelta_to_seconds(self.canon_eta(pair[1]))
 
-        return (num_peers, dht, download_speed, upload_speed, download_size, upload_size, eta_seconds)
+        self.timestamp += ONE_SECOND
+
+        return (self.timestamp, num_peers, dht, download_speed, upload_speed, download_size, upload_size, eta_seconds)
 
 
 def main():
@@ -115,7 +121,7 @@ def main():
         print "Usage: %s filename" % (sys.argv[0])
         sys.exit(1)
 
-    sp = LibtorrentStatusParser(sys.argv[1])
+    sp = LibtorrentStatusParser(sys.argv[1], datetime.datetime(2010, 04, 30))
     sp.parse(sp.cb_print)
 
 if __name__ == "__main__":