[kupfer] core: Fully load sources at launch



commit b3aa2de12a0e206c3c6295c1e5a272aaebed9022
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Jan 19 15:58:05 2010 +0100

    core: Fully load sources at launch
    
    Make sure sources are fully loaded when we start (clean, without
    cache) with new sources. We need to call list() on the source's
    iterator to load it out.
    
    At the same time, we simplify how we call the PeriodcRescanner to
    rescan the source (and register that it was rescanned).

 kupfer/core/sources.py |   32 +++++++++++++-------------------
 1 files changed, 13 insertions(+), 19 deletions(-)
---
diff --git a/kupfer/core/sources.py b/kupfer/core/sources.py
index a608f35..75cdb00 100644
--- a/kupfer/core/sources.py
+++ b/kupfer/core/sources.py
@@ -58,26 +58,24 @@ class PeriodicRescanner (gobject.GObject, pretty.OutputMixin):
 		self.output_info("Campaign finished, pausing %d s" % self.campaign)
 		self.timer.set(self.campaign, self._new_campaign)
 
-	def register_rescan(self, source, sync=False):
-		"""Register an object for rescan
-		If @sync, it will be rescanned synchronously
-		"""
-		self._start_source_rescan(source, sync)
+	def rescan_now(self, source, force_update=False):
+		"Rescan @source immediately"
+		self.latest_rescan_time[source] = time.time()
+		self.rescan_source(source, force_update=force_update)
 
-	def _start_source_rescan(self, source, sync=False):
+	def _start_source_rescan(self, source):
 		self.latest_rescan_time[source] = time.time()
-		if sync:
-			self.rescan_source(source)
-		elif not source.is_dynamic():
+		if not source.is_dynamic():
 			thread = threading.Thread(target=self.rescan_source, args=(source,))
 			thread.setDaemon(True)
 			thread.start()
 
-	def rescan_source(self, source):
-		items = source.get_leaves(force_update=True)
+	def rescan_source(self, source, force_update=True):
+		list(source.get_leaves(force_update=force_update))
 		gobject.idle_add(self.emit, "reloaded-source", source)
 
-gobject.signal_new("reloaded-source", PeriodicRescanner, gobject.SIGNAL_RUN_LAST,
+gobject.signal_new("reloaded-source", PeriodicRescanner,
+		gobject.SIGNAL_RUN_LAST,
 		gobject.TYPE_BOOLEAN, (gobject.TYPE_PYOBJECT,))
 
 class SourcePickler (pretty.OutputMixin):
@@ -451,17 +449,13 @@ class SourceController (pretty.OutputMixin):
 		for src in set(self.sources):
 			with self._exception_guard(src):
 				src.initialize()
+		# Make sure that the toplevel sources are chached
+		# either newly rescanned or the cache is fully loaded
 		for src in set(self.toplevel_sources):
 			with self._exception_guard(src):
-				self._rescan_source(src, force=False)
+				self.rescanner.rescan_now(src, force_update=False)
 		self.loaded_successfully = True
 
-	def _rescan_source(self, source, force=True):
-		if force:
-			self.rescanner.register_rescan(source, sync=True)
-		else:
-			source.get_leaves()
-
 
 _source_controller = None
 def GetSourceController():



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