ppf: LibtorrentStatusParser parses timestamp from status file
authorP2P-Next <p2p-next@cs.pub.ro>
Tue, 17 Aug 2010 12:32:23 +0000 (15:32 +0300)
committerP2P-Next <p2p-next@cs.pub.ro>
Tue, 17 Aug 2010 12:32:23 +0000 (15:32 +0300)
ppf/log-parser/generic/GenericStatusParser.py
ppf/log-parser/generic/LibtorrentStatusParser.py

index efead77..67b82b0 100644 (file)
@@ -102,7 +102,8 @@ class GenericStatusParser:
             download_speed, upload_speed,
             download_size, upload_size,
             eta_seconds):
-        print "time = %s, ps = %d, dht = %d, ds = %d kb/s, us = %d kb/s, dsize = %d bytes, usize = %d bytes" % (timestamp.strftime("%H:%M:%S %d/%m/%y"), num_peers, dht, download_speed, upload_speed, download_size, upload_size)
+        print "time = %s, ps = %d, dht = %d, ds = %d kb/s, us = %d kb/s, dsize = %d bytes, usize = %d bytes" % (timestamp.strftime("%H:%M:%S %d-%m-%y"), 
+                    num_peers, dht, download_speed, upload_speed, download_size, upload_size)
 
     def parse(self, callback_func, callback_arg = None):
         try:
index 572d2c5..802310d 100644 (file)
@@ -39,6 +39,20 @@ class LibtorrentStatusParser(GenericStatusParser):
     #
     def canon_dht(self, non_canon_value):
         return int(non_canon_value)
+    
+    # return datetime object
+    #
+    def canon_datetime(self, non_canon_value):
+        string_parts = re.split("\ *", non_canon_value)
+        if len(string_parts) != 2:
+            return None
+        date_array = string_parts[0].split("-");
+        time_array = string_parts[1].split(":");
+        if len(date_array) != 3 or len(time_array) != 3:
+            return None
+        timestamp = datetime.datetime(int(date_array[2]), int(date_array[1]), int(date_array[0]), #year, month, day
+                                        int(time_array[0]), int(time_array[1]), int(time_array[2])) #hour, min, sec
+        return timestamp
 
     # return integer
     #
@@ -93,11 +107,13 @@ class LibtorrentStatusParser(GenericStatusParser):
         logging.debug("string_array is %s" % string_array)
 
         for string in string_array:
-            pair = re.split("\ *:\ *", string)
+            pair = re.split("\ *:\ +", string)
             if pair[0] == "ps":
                 num_peers = self.canon_num_peers(pair[1])
             if pair[0] == "dht":
                 dht = self.canon_dht(pair[1])
+            if pair[0] == "time":
+                datetime = self.canon_datetime(pair[1])
             if pair[0] == "dl":
                 download_speed = self.canon_download_speed(pair[1])
             if pair[0] == "ul":
@@ -112,7 +128,7 @@ class LibtorrentStatusParser(GenericStatusParser):
                 eta_seconds = self.timedelta_to_seconds(self.canon_eta(pair[1]))
 
         self.timestamp += ONE_SECOND
-
+        self.timestamp = datetime
         return (self.timestamp, num_peers, dht, download_speed, upload_speed, download_size, upload_size, eta_seconds)