[tor-commits] [bridgedb/master] 5482 - Fix timestamp parsing

aagbsn at torproject.org aagbsn at torproject.org
Wed Apr 17 00:26:44 UTC 2013


commit c80488c43e0792b1b7fefab89dc5129bcbbdd63f
Author: aagbsn <aagbsn at extc.org>
Date:   Mon Nov 5 13:06:07 2012 -0800

    5482 - Fix timestamp parsing
---
 lib/bridgedb/Bridges.py |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py
index 822385f..9bcc99a 100644
--- a/lib/bridgedb/Bridges.py
+++ b/lib/bridgedb/Bridges.py
@@ -283,7 +283,7 @@ class Bridge:
         return db.getBridgeHistory(self.fingerprint).weightedFractionalUptime
 
     @property
-    def wt(self):
+    def weightedTime(self):
         """Weighted Time"""
         db = bridgedb.Storage.getDB()
         return db.getBridgeHistory(self.fingerprint).weightedTime
@@ -300,6 +300,12 @@ class Bridge:
         db = bridgedb.Storage.getDB()
         return db.getBridgeHistory(self.fingerprint).tosa
 
+    @property
+    def weightedUptime(self):
+        """Weighted Uptime"""
+        db = bridgedb.Storage.getDB()
+        return db.getBridgeHistory(self.fingerprint).weightedUptime
+
 def parseDescFile(f, bridge_purpose='bridge'):
     """Generator. Parses a cached-descriptors file 'f' and yeilds a Bridge object
        for every entry whose purpose matches bridge_purpose.
@@ -545,8 +551,9 @@ def parseStatusFile(f):
         if line.startswith("r "):
             try:
                 ID = binascii.a2b_base64(line.split()[2]+"=")
-                timestamp = time.strptime(line.split()[4],"%Y-%m-%d %H:%M:%S")
-                timestamp = time.mktime(timestamp)
+                timestamp = time.mktime(time.strptime(
+                    " ".join(line.split()[4:6]), "%Y-%m-%d %H:%M:%S")
+                    )
             except binascii.Error:
                 logging.warn("Unparseable base64 ID %r", line.split()[2])
             except ValueError: timestamp = None
@@ -561,18 +568,12 @@ def parseStatusFile(f):
                     or_addresses[address] = portlist
             else:
                 logging.warn("Skipping extra or-address line "\
-                             "from Bridge with ID %r" % id)
+                             "from Bridge with ID %r" % ID)
             num_or_address_lines += 1
 
         elif ID and timestamp and line.startswith("s "):
             flags = line.split()
             yield ID, ("Running" in flags), ("Stable" in flags), or_addresses, timestamp
-            # add or update BridgeHistory entries into the database
-            # XXX: what do we do with all these or_addresses?
-            # The bridge stability metrics are only concerned with a single ip:port
-            # So for now, we will only consider the bridges primary IP:port
-            bridgedb.Stability.addOrUpdateBridgeHistory(bridge, timestamp)
-
             timestamp = ID = None
             num_or_address_lines = 0
             or_addresses = {}





More information about the tor-commits mailing list