[kupfer] core: Periodically save user data ("config" from sources)
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] core: Periodically save user data ("config" from sources)
- Date: Wed, 2 Mar 2011 20:53:36 +0000 (UTC)
commit 17f840f6bd05011ff016f15e84998bd825a24892
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Wed Mar 2 21:47:17 2011 +0100
core: Periodically save user data ("config" from sources)
In the DataController, periodically save the learning database as well
as the "config" data from all Sources. Default period is 1 hour.
Decreaced learn record pruning probability since it will be pruned
more often now.
kupfer/core/data.py | 25 +++++++++++++++++++++----
kupfer/core/learn.py | 6 +++---
2 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/kupfer/core/data.py b/kupfer/core/data.py
index afd526a..fc15f9d 100644
--- a/kupfer/core/data.py
+++ b/kupfer/core/data.py
@@ -26,6 +26,8 @@ SourcePane, ActionPane, ObjectPane = (1,2,3)
# In two-pane or three-pane mode
SourceActionMode, SourceActionObjectMode = (1,2)
+DATA_SAVE_INTERVAL_S = 3660
+
def identity(x):
return x
@@ -433,6 +435,8 @@ class DataController (gobject.GObject, pretty.OutputMixin):
self._execution_context.connect("late-command-result",
self._late_command_execution_result)
+ self._save_data_timer = scheduler.Timer()
+
sch = scheduler.GetScheduler()
sch.connect("load", self._load)
sch.connect("finish", self._finish)
@@ -482,7 +486,10 @@ class DataController (gobject.GObject, pretty.OutputMixin):
sc.add_action_generator(plugin_id, generator)
def _load(self, sched):
- """Load data from persistent store"""
+ """Begin Data Controller work when we get application 'load' signal
+
+ Load the data model from saved configuration and caches
+ """
setctl = settings.GetSettingsController()
setctl.connect("plugin-enabled-changed", self._plugin_enabled)
setctl.connect("plugin-toplevel-changed", self._plugin_catalog_changed)
@@ -495,6 +502,7 @@ class DataController (gobject.GObject, pretty.OutputMixin):
sc.initialize()
self._reload_source_root()
learn.load()
+ self._save_data_timer.set(DATA_SAVE_INTERVAL_S, self._save_data)
def _get_directory_sources(self):
"""
@@ -591,13 +599,22 @@ class DataController (gobject.GObject, pretty.OutputMixin):
self._reload_source_root()
def _finish(self, sched):
+ "Close down the data model, save user data, and write caches to disk"
GetSourceController().finalize()
- self.output_info("Saving data...")
- learn.finish()
- GetSourceController().save_data()
+ self._save_data(final_invocation=True)
self.output_info("Saving cache...")
GetSourceController().save_cache()
+ def _save_data(self, final_invocation=False):
+ """Save Learning data and User's configuration data in sources
+ (Recurring timer)
+ """
+ self.output_info("Saving data...")
+ learn.save()
+ GetSourceController().save_data()
+ if not final_invocation:
+ self._save_data_timer.set(DATA_SAVE_INTERVAL_S, self._save_data)
+
def _new_source(self, ctr, src):
if ctr is self.source_pane:
pane = SourcePane
diff --git a/kupfer/core/learn.py b/kupfer/core/learn.py
index df2c997..88f6e02 100644
--- a/kupfer/core/learn.py
+++ b/kupfer/core/learn.py
@@ -113,7 +113,7 @@ def _prune_register():
rand = random.random
goalitems = 500
- flux = 10.0
+ flux = 2.0
alpha = flux/goalitems**2
chance = min(0.1, len(_register)*alpha)
@@ -139,9 +139,9 @@ def load():
if not _register:
_register = {}
-def finish():
+def save():
"""
- Close and save the learning record
+ Save the learning record
"""
if not _register:
pretty.print_debug(__name__, "Not writing empty register")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]