From 3385f389c30d007fc08174bdab6c7b2deefb818d Mon Sep 17 00:00:00 2001 From: P2P-Next Date: Tue, 17 Aug 2010 15:32:23 +0300 Subject: [PATCH] ppf: LibtorrentStatusParser parses timestamp from status file --- ppf/log-parser/generic/GenericStatusParser.py | 3 ++- .../generic/LibtorrentStatusParser.py | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ppf/log-parser/generic/GenericStatusParser.py b/ppf/log-parser/generic/GenericStatusParser.py index efead77..67b82b0 100644 --- a/ppf/log-parser/generic/GenericStatusParser.py +++ b/ppf/log-parser/generic/GenericStatusParser.py @@ -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: diff --git a/ppf/log-parser/generic/LibtorrentStatusParser.py b/ppf/log-parser/generic/LibtorrentStatusParser.py index 572d2c5..802310d 100644 --- a/ppf/log-parser/generic/LibtorrentStatusParser.py +++ b/ppf/log-parser/generic/LibtorrentStatusParser.py @@ -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) -- 2.20.1