Merge lp:~didrocks/unity/migrate-favorites into lp:unity

Proposed by Didier Roche-Tolomelli
Status: Merged
Merged at revision: 489
Proposed branch: lp:~didrocks/unity/migrate-favorites
Merge into: lp:unity
Diff against target: 132 lines (+111/-0)
3 files modified
tools/Makefile.am (+2/-0)
tools/migrate_favorites.py (+95/-0)
unity/unity-favorites.vala (+14/-0)
To merge this branch: bzr merge lp:~didrocks/unity/migrate-favorites
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+34858@code.launchpad.net

Description of the change

To fix bug #622146, python script to migrate people from UNR launcher favorite, gnome panel and gnome desktop to unity launcher (non duplicate will be added to the panel).
The script is launched the first time the user is starting unity (it's a one time thing) from unity itself.

If the script fail, we don't care and continue loading unity

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Installation path: It looks like you install the migrate_favorites.py script in $prefix/libexec? But in the vala code you call it in /usr/lib...

*.vala:

 i) Can you use Config.PREFIXDIR or Config.PKGDATADIR or some other variable substitution for the script install path, otherwise you break jhbuild.

migrate_favorites.py:

 a) In get_desktop_dir(): The natural thing would be to use g_get_user_special_dir(), but it does not seem to be bound in Python... And I couldn't find it in the xdg.BaseDirectory or xdg.Config modules... So looks like you have to do what you are currently doing

 b) Can you add a comment in the bottom of the script about "magical" flushing to gconfd? :-)

Approved provided you address i) and b) some way or other.

review: Approve
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

i) fixed with Config.PREFIXDIR and tested and horrible flushing workaround comment added :)
Merging now. Thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tools/Makefile.am'
2--- tools/Makefile.am 2010-01-08 17:12:23 +0000
3+++ tools/Makefile.am 2010-09-08 13:35:55 +0000
4@@ -1,1 +1,3 @@
5 EXTRA_DIST = makebootchart.py unity-xephyr.py
6+
7+libexec_SCRIPTS = migrate_favorites.py
8
9=== added file 'tools/migrate_favorites.py'
10--- tools/migrate_favorites.py 1970-01-01 00:00:00 +0000
11+++ tools/migrate_favorites.py 2010-09-08 13:35:55 +0000
12@@ -0,0 +1,95 @@
13+#!/usr/bin/python
14+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
15+# Copyright 2010 Canonical
16+# Author: Didier Roche
17+#
18+# This program is free software: you can redistribute it and/or modify it
19+# under the terms of the GNU General Public License version 3, as published
20+# by the Free Software Foundation.
21+
22+import gconf
23+import glob
24+import gobject
25+import os
26+import sys
27+
28+def get_desktop_dir():
29+ ''' no python binding from xdg to get the desktop directory? '''
30+
31+ possible_desktop_folder = None
32+ try:
33+ for line in file(os.path.expanduser('~/.config/user-dirs.dirs')):
34+ values = line.split('=')
35+ if values[0] == 'XDG_DESKTOP_DIR':
36+ try:
37+ possible_desktop_folder = values[1][1:-2].replace('$HOME', os.path.expanduser('~'))
38+ if os.path.isdir(possible_desktop_folder):
39+ return possible_desktop_folder
40+ else:
41+ possible_desktop_folder = None
42+ break
43+ except IndexError:
44+ continue
45+ except IOError:
46+ pass
47+ return os.path.expanduser('~/Desktop')
48+
49+def register_new_app(client, launcher_location, apps_list, priority_position):
50+ key_name = 'app-%s' % launcher_location.split('/')[-1]
51+ # default distribution launcher don't begin with / and don't have a desktop file in ~/.gnome2
52+ if os.path.exists(launcher_location) and key_name not in apps_list:
53+ apps_list.append(key_name)
54+ app_gconf_key_path = '/desktop/unity/launcher/favorites/%s' % key_name
55+ client.set_string('%s/desktop_file' % app_gconf_key_path, launcher_location)
56+ client.set_float('%s/priority' % app_gconf_key_path, priority_position)
57+ client.set_string('%s/type' % app_gconf_key_path, 'application')
58+ priority_position += 1
59+ #print key_name
60+ #print launcher_location
61+ #print priority_position
62+ return (apps_list, priority_position)
63+
64+if os.path.exists(os.path.expanduser('~/.gconf/desktop/unity/')):
65+ print "migration already done or unity used before migration support"
66+ sys.exit(0)
67+
68+client = gconf.client_get_default()
69+
70+# import current defaults
71+apps_list = client.get_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING)
72+priority_position = len(apps_list) + 1
73+
74+# get GNOME panel favorites and convert them
75+panel_list = client.get_list('/apps/panel/general/toplevel_id_list', gconf.VALUE_STRING)
76+candidate_objects = client.get_list('/apps/panel/general/object_id_list', gconf.VALUE_STRING)
77+for candidate in candidate_objects:
78+ candidate_path = '/apps/panel/objects/%s' % candidate
79+ if (client.get_string('%s/object_type' % candidate_path) == 'launcher-object'
80+ and client.get_string('%s/toplevel_id' % candidate_path) in panel_list):
81+ launcher_location = client.get_string('%s/launcher_location' % candidate_path)
82+ if launcher_location:
83+ if not launcher_location.startswith('/'):
84+ launcher_location = os.path.expanduser('~/.gnome2/panel2.d/default/launchers/%s' % launcher_location)
85+ (apps_list, priority_position) = register_new_app(client, launcher_location, apps_list, priority_position)
86+
87+
88+# get UNE lucid panel favorites and convert them
89+lucid_favorites_list = client.get_list('/apps/netbook-launcher/favorites/favorites_list', gconf.VALUE_STRING)
90+for candidate in lucid_favorites_list:
91+ candidate_path = '/apps/netbook-launcher/favorites/%s' % candidate
92+ if (client.get_string('%s/type' % candidate_path) == 'application'):
93+ launcher_location = client.get_string('%s/desktop_file' % candidate_path)
94+ if launcher_location:
95+ (apps_list, priority_position) = register_new_app(client, launcher_location, apps_list, priority_position)
96+
97+# get GNOME desktop launchers
98+desktop_dir = get_desktop_dir()
99+for launcher_location in glob.glob('%s/*.desktop' % desktop_dir):
100+ (apps_list, priority_position) = register_new_app(client, launcher_location, apps_list, priority_position)
101+
102+# set list of default and new favorites and write everything!
103+client.set_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING, apps_list)
104+#print apps_list
105+client.clear_cache()
106+loop = gobject.MainLoop(); gobject.idle_add(loop.quit); loop.run();
107+
108
109=== modified file 'unity/unity-favorites.vala'
110--- unity/unity-favorites.vala 2010-07-22 10:59:27 +0000
111+++ unity/unity-favorites.vala 2010-09-08 13:35:55 +0000
112@@ -64,6 +64,20 @@
113
114 construct
115 {
116+
117+ // try to migrate favorites from desktop, old UNE and gnome-panel
118+ var gconf_custom_dir = Environment.get_home_dir () + "/.gconf/desktop/unity";
119+ var migration_script = "/usr/lib/unity/migrate_favorites.py";
120+ if (!FileUtils.test(gconf_custom_dir, FileTest.IS_DIR) &&
121+ FileUtils.test(migration_script, FileTest.IS_EXECUTABLE))
122+ {
123+ try
124+ {
125+ GLib.Process.spawn_command_line_sync(migration_script);
126+ }
127+ catch (SpawnError e) { } // no migration, don't bother
128+ }
129+
130 client = GConf.Client.get_default ();
131 notify_map = new HashMap<string, uint> ();
132 favorite_added.connect (on_favorite_added);