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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2010-11-24 21:44:18 +0000
+++ CMakeLists.txt 2010-11-25 15:59:43 +0000
@@ -1,7 +1,7 @@
1 project (unity)1 project (unity)
2cmake_minimum_required(VERSION 2.8)2cmake_minimum_required(VERSION 2.8)
33
4subdirs (libunity services tests)4subdirs (libunity services tests tools)
55
6#6#
7# Base bits7# Base bits
88
=== modified file 'com.canonical.Unity.gschema.xml'
--- com.canonical.Unity.gschema.xml 2010-11-22 10:40:59 +0000
+++ com.canonical.Unity.gschema.xml 2010-11-25 15:59:43 +0000
@@ -1,9 +1,14 @@
1<schemalist>1<schemalist>
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">
3 <key type="as" name="favorites">3 <key type="as" name="favorites">
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>
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>
6 <description>These applications are shown in the Launcher by default.</description>6 <description>These applications are shown in the Launcher by default.</description>
7 </key>7 </key>
8 <key type="s" name="favorite-migration">
9 <default>''</default>
10 <summary>Version of last migration done</summary>
11 <description>This is a detection key for the favorite migration script to know whether the needed migration is done or not.</description>
12 </key>
8 </schema>13 </schema>
9</schemalist>14</schemalist>
1015
=== modified file 'src/FavoriteStoreGSettings.cpp'
--- src/FavoriteStoreGSettings.cpp 2010-11-24 22:57:59 +0000
+++ src/FavoriteStoreGSettings.cpp 2010-11-25 15:59:43 +0000
@@ -16,12 +16,16 @@
16* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>16* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
17*/17*/
1818
19#include "config.h"
20
19#include <gio/gdesktopappinfo.h>21#include <gio/gdesktopappinfo.h>
2022
21#include "FavoriteStoreGSettings.h"23#include "FavoriteStoreGSettings.h"
2224
23#define SETTINGS_NAME "com.canonical.Unity.Launcher"25#define SETTINGS_NAME "com.canonical.Unity.Launcher"
2426
27#define LATEST_SETTINGS_MIGRATION "3.2.0"
28
25static void on_settings_updated (GSettings *settings, const gchar *key, FavoriteStoreGSettings *self);29static void on_settings_updated (GSettings *settings, const gchar *key, FavoriteStoreGSettings *self);
2630
27FavoriteStoreGSettings::FavoriteStoreGSettings ()31FavoriteStoreGSettings::FavoriteStoreGSettings ()
@@ -41,9 +45,30 @@
41void45void
42FavoriteStoreGSettings::Init ()46FavoriteStoreGSettings::Init ()
43{47{
48 gchar *latest_migration_update;
49
44 m_favorites = NULL;50 m_favorites = NULL;
45 m_ignore_signals = false;51 m_ignore_signals = false;
4652
53 /* migrate the favorites if needed and ignore errors */
54 latest_migration_update = g_settings_get_string (m_settings, "favorite-migration");
55 if (g_strcmp0 (latest_migration_update, LATEST_SETTINGS_MIGRATION) < 0)
56 {
57 GError *error = NULL;
58 char *cmd = g_strdup_printf ("%s/lib/unity/migrate_favorites.py", PREFIXDIR);
59 char *output;
60
61 g_spawn_command_line_sync (cmd, &output, NULL, NULL, &error);
62 if (error)
63 {
64 printf ("WARNING: Unable to run the migrate favorites tools successfully: %s.\nThe output was:%s\n", error->message,output);
65 g_error_free (error);
66 }
67 g_free (output);
68 g_free (cmd);
69 }
70 g_free (latest_migration_update);
71
47 g_signal_connect (m_settings, "changed",72 g_signal_connect (m_settings, "changed",
48 G_CALLBACK (on_settings_updated), this);73 G_CALLBACK (on_settings_updated), this);
4974
5075
=== added file 'tools/CMakeLists.txt'
--- tools/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tools/CMakeLists.txt 2010-11-25 15:59:43 +0000
@@ -0,0 +1,5 @@
1#
2# Some unity tools
3#
4install(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/)
5
06
=== modified file 'tools/migrate_favorites.py'
--- tools/migrate_favorites.py 2010-10-06 08:37:47 +0000
+++ tools/migrate_favorites.py 2010-11-25 15:59:43 +0000
@@ -12,6 +12,10 @@
12import gobject12import gobject
13import os13import os
14import sys14import sys
15import subprocess
16from xdg import BaseDirectory
17
18LAST_MIGRATION = '3.2.0'
1519
16def get_desktop_dir():20def get_desktop_dir():
17 ''' no python binding from xdg to get the desktop directory? '''21 ''' no python binding from xdg to get the desktop directory? '''
@@ -34,68 +38,100 @@
34 pass38 pass
35 return os.path.expanduser('~/Desktop')39 return os.path.expanduser('~/Desktop')
3640
37def register_new_app(client, launcher_location, apps_list, priority_position):41def register_new_app(launcher_location, apps_list):
38 key_name = 'app-%s' % launcher_location.split('/')[-1]42 ''' append a new app with full desktop path if valid, take care of dups '''
39 # remove forbidden key in gconf:43
40 for val in [' ', '+', '\'', '"', '\\', '`', '[', ']', '(', ')', '°', '#', '~', '|', '&', '=', '?']:44 # default distribution launcher don't go into that function (as don't have an aboslute path)
41 key_name = key_name.replace(val, '_')45 entry = ""
42 # default distribution launcher don't begin with / and don't have a desktop file in ~/.gnome246 if os.path.exists(launcher_location):
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:
44 apps_list.append(key_name)48 for xdg_dir in BaseDirectory.xdg_data_dirs:
45 app_gconf_key_path = '/desktop/unity/launcher/favorites/%s' % key_name49 xdg_app_dir = os.path.join(xdg_dir, "applications", "")
46 client.set_string('%s/desktop_file' % app_gconf_key_path, launcher_location)50 if launcher_location.startswith(xdg_app_dir):
47 client.set_float('%s/priority' % app_gconf_key_path, priority_position)51 candidate_desktop_file = launcher_location.split(xdg_app_dir)[1]
48 client.set_string('%s/type' % app_gconf_key_path, 'application')52 # if really the xdg path is the path to the launcher
49 priority_position += 153 if not '/' in candidate_desktop_file:
50 #print key_name54 entry = candidate_desktop_file
51 #print launcher_location55 break
52 #print priority_position56 if not entry:
53 return (apps_list, priority_position)57 entry = launcher_location
5458 if entry not in apps_list:
55if os.path.exists(os.path.expanduser('~/.gconf/desktop/unity/')):59 apps_list.append(entry)
56 print "migration already done or unity used before migration support"60
61 return apps_list
62
63
64migration_level = subprocess.Popen(["gsettings", "get", "com.canonical.Unity.Launcher", "favorite-migration"], stdout=subprocess.PIPE).communicate()[0].strip()[1:-1]
65if migration_level >= LAST_MIGRATION:
66 print "Migration already done"
57 sys.exit(0)67 sys.exit(0)
5868
59client = gconf.client_get_default()69client = gconf.client_get_default()
6070
61# import current defaults71# get current gsettings defaults into a list
62apps_list = client.get_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING)72defaults_call = subprocess.Popen(["gsettings", "get", "com.canonical.Unity.Launcher", "favorites"], stdout=subprocess.PIPE)
63priority_position = len(apps_list) + 173apps_list = [elem.strip()[1:-1] for elem in defaults_call.communicate()[0].strip()[1:-1].split(',')]
6474
65# get GNOME panel favorites and convert them75# first migration to unity compiz
66panel_list = client.get_list('/apps/panel/general/toplevel_id_list', gconf.VALUE_STRING)76if migration_level < '3.2.0':
67candidate_objects = client.get_list('/apps/panel/general/object_id_list', gconf.VALUE_STRING)77
68for candidate in candidate_objects:78 unity_mutter_favorites_list = client.get_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING)
69 candidate_path = '/apps/panel/objects/%s' % candidate79 unity_mutter_launcher_ordered = {}
70 if (client.get_string('%s/object_type' % candidate_path) == 'launcher-object'80 for candidate in unity_mutter_favorites_list:
71 and client.get_string('%s/toplevel_id' % candidate_path) in panel_list):81 candidate_path = '/desktop/unity/launcher/favorites/%s' % candidate
72 launcher_location = client.get_string('%s/launcher_location' % candidate_path)82 if (client.get_string('%s/type' % candidate_path) == 'application'):
73 if launcher_location:83 launcher_location = client.get_string('%s/desktop_file' % candidate_path)
74 if not launcher_location.startswith('/'):84 position = client.get_string('%s/desktop_file' % candidate_path)
75 launcher_location = os.path.expanduser('~/.gnome2/panel2.d/default/launchers/%s' % launcher_location)85 if launcher_location:
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
7787 unity_mutter_launcher_ordered[position] = launcher_location
7888 for launcher_location in unity_mutter_launcher_ordered:
79# get UNE lucid panel favorites and convert them89 apps_list = register_new_app(launcher_location, apps_list)
80lucid_favorites_list = client.get_list('/apps/netbook-launcher/favorites/favorites_list', gconf.VALUE_STRING)90
81for candidate in lucid_favorites_list:91
82 candidate_path = '/apps/netbook-launcher/favorites/%s' % candidate92 # import netbook-launcher favorites and convert them
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)
84 launcher_location = client.get_string('%s/desktop_file' % candidate_path)94 for candidate in lucid_favorites_list:
85 if launcher_location: 95 candidate_path = '/apps/netbook-launcher/favorites/%s' % candidate
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'):
87 97 launcher_location = client.get_string('%s/desktop_file' % candidate_path)
88# get GNOME desktop launchers98 if launcher_location:
89desktop_dir = get_desktop_dir()99 apps_list = register_new_app(launcher_location, apps_list)
90for launcher_location in glob.glob('%s/*.desktop' % desktop_dir):100
91 # blacklist ubiquity as will have two ubiquity in the netbook live session then101 # get GNOME panel favorites and convert them
92 if not "ubiquity" in launcher_location:102 panel_list = client.get_list('/apps/panel/general/toplevel_id_list', gconf.VALUE_STRING)
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)
94104 for candidate in candidate_objects:
95# set list of default and new favorites and write everything!105 candidate_path = '/apps/panel/objects/%s' % candidate
96client.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'
97#print apps_list107 and client.get_string('%s/toplevel_id' % candidate_path) in panel_list):
98client.clear_cache()108 launcher_location = client.get_string('%s/launcher_location' % candidate_path)
99# ugly workaround to force gconf client to actually dump its cache to gconfd109 if launcher_location:
100loop = gobject.MainLoop(); gobject.idle_add(loop.quit); loop.run();110 if not launcher_location.startswith('/'):
111 launcher_location = os.path.expanduser('~/.gnome2/panel2.d/default/launchers/%s' % launcher_location)
112 apps_list = register_new_app(launcher_location, apps_list)
113
114 # get GNOME desktop launchers
115 desktop_dir = get_desktop_dir()
116 for launcher_location in glob.glob('%s/*.desktop' % desktop_dir):
117 # blacklist ubiquity as will have two ubiquity in the netbook live session then
118 if not "ubiquity" in launcher_location:
119 apps_list = register_new_app(launcher_location, apps_list)
120
121 # Now write to gsettings!
122 #print apps_list
123 return_code = subprocess.call(["gsettings", "set", "com.canonical.Unity.Launcher", "favorites", str(apps_list)])
124
125 if return_code != 0:
126 print "Settings fail to transition to new unity compiz"
127 sys.exit(1)
128
129 # some autumn cleanage (gconf binding for recursive_unset seems broken)
130 subprocess.call(["gconftool-2", "--recursive-unset", "/apps/netbook-launcher"])
131 subprocess.call(["gconftool-2", "--recursive-unset", "/desktop/unity"])
132 print "Settings successfully transitionned to new unity compiz"
133
134# stamp that all went well
135subprocess.call(["gsettings", "set", "com.canonical.Unity.Launcher", "favorite-migration", "\'%s\'" % LAST_MIGRATION])
136sys.exit(0)
101137