conduit r1919 - in trunk: . conduit/modules conduit/modules/FeedModule test/python-tests



Author: jstowers
Date: Tue Mar  3 11:50:05 2009
New Revision: 1919
URL: http://svn.gnome.org/viewvc/conduit?rev=1919&view=rev

Log:
2009-03-04  John Stowers  <john stowers gmail com>

	* conduit/modules/DesktopWallpaperModule.py: Always overwrite the
	existing wallpaper so it gets updated.

	* conduit/modules/FeedModule/FeedModule.py:
	* test/python-tests/TestDataProviderFeed.py: Update FeedModule to
	consider limit and random orthogonal. One can get a random range within
	a limited (or not) set. Non random limited sets now retain
	their order.



Modified:
   trunk/ChangeLog
   trunk/conduit/modules/DesktopWallpaperModule.py
   trunk/conduit/modules/FeedModule/FeedModule.py
   trunk/test/python-tests/TestDataProviderFeed.py

Modified: trunk/conduit/modules/DesktopWallpaperModule.py
==============================================================================
--- trunk/conduit/modules/DesktopWallpaperModule.py	(original)
+++ trunk/conduit/modules/DesktopWallpaperModule.py	Tue Mar  3 11:50:05 2009
@@ -1,7 +1,7 @@
+import gconf
 import logging
 log = logging.getLogger( "modules.DesktopWallpaper")
 
-import gconf
 import conduit
 import conduit.utils as Utils
 import conduit.dataproviders.File as FileDataProvider
@@ -13,7 +13,7 @@
 
 class DesktopWallpaperDataProvider(FileDataProvider.FolderTwoWay):
 
-    _name_ = "Desktop Wallpaper"
+    _name_ = "Wallpaper"
     _description_ = "Changes your Desktop Wallpaper"
     _category_ = conduit.dataproviders.CATEGORY_MISC
     _module_type_ = "sink"
@@ -25,7 +25,7 @@
     def __init__(self, *args):
         #Put photos into the users Pictures dir
         pdir = Utils.exec_command_and_return_result("xdg-user-dir", "PICTURES")
-        if 1:
+        if pdir:
             folder = "file://"+pdir.strip()
         else:
             folder = "file://"+Utils.new_tempdir()
@@ -47,7 +47,7 @@
         return Utils.get_user_string()
 
     def put(self, vfsFile, overwrite, LUID=None):
-        rid = FileDataProvider.FolderTwoWay.put(self, vfsFile, overwrite, LUID)
+        rid = FileDataProvider.FolderTwoWay.put(self, vfsFile, True, LUID)
 
         #if the file was successfully transferred then set it
         #as the wallpaper

Modified: trunk/conduit/modules/FeedModule/FeedModule.py
==============================================================================
--- trunk/conduit/modules/FeedModule/FeedModule.py	(original)
+++ trunk/conduit/modules/FeedModule/FeedModule.py	Tue Mar  3 11:50:05 2009
@@ -68,13 +68,15 @@
         DataProvider.DataSource.__init__(self)
         self.update_configuration(
             feedUrl = "",
-            limit = 0,
+            limitNum = 1,
+            limit = False,
             randomize = False,
             downloadPhotos = True,
             downloadAudio = True,
             downloadVideo = True,
         )
-        self.files = {}
+        self._files = {}
+        self._count = 0
         
     def _is_allowed_type(self, mimetype):
         ok = False
@@ -89,11 +91,21 @@
     def _add_file(self, url, title, t):
         log.debug("Got enclosure %s %s (%s)" % (title,url,t))
         if self._is_allowed_type(t):
-            if len(self.files) < self.limit or self.limit == 0 or self.randomize:
-                self.files[url] = (title,t)
+            if url not in self._files:
+                self._files[url] = (title,t,self._count)
+                self._count += 1
         else:
             log.debug("Enclosure %s is an illegal type (%s)" % (title,t))
 
+    def _get_all_files(self):
+        """
+        Returns all files in the correct order
+        """
+        files = self._files.keys()
+        for url, (title,t,count) in self._files.iteritems():
+            files[count] = url
+        return files
+
     def initialize(self):
         return True
 
@@ -105,14 +117,14 @@
         )
         config.add_section("Enclosure settings")
         limit_config = config.add_item("Limit downloaded enclosures", "check",
-            initial_value = (self.limit > 0)
+            config_name = 'limit'
         )
         limit_config.connect("value-changed", 
             lambda item, changed, value: limit_spin_config.set_enabled(value)
         )
         limit_spin_config = config.add_item("Limit to", "spin",
-            config_name = 'limit',
-            enabled = (self.limit > 0),
+            config_name = 'limitNum',
+            enabled = self.limit,
         )
         random_config = config.add_item("Randomize enclosures", "check",
             config_name = 'randomize'
@@ -125,8 +137,10 @@
     
     def refresh(self):
         DataProvider.DataSource.refresh(self)
-        #url : (title, mimetype)
-        self.files = {}
+        #url : (title, mimetype, idx)
+        self._files = {}
+        self._count = 0
+        
         d = feedparser.parse(self.feedUrl)
         for entry in d.entries:
             #check for enclosures first (i.e. podcasts)
@@ -138,23 +152,30 @@
 
     def get_all(self):
         DataProvider.DataSource.get_all(self)
-        all_files = self.files.keys()
+
+        all_files = self._get_all_files()
+        num_files = len(all_files)
+
+        if self.limit:
+            log.debug("Getting %s/%s files (random: %s)" % (self.limitNum, num_files, self.randomize))
+        else:
+            log.debug("Getting %s files (random: %s)" % (self.limitNum, self.randomize))
 
         if self.randomize:
-            if self.limit == 0:
-                #no need to randomly choose between *all* files,
-                #as order is irellevant, really
-                return all_files
-            else:
-                #randomly choose limit files from all_files
-                lim = self.limit
+            if self.limit and self.limitNum > 0:
+                lim = self.limitNum
                 files = []
                 while lim > 0:
-                    files.append(all_files.pop(random.randint(0,len(all_files)-1)))
+                    files.append(all_files.pop(random.randint(0,num_files-1)))
                     lim -= 1
                 return files
+            else:
+                return all_files
         else:
-            return all_files
+            if self.limit and self.limitNum > 0:
+                return all_files[0:min(self.limitNum, num_files-1)]
+            else:
+                return all_files
             
     def get(self, url):
         DataProvider.DataSource.get(self, url)
@@ -166,7 +187,7 @@
         
         #create the correct filename and retain the original extension
         try:
-            title,t = self.files[url]
+            title,t,idx = self._files[url]
             f.force_new_filename(title)
             f.force_new_file_extension(ext)
         except:
@@ -176,7 +197,8 @@
 
     def finish(self, aborted, error, conflict):
         DataProvider.DataSource.finish(self)
-        self.files = {}
+        self._files = {}
+        self._count = 0
 
     def get_UID(self):
         return self.feedUrl

Modified: trunk/test/python-tests/TestDataProviderFeed.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderFeed.py	(original)
+++ trunk/test/python-tests/TestDataProviderFeed.py	Tue Mar  3 11:50:05 2009
@@ -9,9 +9,9 @@
 
 TESTS = (
     ("Photos",  "http://www.flickr.com/services/feeds/photos_public gne?id=44124362632 N01&format=rss_200_enc"),
-    ("Audio (ogg)",   "http://www.lugradio.org/episodes.ogg.rss";),
-    ("Audio (mp3)",   "http://feeds.feedburner.com/TheLinuxLinkTechShowMp3Feed";),
-    ("Video",   "http://telemusicvision.com/videos/tmv.rss";)
+#    ("Audio (ogg)",   "http://www.lugradio.org/episodes.ogg.rss";),
+#    ("Audio (mp3)",   "http://feeds.feedburner.com/TheLinuxLinkTechShowMp3Feed";),
+#    ("Video",   "http://telemusicvision.com/videos/tmv.rss";)
 )
 NUM_ENCLOSURES = 5
 
@@ -20,7 +20,9 @@
 
     config = {
         "feedUrl":          url,
-        "limit":            NUM_ENCLOSURES,
+        "limit":            True,
+        "randomize":        False,
+        "limitNum":         NUM_ENCLOSURES,
         "downloadPhotos":   True,
         "downloadAudio":    True,
         "downloadVideo":    True



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]