[kupfer] core: Small rearrangement, separate finalize and save in sources.py
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] core: Small rearrangement, separate finalize and save in sources.py
- Date: Wed, 2 Mar 2011 20:53:30 +0000 (UTC)
commit 24495c0051590a0a74dbe476fd07dd42acb03691
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Wed Mar 2 20:49:31 2011 +0100
core: Small rearrangement, separate finalize and save in sources.py
kupfer/core/data.py | 3 +-
kupfer/core/sources.py | 49 ++++++++++++++++++++++++++++++-----------------
2 files changed, 33 insertions(+), 19 deletions(-)
---
diff --git a/kupfer/core/data.py b/kupfer/core/data.py
index c4ee1e2..afd526a 100644
--- a/kupfer/core/data.py
+++ b/kupfer/core/data.py
@@ -591,11 +591,12 @@ class DataController (gobject.GObject, pretty.OutputMixin):
self._reload_source_root()
def _finish(self, sched):
+ GetSourceController().finalize()
self.output_info("Saving data...")
learn.finish()
GetSourceController().save_data()
self.output_info("Saving cache...")
- GetSourceController().finish()
+ GetSourceController().save_cache()
def _new_source(self, ctr, src):
if ctr is self.source_pane:
diff --git a/kupfer/core/sources.py b/kupfer/core/sources.py
index 8471e91..91756a9 100644
--- a/kupfer/core/sources.py
+++ b/kupfer/core/sources.py
@@ -15,6 +15,9 @@ from kupfer import conspickle
from kupfer.obj import base, sources
from kupfer.core import pluginload
+class InternalError (Exception):
+ pass
+
class PeriodicRescanner (pretty.OutputMixin):
"""
Periodically rescan a @catalog of sources
@@ -257,6 +260,7 @@ class SourceController (pretty.OutputMixin):
self.action_generators = []
self.plugin_object_map = weakref.WeakKeyDictionary()
self.loaded_successfully = False
+ self.did_finalize_sources = False
self._pre_root = None
def add(self, plugin_id, srcs, toplevel=False, initialize=False):
@@ -486,13 +490,23 @@ class SourceController (pretty.OutputMixin):
use_reprs=False)
obj.add_content(content)
- def finish(self):
+ def finalize(self):
+ "Finalize all sources, equivalent to deactivating all sources"
+ for src in self.sources:
+ src.finalize()
+ self.did_finalize_sources = True
+
+ def save_cache(self):
+ "Save all caches (non-important data)"
+ if not self.did_finalize_sources:
+ raise InternalError("Called save_cache without finalize!")
if self.loaded_successfully:
self._pickle_sources(self.sources)
else:
self.output_debug("Not writing cache on failed load")
def save_data(self):
+ "Save (important) user data/configuration"
if not self.loaded_successfully:
self.output_info("Not writing configuration on failed load")
return
@@ -503,20 +517,34 @@ class SourceController (pretty.OutputMixin):
@classmethod
def _save_source(self, source, pickler=None):
- source.finalize()
configsaver = pickler or SourceDataPickler()
configsaver.save_source(source)
def _finalize_source(self, source):
"Either save config, or save cache for @source"
+ source.finalize()
if SourceDataPickler.source_has_config(source):
self._save_source(source)
elif not source.is_dynamic():
self._pickle_source(source)
+ def _pickle_sources(self, sources):
+ sourcepickler = SourcePickler()
+ sourcepickler.rm_old_cachefiles()
+ for source in sources:
+ if (source.is_dynamic() or
+ SourceDataPickler.source_has_config(source)):
+ continue
+ self._pickle_source(source, pickler=sourcepickler)
+
+ @classmethod
+ def _pickle_source(self, source, pickler=None):
+ sourcepickler = pickler or SourcePickler()
+ sourcepickler.pickle_source(source)
+
def _try_restore(self, sources):
"""
- Try to restor the source that is equivalent to the
+ Try to restore the source that is equivalent to the
"dummy" instance @source, from cache, or from saved configuration.
yield the instances that succeed.
"""
@@ -530,21 +558,6 @@ class SourceController (pretty.OutputMixin):
if source:
yield source
- def _pickle_sources(self, sources):
- sourcepickler = SourcePickler()
- sourcepickler.rm_old_cachefiles()
- for source in sources:
- if (source.is_dynamic() or
- SourceDataPickler.source_has_config(source)):
- continue
- self._pickle_source(source, pickler=sourcepickler)
-
- @classmethod
- def _pickle_source(self, source, pickler=None):
- source.finalize()
- sourcepickler = pickler or SourcePickler()
- sourcepickler.pickle_source(source)
-
def _remove_source(self, source):
"Oust @source from catalog if any exception is raised"
self.sources.discard(source)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]