[kupfer] sources: add get_items_forced to force update source
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] sources: add get_items_forced to force update source
- Date: Tue, 6 Apr 2010 18:22:19 +0000 (UTC)
commit 3a6e48345dbf834a9ba6928a1f55f92d722ef1ff
Author: Karol BÄ?dkowski <karol bedkowski gmail com>
Date: Sun Apr 4 22:07:09 2010 +0200
sources: add get_items_forced to force update source
* add new method in Sources: get_items_forced (as suggested by Ulrik). For
default this method call get_items method.
* don't force load on start up, only by PeriodicUpdater or Refresh action
This allow to fast Kupfer start and load items in background without
background loader.
* apply this for gmail and picasa plugins
kupfer/core/sources.py | 3 +--
kupfer/obj/base.py | 19 +++++++++++++++----
kupfer/plugin/gmail/__init__.py | 13 ++++++++++---
kupfer/plugin/google_picasa/__init__.py | 16 ++++++++++------
4 files changed, 36 insertions(+), 15 deletions(-)
---
diff --git a/kupfer/core/sources.py b/kupfer/core/sources.py
index e2c8295..c4d6ff6 100644
--- a/kupfer/core/sources.py
+++ b/kupfer/core/sources.py
@@ -468,8 +468,7 @@ class SourceController (pretty.OutputMixin):
# either newly rescanned or the cache is fully loaded
for src in set(sources):
with pluginload.exception_guard(src, self._remove_source, src):
- force = (src not in self._restored_sources)
- self.rescanner.rescan_now(src, force_update=force)
+ self.rescanner.rescan_now(src, force_update=False)
_source_controller = None
diff --git a/kupfer/obj/base.py b/kupfer/obj/base.py
index 1084b23..988b79f 100644
--- a/kupfer/obj/base.py
+++ b/kupfer/obj/base.py
@@ -341,6 +341,13 @@ class Source (KupferObject, pretty.OutputMixin):
"""
return []
+ def get_items_forced(self):
+ """
+ Force compute and return items for source.
+ Default - call get_items method.
+ """
+ return self.get_items()
+
def is_dynamic(self):
"""
Whether to recompute contents each time it is accessed
@@ -378,14 +385,18 @@ class Source (KupferObject, pretty.OutputMixin):
sort_func = lambda x: x
if self.is_dynamic():
- return sort_func(self.get_items())
-
+ if force_update:
+ return sort_func(self.get_items_forced())
+ else:
+ return sort_func(self.get_items())
+
if self.cached_items is None or force_update:
- cache_type = aslist if force_update else datatools.SavedIterable
- self.cached_items = cache_type(sort_func(self.get_items()))
if force_update:
+ self.cached_items = aslist(sort_func(self.get_items_forced()))
self.output_info("Loaded %d items" % len(self.cached_items))
else:
+ self.cached_items = \
+ datatools.SavedIterable(sort_func(self.get_items()))
self.output_debug("Loaded items")
return self.cached_items
diff --git a/kupfer/plugin/gmail/__init__.py b/kupfer/plugin/gmail/__init__.py
index 2d6dee2..b869d0d 100644
--- a/kupfer/plugin/gmail/__init__.py
+++ b/kupfer/plugin/gmail/__init__.py
@@ -3,7 +3,7 @@ __kupfer_name__ = _("Gmail")
__kupfer_sources__ = ("GoogleContactsSource", )
__kupfer_actions__ = ('NewMailAction', )
__description__ = _("Load contacts and compose new email in Gmail")
-__version__ = "2010-03-04"
+__version__ = "2010-04-04"
__author__ = "Karol BÄ?dkowski <karol bedkowski gmail com>"
import urllib
@@ -139,11 +139,18 @@ class GoogleContact(EmailContact):
class GoogleContactsSource(ToplevelGroupingSource):
def __init__(self, name=_("Gmail")):
super(GoogleContactsSource, self).__init__(name, "Contacts")
- self._version = 3
+ self._version = 4
+ self._contacts = []
def get_items(self):
if is_plugin_configured():
- return get_contacts() or []
+ return self._contacts
+ return [PleaseConfigureLeaf(__name__, __kupfer_name__)]
+
+ def get_items_forced(self):
+ if is_plugin_configured():
+ self._contacts = get_contacts() or []
+ return self._contacts
return [PleaseConfigureLeaf(__name__, __kupfer_name__)]
def should_sort_lexically(self):
diff --git a/kupfer/plugin/google_picasa/__init__.py b/kupfer/plugin/google_picasa/__init__.py
index 4b6b700..493e62f 100644
--- a/kupfer/plugin/google_picasa/__init__.py
+++ b/kupfer/plugin/google_picasa/__init__.py
@@ -3,7 +3,7 @@ __kupfer_name__ = _("Google Picasa")
__kupfer_sources__ = ("PicasaUsersSource", )
__kupfer_actions__ = ('UploadFileToPicasa', 'UploadDirToPicasa')
__description__ = _("Show albums and upload files to Picasa")
-__version__ = "2010-02-04"
+__version__ = "2010-04-04"
__author__ = "Karol BÄ?dkowski <karol bedkowski gmail com>"
import os.path
@@ -127,7 +127,6 @@ class UploadTask(task.ThreadTask):
def thread_finish(self):
pass
-# get_albums.activate()
def picasa_login():
@@ -182,7 +181,7 @@ class PicasaDataCache():
def get_albums(cls, force=False):
''' Load user albums, and albums users defined in 'showusers' setting. '''
pretty.print_debug(__name__, 'get_albums', str(force))
- if cls.data and not force:
+ if not force:
return cls.data
start_time = time.time()
gd_client = picasa_login()
@@ -380,7 +379,7 @@ class PicasaPrivAlbumsSource(Source):
def get_items(self):
if is_plugin_configured():
- for user in PicasaDataCache.get_albums() or []:
+ for user in PicasaDataCache.get_albums():
if user.my_albums:
return user.albums
return []
@@ -402,11 +401,16 @@ class PicasaUsersSource(Source):
def initialize(self):
# fill loader cache by source cache
- PicasaDataCache.data = self.cached_items
+ PicasaDataCache.data = self.cached_items or []
def get_items(self):
if is_plugin_configured():
- return PicasaDataCache.get_albums(True) or []
+ return PicasaDataCache.get_albums()
+ return [PleaseConfigureLeaf(__name__, __kupfer_name__)]
+
+ def get_items_forced(self):
+ if is_plugin_configured():
+ return PicasaDataCache.get_albums(True)
return [PleaseConfigureLeaf(__name__, __kupfer_name__)]
def should_sort_lexically(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]