[kupfer] core: Call Source.finalize() before disposing of a source
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] core: Call Source.finalize() before disposing of a source
- Date: Sun, 9 May 2010 15:55:43 +0000 (UTC)
commit d146007f81d804d54c66a82589dda233fd1bcf7f
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Sun May 9 16:25:25 2010 +0100
core: Call Source.finalize() before disposing of a source
kupfer/core/sources.py | 25 ++++++++++++++++++++++---
kupfer/obj/base.py | 6 ++++++
2 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/core/sources.py b/kupfer/core/sources.py
index 021c579..8c71294 100644
--- a/kupfer/core/sources.py
+++ b/kupfer/core/sources.py
@@ -422,7 +422,20 @@ class SourceController (pretty.OutputMixin):
configsaver = SourceDataPickler()
for source in self.sources:
if configsaver.source_has_config(source):
- configsaver.save_source(source)
+ self._save_source(source, pickler=configsaver)
+
+ @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"
+ if SourceDataPickler.source_has_config(source):
+ self._save_source(source)
+ elif not source.is_dynamic():
+ self._pickle_source(source)
def _try_restore(self, sources):
"""
@@ -445,9 +458,15 @@ class SourceController (pretty.OutputMixin):
sourcepickler.rm_old_cachefiles()
for source in sources:
if (source.is_dynamic() or
- SourceDataPickler.source_has_config(source)):
+ SourceDataPickler.source_has_config(source)):
continue
- sourcepickler.pickle_source(source)
+ 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"
diff --git a/kupfer/obj/base.py b/kupfer/obj/base.py
index 87f3f48..5071c91 100644
--- a/kupfer/obj/base.py
+++ b/kupfer/obj/base.py
@@ -333,6 +333,12 @@ class Source (KupferObject, pretty.OutputMixin):
"""
pass
+ def finalize(self):
+ """
+ Called before a source is deactivated.
+ """
+ pass
+
def repr_key(self):
return ""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]