Merge lp:~sil2100/unity/keybindings-migrations into lp:unity

Proposed by Łukasz Zemczak on 2012-09-06
Status: Rejected
Rejected by: Łukasz Zemczak on 2012-09-07
Proposed branch: lp:~sil2100/unity/keybindings-migrations
Merge into: lp:unity
Diff against target: 278 lines (+253/-0)
5 files modified
tests/migration-scripts/test_keybinding_migration.py (+123/-0)
tools/convert-files/global-unity-keybindings.convert (+59/-0)
tools/convert-files/keybindings-active-unity.convert (+2/-0)
tools/convert-files/keybindings-unity.convert (+2/-0)
tools/migration-scripts/03_migrate_keybindings_to_gsettings.py (+67/-0)
To merge this branch: bzr merge lp:~sil2100/unity/keybindings-migrations
Reviewer Review Type Date Requested Status
Timo Jyrinki 2012-09-06 Needs Fixing on 2012-09-07
Review via email: mp+123117@code.launchpad.net

Commit Message

Initial version of keybinding convert files for unity

Description of the Change

- Problem:
Currently, the migration script and .convert files for migrating GSettings files do not migrate keybindings for the unity profile.

- Fix:
Adding those keybinding changing .convert files to unity. Also, preparing another session-migration script that would run the gsettings-data-convert with the new files.

- Tests:
Attached a pymock script for testing the script functionality, based on the migrations tests script by Francis.

To post a comment you must log in.
Didier Roche (didrocks) wrote :

Hum, I guess the compiz key migrations should be in compiz itself for people having compiz without unity installed and still having a good migration experience.

The hud one is needed in unity, indeed.

Timo Jyrinki (timo-jyrinki) wrote :

Didier: They are in compiz already, that's where these were copied from.

Łukasz: the exec needs to be changed to run-command-terminal (a fix now merged in lp:compiz as well)

review: Needs Fixing
Didier Roche (didrocks) wrote :

@Timo: where in unity?
I can see tools/convert-files/compiz-profile-active-unity.convert and tools/convert-files/compiz-profile-unity.convert which indeed convert all compiz keys *for the unity profile* and only for that one, which makes sense as the profile is shipped in unity.

Those convert keys though are not dependent of any profile (apart from the HUD key which is already converted into the unity profile), so tools/convert-files/keybindings-active-unity.convert and tools/convert-files/keybindings-unity.convert are useless as already in the previous mentionned files.

However, the rest of the keys are not linked to any profiles (default or unity) at all, and so, need to be in compiz, as told.

Timo Jyrinki (timo-jyrinki) wrote :

Ok, I thought you meant the key migrations needing to be in Compiz sources, since you mentioned "without unity installed". They've been in compiz under postinst/convert-files/ and are in the released packages since gsettings migration.

Didier Roche (didrocks) wrote :

But, that's exactly what I meant, on this merge proposal:
- remove the HUD transition, uneeded apparently
- put all the other migrations in compiz, as it's generic and doesn't depend on any profile, so we want this to happen even for people not having unity installed and it's the right place to put them anyway.

Didier Roche (didrocks) wrote :

Also @Lukasz: as the metacity keys won't exist anymore on a new profile, please check on the guest sessions that the keys are still populated with the default and not unsetted after this migration.

Łukasz Zemczak (sil2100) wrote :

Ok, I can move the global-keybinding bits to compiz. I would have to remove those from the profile .convert files in compiz though. I did it like this because I wanted to write one new migration script instead of two. Why is it so? Since the situation now looks like this:
- Compiz already has the keybinding conversions in its compiz Default profile .convert files (both active and non-active profile). So, essentially, when someone uses the Default profile, he already has the keybindings migrated. The migration only doesn't happen for Unity profile users, as Timo added those conversions to the default profiles only.
- The way it is now is that, since we already have the Default profiles covered by the default migration script, I only had to write one migration script for the unity case. If we decide to add the global keybindings in compiz executed for all profiles, we would have to have 2 additional migration scripts: one for migrating global keybindings (located in compiz) and one for migrating the hud key (located in unity).

Regarding the HUD key conversion - is it not required like this? Since, well, it needs to be converted from the unity active/non-active profile to the org.compiz.integrated schema - not sure if we have it covered anywhere else?

Didier Roche (didrocks) wrote :

for the compiz part, I checked with Mirv and the part in compiz was wrongly merged into existing file in a previous merge proposal per profile, even if those keys are not per profile (and this merge proposal is redundant with them). The goal is to avoid to write 4 times exactly the same convertion key list as we have with this merge proposal (2 in compiz and 2 in unity), in addition, 2 of them will be useless as you move exactly the same keys.

So one place instead of 4 seems a big win to me ;)

the HUD key is already covered by one of your script in unity, look at them :)

Unmerged revisions

2658. By Łukasz Zemczak on 2012-09-06

Initial version of keybinding convert files for unity

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'tests/migration-scripts'
2=== added file 'tests/migration-scripts/test_keybinding_migration.py'
3--- tests/migration-scripts/test_keybinding_migration.py 1970-01-01 00:00:00 +0000
4+++ tests/migration-scripts/test_keybinding_migration.py 2012-09-06 16:12:21 +0000
5@@ -0,0 +1,123 @@
6+#!/usr/bin/python
7+# -*- coding: utf-8 -*-
8+# Copyright (C) 2012 Canonical
9+#
10+# Authors:
11+# Francis 'fginther' Ginther <francis.ginther@canonical.com>
12+# Łukasz 'sil2100' Zemczak <lukasz.zemczak@canonical.com>
13+#
14+# This program is free software; you can redistribute it and/or modify it under
15+# the terms of the GNU General Public License as published by the Free Software
16+# Foundation; version 3.
17+#
18+# This program is distributed in the hope that it will be useful, but WITHOUTa
19+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21+# details.
22+#
23+# You should have received a copy of the GNU General Public License along with
24+# this program; if not, write to the Free Software Foundation, Inc.,
25+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26+
27+
28+import sys
29+import unittest
30+from mock import MagicMock, patch
31+from StringIO import StringIO
32+
33+import gconf
34+import glib
35+import os.path
36+import subprocess
37+
38+# Module Under Test (mut)
39+try:
40+ mut = __import__("03_migrate_keybindings_to_gsettings")
41+except (ImportError):
42+ sys.exit("Error! 03_migrate_keybindings_to_gsettings module-under-test not found - perhaps you missed including it in the PYTHONPATH environment variable? Add the migration module directory and re-run the script again.")
43+
44+class MigrateGconfToGsettingsTests(unittest.TestCase):
45+ """Test suite for method migrate_keybindings_to_gsettings"""
46+
47+ def setUp(self):
48+ """Redirects stdout so that tests can assert print statements"""
49+ self.stdout = sys.stdout
50+ self.out = StringIO()
51+ sys.stdout = self.out
52+
53+ def tearDown(self):
54+ """Restores stdout"""
55+ sys.stdout = self.stdout
56+ # Dump the content that was sent to stdout
57+ # print(self.out.getvalue())
58+
59+ def testClientGetDefaultFalse(self):
60+ """Test missing gconf client"""
61+ gconf.client_get_default = MagicMock(return_value=False)
62+ mut.migrate_keybindings_to_gsettings()
63+ self.assertEqual(self.out.getvalue().strip(), "WARNING: no gconf client found.")
64+
65+ def testGetSchemaException(self):
66+ """Test exception handling for get_schema"""
67+ gconf_mock = MagicMock(name="gconf-Mock")
68+ gconf.client_get_default = MagicMock(return_value=gconf_mock)
69+ gconf_schema_mock = MagicMock(name="gconf.Schema-Mock")
70+ gconf_mock.get_schema = MagicMock(return_value=gconf_schema_mock,
71+ side_effect=glib.GError)
72+ self.assertRaises(glib.GError, mut.migrate_keybindings_to_gsettings())
73+
74+ def testGetSchemaNone(self):
75+ """Test missing schema"""
76+ gconf_mock = MagicMock(name="gconf-Mock")
77+ gconf.client_get_default = MagicMock(return_value=gconf_mock)
78+ #gconf_schema_mock = MagicMock(name="gconf.Schema-Mock")
79+ gconf_mock.get_schema = MagicMock(return_value=False)
80+ mut.migrate_keybindings_to_gsettings()
81+ self.assertEqual(self.out.getvalue().strip(), "No current profile set, no migration needed")
82+
83+ def setupGetSchema(self, profile):
84+ """Set up mock objects for testing a valid schema"""
85+ # gconf.client_get_default
86+ gconf_mock = MagicMock(name="gconf-Mock")
87+ gconf.client_get_default = MagicMock(return_value=gconf_mock)
88+ # client.get_schema
89+ gconf_schema_mock = MagicMock(name="gconf.Schema-Mock")
90+ gconf_mock.get_schema = MagicMock(return_value=gconf_schema_mock)
91+ # current_profile_schema.get_default_value
92+ gconf_gconfvalue_mock = MagicMock(name="gconf.Schema.gconfvalue-Mock")
93+ gconf_schema_mock.get_default_value = MagicMock(return_value=gconf_gconfvalue_mock)
94+ # current_profile_gconfvalue.get_string
95+ gconf_gconfvalue_mock.get_string = MagicMock(return_value=profile)
96+
97+ # Popen
98+ subprocess_mock = MagicMock(name="subprocess-Mock")
99+ popen_mock = MagicMock(name="popen-Mock", return_value=subprocess_mock)
100+ subprocess.Popen = popen_mock
101+ return popen_mock
102+
103+ def testGetSchemaUnity(self):
104+ """Test the 'unity' schema"""
105+ popen_mock = self.setupGetSchema("unity")
106+ mut.migrate_keybindings_to_gsettings()
107+ # 2 files should be converted: global and unity
108+ self.assertEqual(len(popen_mock.call_args_list), 2)
109+ self.assertEqual(popen_mock.call_args_list[0][0][0][1],
110+ '--file=/usr/lib/compiz/migration/global-unity-keybindings.convert')
111+ self.assertEqual(popen_mock.call_args_list[1][0][0][1],
112+ '--file=/usr/lib/compiz/migration/keybindings-active-unity.convert')
113+
114+ def testGetSchemaDefault(self):
115+ """Test the default schema"""
116+ popen_mock = self.setupGetSchema("Default")
117+ os.path.exists = MagicMock(return_value=False)
118+ mut.migrate_keybindings_to_gsettings()
119+ # 2 files should be converted: global and default
120+ self.assertEqual(len(popen_mock.call_args_list), 2)
121+ self.assertEqual(popen_mock.call_args_list[0][0][0][1],
122+ '--file=/usr/lib/compiz/migration/global-unity-keybindings.convert')
123+ self.assertEqual(popen_mock.call_args_list[1][0][0][1],
124+ '--file=/usr/lib/compiz/migration/keybindings-unity.convert')
125+
126+if __name__ == '__main__':
127+ unittest.main()
128+
129
130=== added file 'tools/convert-files/global-unity-keybindings.convert'
131--- tools/convert-files/global-unity-keybindings.convert 1970-01-01 00:00:00 +0000
132+++ tools/convert-files/global-unity-keybindings.convert 2012-09-06 16:12:21 +0000
133@@ -0,0 +1,59 @@
134+[org.compiz.integrated]
135+exec = /apps/metacity/global_keybindings/run_command_terminal
136+run-command-screenshot = /apps/metacity/global_keybindings/run_command_screenshot
137+run-command-window-screenshot = /apps/metacity/global_keybindings/run_command_window_screenshot
138+panel-run-dialog = /apps/metacity/global_keybindings/panel_run_dialog
139+panel-main-menu = /apps/metacity/global_keybindings/panel_main_menu
140+
141+
142+[org.gnome.desktop.wm.keybindings]
143+move-to-workspace-1 = /apps/metacity/window_keybindings/move_to_workspace_1
144+move-to-workspace-2 = /apps/metacity/window_keybindings/move_to_workspace_2
145+move-to-workspace-3 = /apps/metacity/window_keybindings/move_to_workspace_3
146+move-to-workspace-4 = /apps/metacity/window_keybindings/move_to_workspace_4
147+move-to-workspace-5 = /apps/metacity/window_keybindings/move_to_workspace_5
148+move-to-workspace-6 = /apps/metacity/window_keybindings/move_to_workspace_6
149+move-to-workspace-7 = /apps/metacity/window_keybindings/move_to_workspace_7
150+move-to-workspace-8 = /apps/metacity/window_keybindings/move_to_workspace_8
151+move-to-workspace-9 = /apps/metacity/window_keybindings/move_to_workspace_9
152+move-to-workspace-10 = /apps/metacity/window_keybindings/move_to_workspace_10
153+move-to-workspace-11 = /apps/metacity/window_keybindings/move_to_workspace_11
154+move-to-workspace-12 = /apps/metacity/window_keybindings/move_to_workspace_12
155+move-to-workspace-left = /apps/metacity/window_keybindings/move_to_workspace_left
156+move-to-workspace-right = /apps/metacity/window_keybindings/move_to_workspace_right
157+move-to-workspace-up = /apps/metacity/window_keybindings/move_to_workspace_up
158+move-to-workspace-down = /apps/metacity/window_keybindings/move_to_workspace_down
159+switch-windows = /apps/metacity/global_keybindings/switch_windows
160+switch-group = /apps/metacity/global_keybindings/switch_group
161+show-desktop = /apps/metacity/global_keybindings/show_desktop
162+switch-to-workspace-1 = /apps/metacity/global_keybindings/switch_to_workspace_1
163+switch-to-workspace-2 = /apps/metacity/global_keybindings/switch_to_workspace_2
164+switch-to-workspace-3 = /apps/metacity/global_keybindings/switch_to_workspace_3
165+switch-to-workspace-4 = /apps/metacity/global_keybindings/switch_to_workspace_4
166+switch-to-workspace-5 = /apps/metacity/global_keybindings/switch_to_workspace_5
167+switch-to-workspace-6 = /apps/metacity/global_keybindings/switch_to_workspace_6
168+switch-to-workspace-7 = /apps/metacity/global_keybindings/switch_to_workspace_7
169+switch-to-workspace-8 = /apps/metacity/global_keybindings/switch_to_workspace_8
170+switch-to-workspace-9 = /apps/metacity/global_keybindings/switch_to_workspace_9
171+switch-to-workspace-10 = /apps/metacity/global_keybindings/switch_to_workspace_10
172+switch-to-workspace-11 = /apps/metacity/global_keybindings/switch_to_workspace_11
173+switch-to-workspace-12 = /apps/metacity/global_keybindings/switch_to_workspace_12
174+switch-to-workspace-left = /apps/metacity/global_keybindings/switch_to_workspace_left
175+switch-to-workspace-right = /apps/metacity/global_keybindings/switch_to_workspace_right
176+switch-to-workspace-up = /apps/metacity/global_keybindings/switch_to_workspace_up
177+switch-to-workspace-down = /apps/metacity/global_keybindings/switch_to_workspace_down
178+activate-window-menu = /apps/metacity/window_keybindings/activate_window_menu
179+toggle-fullscreen = /apps/metacity/window_keybindings/toggle_fullscreen
180+toggle-maximized = /apps/metacity/window_keybindings/toggle_maximized
181+maximize = /apps/metacity/window_keybindings/maximize
182+unmaximize = /apps/metacity/window_keybindings/unmaximize
183+toggle-shaded = /apps/metacity/window_keybindings/toggle_shaded
184+close = /apps/metacity/window_keybindings/close
185+minimize = /apps/metacity/window_keybindings/minimize
186+begin-move = /apps/metacity/window_keybindings/begin_move
187+begin-resize = /apps/metacity/window_keybindings/begin_resize
188+raise = /apps/metacity/window_keybindings/raise
189+lower = /apps/metacity/window_keybindings/lower
190+maximize-vertically = /apps/metacity/window_keybindings/maximize_vertically
191+maximize-horizontally = /apps/metacity/window_keybindings/maximize_horizontally
192+
193
194=== added file 'tools/convert-files/keybindings-active-unity.convert'
195--- tools/convert-files/keybindings-active-unity.convert 1970-01-01 00:00:00 +0000
196+++ tools/convert-files/keybindings-active-unity.convert 2012-09-06 16:12:21 +0000
197@@ -0,0 +1,2 @@
198+[org.compiz.integrated]
199+show-hud = /apps/compiz-1/plugins/unityshell/screen0/options/show_hud
200
201=== added file 'tools/convert-files/keybindings-unity.convert'
202--- tools/convert-files/keybindings-unity.convert 1970-01-01 00:00:00 +0000
203+++ tools/convert-files/keybindings-unity.convert 2012-09-06 16:12:21 +0000
204@@ -0,0 +1,2 @@
205+[org.compiz.integrated]
206+show-hud = /apps/compizconfig-1/profiles/unity/plugins/unityshell/screen0/options/show_hud
207
208=== added file 'tools/migration-scripts/03_migrate_keybindings_to_gsettings.py'
209--- tools/migration-scripts/03_migrate_keybindings_to_gsettings.py 1970-01-01 00:00:00 +0000
210+++ tools/migration-scripts/03_migrate_keybindings_to_gsettings.py 2012-09-06 16:12:21 +0000
211@@ -0,0 +1,67 @@
212+#!/usr/bin/python
213+# -*- coding: utf-8 -*-
214+# Copyright (C) 2012 Canonical
215+#
216+# Authors:
217+# Łukasz 'sil2100' Zemczak <lukasz.zemczak@canonical.com>
218+#
219+# This program is free software; you can redistribute it and/or modify it under
220+# the terms of the GNU General Public License as published by the Free Software
221+# Foundation; version 3.
222+#
223+# This program is distributed in the hope that it will be useful, but WITHOUTa
224+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
225+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
226+# details.
227+#
228+# You should have received a copy of the GNU General Public License along with
229+# this program; if not, write to the Free Software Foundation, Inc.,
230+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
231+
232+import gconf
233+import glib
234+import subprocess
235+import os.path
236+
237+# this should point to the directory where all the .convert files are stored
238+CONVERT_PATH = "/usr/lib/compiz/migration/"
239+
240+def migrate_file(convert_file):
241+ subprocess.Popen(["gsettings-data-convert", "--file={}{}".format(CONVERT_PATH, convert_file)]).communicate()
242+
243+def migrate_keybindings_to_gsettings():
244+ # first, we actually convert the global keybindings, since no knowledge
245+ # of the active profile is needed here
246+ migrate_file("global-unity-keybindings.convert")
247+
248+ # now get the default profile and migrate profile specific keybindings
249+
250+ client = gconf.client_get_default()
251+
252+ if not client:
253+ print "WARNING: no gconf client found."
254+ return
255+
256+ try:
257+ current_profile_schema = client.get_schema("/apps/compizconfig-1/current_profile")
258+ except (glib.GError, AttributeError):
259+ print "No current profile set, no migration needed"
260+ return
261+
262+ if current_profile_schema:
263+ current_profile_gconfvalue = current_profile_schema.get_default_value()
264+ current_profile_str = current_profile_gconfvalue.get_string()
265+ else:
266+ print "No current profile set, no migration needed"
267+ return
268+
269+ # depending what current profile is set, migrate using specific .convert files
270+ if current_profile_str == 'unity':
271+ print "Will migrate keybindings for unity as the active profile"
272+ migrate_file('keybindings-active-unity.convert')
273+ else:
274+ print "Will migrate keybindings for unity as the active profile"
275+ migrate_file('keybindings-unity.convert')
276+
277+if __name__ == '__main__':
278+ migrate_keybindings_to_gsettings ()