Provide a configuration to enable/disable scheduling with Woodchuck.
authorNeal H. Walfield <neal@walfield.org>
Sun, 27 Nov 2011 16:45:17 +0000 (17:45 +0100)
committerNeal H. Walfield <neal@walfield.org>
Sun, 27 Nov 2011 17:00:59 +0000 (18:00 +0100)
 - Implement it.

src/config.py
src/rss_sqlite.py
src/wc.py

index a42137d..5b28e2d 100644 (file)
@@ -117,10 +117,34 @@ class Config():
 
         heading('Updating')
         button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
-        button.set_label("Automatically update feeds")
+        button.set_label("Time-Based Automatic Update\n"
+                         + "(requires use of FeedingIt widget)")
         button.set_active(self.config["autoupdate"])
         button.connect("toggled", self.button_toggled, "autoupdate")
         vbox.pack_start(button, expand=False)
+        button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
+        button.set_label("Woodchuck-Based Automatic Update")
+        button.set_active(self.config["woodchuck"])
+        button.connect("toggled", self.button_toggled, "woodchuck")
+        vbox.pack_start(button, expand=False)
+
+        try:
+            import woodchuck
+            woodchuck_installed = True
+        except ImportError:
+            woodchuck_installed = False
+
+        if not woodchuck_installed:
+            def install_woodchuck_clicked(button):
+                from FeedingIt import open_in_browser
+                open_in_browser("http://maemo.org/downloads/product/raw/Maemo5/murmeltier?get_installfile")
+
+            button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+            button.set_label("Install Woodchuck")
+            button.connect("clicked", install_woodchuck_clicked)
+            button.set_alignment(0,0,1,1)
+            vbox.pack_start(button, expand=False)
+
         add_setting('updateInterval')
         add_setting('expiry')
 
@@ -176,6 +200,14 @@ class Config():
         else:
             self.config[configName] = False
         #print "autoup",  self.autoupdate
+
+        if configName == 'woodchuck':
+            try:
+                from wc import wc_disable_set
+                wc_disable_set(not self.config['woodchuck'])
+            except Exception:
+                logger.exception("Disabling Woodchuck")
+
         self.saveConfig()
         
     def selection_changed(self, selector, button, setting):
@@ -204,6 +236,7 @@ class Config():
                   (configParser.getint, "artFontSize", 14),
                   (configParser.getint, "expiry", 24),
                   (configParser.getboolean, "autoupdate", False),
+                  (configParser.getboolean, "woodchuck", True),
                   (configParser.getint, "updateInterval", 4),
                   (configParser.get, "orientation", "Automatic"),
                   (configParser.getboolean, "imageCache", False),
@@ -229,6 +262,7 @@ class Config():
         configParser.set(section, 'expiry', str(self.config["expiry"]))
         configParser.set(section, 'autoupdate', str(self.config["autoupdate"]))
         configParser.set(section, 'updateInterval', str(self.config["updateInterval"]))
+        configParser.set(section, 'woodchuck', str(self.config["woodchuck"]))
         configParser.set(section, 'orientation', str(self.config["orientation"]))
         configParser.set(section, 'imageCache', str(self.config["imageCache"]))
         configParser.set(section, 'proxy', str(self.config["proxy"]))
@@ -267,6 +301,8 @@ class Config():
         return self.config["expiry"]
     def isAutoUpdateEnabled(self):
         return self.config["autoupdate"]
+    def getWoodchuckEnabled(self):
+        return self.config["woodchuck"]
     def getUpdateInterval(self):
         return float(self.config["updateInterval"])
     def getReadFont(self):
index f1032d7..503c9d3 100644 (file)
@@ -988,7 +988,7 @@ class Listing(BaseObject):
         # state.
         try:
             updater = os.path.basename(sys.argv[0]) == 'update_feeds.py'
-            wc_init (self, True if updater else False)
+            wc_init(config, self, True if updater else False)
             if wc().available() and updater:
                 # The list of known streams.
                 streams = wc().streams_list ()
index c28d1d7..d9a2efd 100644 (file)
--- a/src/wc.py
+++ b/src/wc.py
@@ -32,7 +32,7 @@ except ImportError, exception:
         % traceback.format_exc ())
     woodchuck_imported = False
     class PyWoodchuck (object):
-        def available(self):
+        def available(self, *args, **kwargs):
             return False
     woodchuck = None
 
@@ -40,7 +40,7 @@ except ImportError, exception:
 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,
@@ -52,9 +52,22 @@ class mywoodchuck (PyWoodchuck):
             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.
@@ -85,12 +98,12 @@ class mywoodchuck (PyWoodchuck):
                            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 ():
@@ -98,6 +111,27 @@ def wc_init(listing, request_feedback=False):
     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