From: Razvan Deaconescu Date: Fri, 30 Apr 2010 10:08:10 +0000 (+0300) Subject: add timestamp support to libtorrent status parser X-Git-Tag: getopt_long~33 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=543ef60680e26c4b05a8133bf5eab1f85a02e4f4;p=cs-p2p-next.git add timestamp support to libtorrent status parser --- diff --git a/ppf/log-parser/generic/LibtorrentStatusParser.py b/ppf/log-parser/generic/LibtorrentStatusParser.py index bc84044..572d2c5 100644 --- a/ppf/log-parser/generic/LibtorrentStatusParser.py +++ b/ppf/log-parser/generic/LibtorrentStatusParser.py @@ -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__":