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