Merge lp:~didrocks/unity/gsettings-migration into lp:unity

Proposed by Didier Roche-Tolomelli
Status: Merged
Merged at revision: 630
Proposed branch: lp:~didrocks/unity/gsettings-migration
Merge into: lp:unity
Diff against target: 269 lines (+133/-62)
5 files modified
CMakeLists.txt (+1/-1)
com.canonical.Unity.gschema.xml (+6/-1)
src/FavoriteStoreGSettings.cpp (+25/-0)
tools/CMakeLists.txt (+5/-0)
tools/migrate_favorites.py (+96/-60)
To merge this branch: bzr merge lp:~didrocks/unity/gsettings-migration
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+41876@code.launchpad.net

Description of the change

gsettings migration, handle lucid -> next LTS, lucid UNE -> next LTS, lucid Unity ppa -> next LTS, maverick -> natty and maverick unity -> natty

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Can'test it works but code looks good and the python is hurting my eyes enough :)

Approved, but could you just make gchar *output = NULL, so if it's not set we don't accidently free a random memory area.

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2010-11-24 21:44:18 +0000
3+++ CMakeLists.txt 2010-11-25 15:59:43 +0000
4@@ -1,7 +1,7 @@
5 project (unity)
6 cmake_minimum_required(VERSION 2.8)
7
8-subdirs (libunity services tests)
9+subdirs (libunity services tests tools)
10
11 #
12 # Base bits
13
14=== modified file 'com.canonical.Unity.gschema.xml'
15--- com.canonical.Unity.gschema.xml 2010-11-22 10:40:59 +0000
16+++ com.canonical.Unity.gschema.xml 2010-11-25 15:59:43 +0000
17@@ -1,9 +1,14 @@
18 <schemalist>
19 <schema path="/desktop/unity/launcher/" id="com.canonical.Unity.Launcher" gettext-domain="unity">
20 <key type="as" name="favorites">
21- <default>[ 'ubiquity-gtkui.desktop', 'nautilus.desktop', 'firefox.desktop', 'empathy.desktop', 'tomboy.desktop' ]</default>
22+ <default>[ 'ubiquity-gtkui.desktop', 'nautilus.desktop', 'firefox.desktop', 'empathy.desktop', 'ubuntuone-control-panel-gtk.desktop', 'tomboy.desktop' ]</default>
23 <summary>List of desktop file ids for favorites on the launcher.</summary>
24 <description>These applications are shown in the Launcher by default.</description>
25 </key>
26+ <key type="s" name="favorite-migration">
27+ <default>''</default>
28+ <summary>Version of last migration done</summary>
29+ <description>This is a detection key for the favorite migration script to know whether the needed migration is done or not.</description>
30+ </key>
31 </schema>
32 </schemalist>
33
34=== modified file 'src/FavoriteStoreGSettings.cpp'
35--- src/FavoriteStoreGSettings.cpp 2010-11-24 22:57:59 +0000
36+++ src/FavoriteStoreGSettings.cpp 2010-11-25 15:59:43 +0000
37@@ -16,12 +16,16 @@
38 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
39 */
40
41+#include "config.h"
42+
43 #include <gio/gdesktopappinfo.h>
44
45 #include "FavoriteStoreGSettings.h"
46
47 #define SETTINGS_NAME "com.canonical.Unity.Launcher"
48
49+#define LATEST_SETTINGS_MIGRATION "3.2.0"
50+
51 static void on_settings_updated (GSettings *settings, const gchar *key, FavoriteStoreGSettings *self);
52
53 FavoriteStoreGSettings::FavoriteStoreGSettings ()
54@@ -41,9 +45,30 @@
55 void
56 FavoriteStoreGSettings::Init ()
57 {
58+ gchar *latest_migration_update;
59+
60 m_favorites = NULL;
61 m_ignore_signals = false;
62
63+ /* migrate the favorites if needed and ignore errors */
64+ latest_migration_update = g_settings_get_string (m_settings, "favorite-migration");
65+ if (g_strcmp0 (latest_migration_update, LATEST_SETTINGS_MIGRATION) < 0)
66+ {
67+ GError *error = NULL;
68+ char *cmd = g_strdup_printf ("%s/lib/unity/migrate_favorites.py", PREFIXDIR);
69+ char *output;
70+
71+ g_spawn_command_line_sync (cmd, &output, NULL, NULL, &error);
72+ if (error)
73+ {
74+ printf ("WARNING: Unable to run the migrate favorites tools successfully: %s.\nThe output was:%s\n", error->message,output);
75+ g_error_free (error);
76+ }
77+ g_free (output);
78+ g_free (cmd);
79+ }
80+ g_free (latest_migration_update);
81+
82 g_signal_connect (m_settings, "changed",
83 G_CALLBACK (on_settings_updated), this);
84
85
86=== added file 'tools/CMakeLists.txt'
87--- tools/CMakeLists.txt 1970-01-01 00:00:00 +0000
88+++ tools/CMakeLists.txt 2010-11-25 15:59:43 +0000
89@@ -0,0 +1,5 @@
90+#
91+# Some unity tools
92+#
93+install(FILES migrate_favorites.py PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/unity/)
94+
95
96=== modified file 'tools/migrate_favorites.py'
97--- tools/migrate_favorites.py 2010-10-06 08:37:47 +0000
98+++ tools/migrate_favorites.py 2010-11-25 15:59:43 +0000
99@@ -12,6 +12,10 @@
100 import gobject
101 import os
102 import sys
103+import subprocess
104+from xdg import BaseDirectory
105+
106+LAST_MIGRATION = '3.2.0'
107
108 def get_desktop_dir():
109 ''' no python binding from xdg to get the desktop directory? '''
110@@ -34,68 +38,100 @@
111 pass
112 return os.path.expanduser('~/Desktop')
113
114-def register_new_app(client, launcher_location, apps_list, priority_position):
115- key_name = 'app-%s' % launcher_location.split('/')[-1]
116- # remove forbidden key in gconf:
117- for val in [' ', '+', '\'', '"', '\\', '`', '[', ']', '(', ')', '°', '#', '~', '|', '&', '=', '?']:
118- key_name = key_name.replace(val, '_')
119- # default distribution launcher don't begin with / and don't have a desktop file in ~/.gnome2
120- if os.path.exists(launcher_location) and key_name not in apps_list:
121- apps_list.append(key_name)
122- app_gconf_key_path = '/desktop/unity/launcher/favorites/%s' % key_name
123- client.set_string('%s/desktop_file' % app_gconf_key_path, launcher_location)
124- client.set_float('%s/priority' % app_gconf_key_path, priority_position)
125- client.set_string('%s/type' % app_gconf_key_path, 'application')
126- priority_position += 1
127- #print key_name
128- #print launcher_location
129- #print priority_position
130- return (apps_list, priority_position)
131-
132-if os.path.exists(os.path.expanduser('~/.gconf/desktop/unity/')):
133- print "migration already done or unity used before migration support"
134+def register_new_app(launcher_location, apps_list):
135+ ''' append a new app with full desktop path if valid, take care of dups '''
136+
137+ # default distribution launcher don't go into that function (as don't have an aboslute path)
138+ entry = ""
139+ if os.path.exists(launcher_location):
140+ # try to strip the full path we had in unity mutter if it's part of a xdg path:
141+ for xdg_dir in BaseDirectory.xdg_data_dirs:
142+ xdg_app_dir = os.path.join(xdg_dir, "applications", "")
143+ if launcher_location.startswith(xdg_app_dir):
144+ candidate_desktop_file = launcher_location.split(xdg_app_dir)[1]
145+ # if really the xdg path is the path to the launcher
146+ if not '/' in candidate_desktop_file:
147+ entry = candidate_desktop_file
148+ break
149+ if not entry:
150+ entry = launcher_location
151+ if entry not in apps_list:
152+ apps_list.append(entry)
153+
154+ return apps_list
155+
156+
157+migration_level = subprocess.Popen(["gsettings", "get", "com.canonical.Unity.Launcher", "favorite-migration"], stdout=subprocess.PIPE).communicate()[0].strip()[1:-1]
158+if migration_level >= LAST_MIGRATION:
159+ print "Migration already done"
160 sys.exit(0)
161
162 client = gconf.client_get_default()
163
164-# import current defaults
165-apps_list = client.get_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING)
166-priority_position = len(apps_list) + 1
167-
168-# get GNOME panel favorites and convert them
169-panel_list = client.get_list('/apps/panel/general/toplevel_id_list', gconf.VALUE_STRING)
170-candidate_objects = client.get_list('/apps/panel/general/object_id_list', gconf.VALUE_STRING)
171-for candidate in candidate_objects:
172- candidate_path = '/apps/panel/objects/%s' % candidate
173- if (client.get_string('%s/object_type' % candidate_path) == 'launcher-object'
174- and client.get_string('%s/toplevel_id' % candidate_path) in panel_list):
175- launcher_location = client.get_string('%s/launcher_location' % candidate_path)
176- if launcher_location:
177- if not launcher_location.startswith('/'):
178- launcher_location = os.path.expanduser('~/.gnome2/panel2.d/default/launchers/%s' % launcher_location)
179- (apps_list, priority_position) = register_new_app(client, launcher_location, apps_list, priority_position)
180-
181-
182-# get UNE lucid panel favorites and convert them
183-lucid_favorites_list = client.get_list('/apps/netbook-launcher/favorites/favorites_list', gconf.VALUE_STRING)
184-for candidate in lucid_favorites_list:
185- candidate_path = '/apps/netbook-launcher/favorites/%s' % candidate
186- if (client.get_string('%s/type' % candidate_path) == 'application'):
187- launcher_location = client.get_string('%s/desktop_file' % candidate_path)
188- if launcher_location:
189- (apps_list, priority_position) = register_new_app(client, launcher_location, apps_list, priority_position)
190-
191-# get GNOME desktop launchers
192-desktop_dir = get_desktop_dir()
193-for launcher_location in glob.glob('%s/*.desktop' % desktop_dir):
194- # blacklist ubiquity as will have two ubiquity in the netbook live session then
195- if not "ubiquity" in launcher_location:
196- (apps_list, priority_position) = register_new_app(client, launcher_location, apps_list, priority_position)
197-
198-# set list of default and new favorites and write everything!
199-client.set_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING, apps_list)
200-#print apps_list
201-client.clear_cache()
202-# ugly workaround to force gconf client to actually dump its cache to gconfd
203-loop = gobject.MainLoop(); gobject.idle_add(loop.quit); loop.run();
204+# get current gsettings defaults into a list
205+defaults_call = subprocess.Popen(["gsettings", "get", "com.canonical.Unity.Launcher", "favorites"], stdout=subprocess.PIPE)
206+apps_list = [elem.strip()[1:-1] for elem in defaults_call.communicate()[0].strip()[1:-1].split(',')]
207+
208+# first migration to unity compiz
209+if migration_level < '3.2.0':
210+
211+ unity_mutter_favorites_list = client.get_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING)
212+ unity_mutter_launcher_ordered = {}
213+ for candidate in unity_mutter_favorites_list:
214+ candidate_path = '/desktop/unity/launcher/favorites/%s' % candidate
215+ if (client.get_string('%s/type' % candidate_path) == 'application'):
216+ launcher_location = client.get_string('%s/desktop_file' % candidate_path)
217+ position = client.get_string('%s/desktop_file' % candidate_path)
218+ if launcher_location:
219+ # try to preserve the order, will be done in a second loop
220+ unity_mutter_launcher_ordered[position] = launcher_location
221+ for launcher_location in unity_mutter_launcher_ordered:
222+ apps_list = register_new_app(launcher_location, apps_list)
223+
224+
225+ # import netbook-launcher favorites and convert them
226+ lucid_favorites_list = client.get_list('/apps/netbook-launcher/favorites/favorites_list', gconf.VALUE_STRING)
227+ for candidate in lucid_favorites_list:
228+ candidate_path = '/apps/netbook-launcher/favorites/%s' % candidate
229+ if (client.get_string('%s/type' % candidate_path) == 'application'):
230+ launcher_location = client.get_string('%s/desktop_file' % candidate_path)
231+ if launcher_location:
232+ apps_list = register_new_app(launcher_location, apps_list)
233+
234+ # get GNOME panel favorites and convert them
235+ panel_list = client.get_list('/apps/panel/general/toplevel_id_list', gconf.VALUE_STRING)
236+ candidate_objects = client.get_list('/apps/panel/general/object_id_list', gconf.VALUE_STRING)
237+ for candidate in candidate_objects:
238+ candidate_path = '/apps/panel/objects/%s' % candidate
239+ if (client.get_string('%s/object_type' % candidate_path) == 'launcher-object'
240+ and client.get_string('%s/toplevel_id' % candidate_path) in panel_list):
241+ launcher_location = client.get_string('%s/launcher_location' % candidate_path)
242+ if launcher_location:
243+ if not launcher_location.startswith('/'):
244+ launcher_location = os.path.expanduser('~/.gnome2/panel2.d/default/launchers/%s' % launcher_location)
245+ apps_list = register_new_app(launcher_location, apps_list)
246+
247+ # get GNOME desktop launchers
248+ desktop_dir = get_desktop_dir()
249+ for launcher_location in glob.glob('%s/*.desktop' % desktop_dir):
250+ # blacklist ubiquity as will have two ubiquity in the netbook live session then
251+ if not "ubiquity" in launcher_location:
252+ apps_list = register_new_app(launcher_location, apps_list)
253+
254+ # Now write to gsettings!
255+ #print apps_list
256+ return_code = subprocess.call(["gsettings", "set", "com.canonical.Unity.Launcher", "favorites", str(apps_list)])
257+
258+ if return_code != 0:
259+ print "Settings fail to transition to new unity compiz"
260+ sys.exit(1)
261+
262+ # some autumn cleanage (gconf binding for recursive_unset seems broken)
263+ subprocess.call(["gconftool-2", "--recursive-unset", "/apps/netbook-launcher"])
264+ subprocess.call(["gconftool-2", "--recursive-unset", "/desktop/unity"])
265+ print "Settings successfully transitionned to new unity compiz"
266+
267+# stamp that all went well
268+subprocess.call(["gsettings", "set", "com.canonical.Unity.Launcher", "favorite-migration", "\'%s\'" % LAST_MIGRATION])
269+sys.exit(0)
270