% traceback.format_exc ())
woodchuck_imported = False
class PyWoodchuck (object):
- def available(self):
+ def available(self, *args, **kwargs):
return False
woodchuck = None
refresh_interval = 6 * 60 * 60
class mywoodchuck (PyWoodchuck):
- def __init__(self, listing, human_readable_name, identifier,
+ def __init__(self, config, listing, human_readable_name, identifier,
request_feedback):
try:
PyWoodchuck.__init__ (self, human_readable_name, identifier,
self.available = self.not_available
return
+ self.config = config
self.listing = listing
- def not_available(self):
+ try:
+ self.enabled = config.getWoodchuckEnabled()
+ except Exception:
+ logging.exception("Setting enabled")
+
+ def available(self, check_config=True):
+ if not PyWoodchuck.available(self):
+ return False
+ if check_config:
+ return self.config.getWoodchuckEnabled()
+ return True
+
+ def not_available(self, *args, **kwargs):
return False
# Woodchuck upcalls.
str(e)))
_w = None
-def wc_init(listing, request_feedback=False):
+def wc_init(config, listing, request_feedback=False):
"""Connect to the woodchuck server and initialize any state."""
global _w
assert _w is None
- _w = mywoodchuck (listing, "FeedingIt", "org.marcoz.feedingit",
+ _w = mywoodchuck (config, listing, "FeedingIt", "org.marcoz.feedingit",
request_feedback)
if not woodchuck_imported or not _w.available ():
else:
logger.debug("Woodchuck appears to be available.")
+def wc_disable_set(disable=True):
+ """Disable Woodchuck."""
+ if disable:
+ logger.info("Disabling Woodchuck")
+ else:
+ logger.info("Enabling Woodchuck")
+
+ global _w
+ if _w is None:
+ logging.info("Woodchuck not loaded. Not doing anything.")
+ return
+
+ if not _w.available(check_config=False):
+ logging.info("Woodchuck not available. Not doing anything.")
+ return
+
+ try:
+ _w.enabled = not disable
+ except Exception:
+ logger.exception("Disabling Woodchuck")
+
def wc():
"""Return the Woodchuck singleton."""
global _w