If initializing the Woodchuck connection fails, just disable Woodchuck.
authorNeal H. Walfield <neal@walfield.org>
Tue, 6 Sep 2011 20:54:06 +0000 (22:54 +0200)
committerNeal H. Walfield <neal@walfield.org>
Thu, 8 Sep 2011 16:37:31 +0000 (18:37 +0200)
src/wc.py

index cb73c47..b061138 100644 (file)
--- a/src/wc.py
+++ b/src/wc.py
@@ -42,11 +42,21 @@ refresh_interval = 6 * 60 * 60
 class mywoodchuck (PyWoodchuck):
     def __init__(self, listing, human_readable_name, identifier,
                  request_feedback):
-        PyWoodchuck.__init__ (self, human_readable_name, identifier,
-                              request_feedback)
+        try:
+            PyWoodchuck.__init__ (self, human_readable_name, identifier,
+                                  request_feedback)
+        except woodchuck.Error, e:
+            logger.error(
+                "Failed to establish a connection to the Woodchuck server: %s"
+                % (str(e),))
+            self.available = self.not_available
+            return
 
         self.listing = listing
 
+    def not_available(self):
+        return False
+
     # Woodchuck upcalls.
     def stream_update_cb(self, stream):
         logger.debug("stream update called on %s (%s)"
@@ -68,6 +78,7 @@ class mywoodchuck (PyWoodchuck):
 
 _w = None
 def wc_init(listing, request_feedback=False):
+    """Connect to the woodchuck server and initialize any state."""
     global _w
     assert _w is None
     
@@ -80,7 +91,7 @@ def wc_init(listing, request_feedback=False):
         logger.debug("Woodchuck appears to be available.")
 
 def wc():
-    """Connect to the woodchuck server and initialize any state."""
+    """Return the Woodchuck singleton."""
     global _w
     assert _w is not None
     return _w