Skip to content

Configuration migration support

Colomban Wendling requested to merge cwendling/orca:profile-migration into master

This is an implementation for migrating configurations when options changes in some way that would benefit from an upgrade path, including setting renaming, value meaning, etc.

It also improves backward compatibility by always giving user keybindings preference over built-in ones, avoiding overriding a user's setting when adding or changing a build-in binding.

Currently only plain settings migration is supported, but it would be easy to add migration for keybindings or pronunciations, akin to the support for general settings.

This fixes #21 (closed).


Actual settings migration requires code to handle its specifics, but for example adding migration support for !17 (merged) could look like this:

diff --git a/src/orca/settings.py b/src/orca/settings.py
index 2a3fb8561..a8e040401 100644
--- a/src/orca/settings.py
+++ b/src/orca/settings.py
@@ -188,7 +188,7 @@ HYPERLINK_VOICE         = "hyperlink"
 SYSTEM_VOICE            = "system"
 
 # version of the settings, allowing to check compatibility
-settingsVersion = 1
+settingsVersion = 2
 
 voicesKeys = {
 "DEFAULT_VOICE"     : "default",
diff --git a/src/orca/settings_migration.py b/src/orca/settings_migration.py
index 0d4d52e40..3c5fe4116 100644
--- a/src/orca/settings_migration.py
+++ b/src/orca/settings_migration.py
@@ -64,3 +64,10 @@ class SettingsMigration(object):
                     general = migrator(general, name)
 
         return general
+
+    def _migrateOrcaModifierKeys(self, general, name):
+        if self.fromVersion < 2:
+            # before v2, LAPTOP_MODIFIER_KEYS contained only one element
+            if any(i in settings.LAPTOP_MODIFIER_KEYS for i in general[name]):
+                general[name] = settings.LAPTOP_MODIFIER_KEYS
+        return general

Merge request reports