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

Proposed by Didier Roche-Tolomelli
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 754
Proposed branch: lp:~didrocks/unity/migrate-docks
Merge into: lp:unity
Diff against target: 193 lines (+96/-23)
2 files modified
src/FavoriteStoreGSettings.cpp (+1/-1)
tools/migrate_favorites.py (+95/-22)
To merge this branch: bzr merge lp:~didrocks/unity/migrate-docks
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
Review via email: mp+45175@code.launchpad.net

Description of the change

This branch enables:
- advanced matching on Exec key of the desktop file with system desktop file to
  avoid using copy (this complete the basic name matching already and is
  completed with more advanced heuristic for cairo-dock and such)
- migrate popular dock launchers to fix bug #692967. Now are handled:
  awn
  docky (multiple docks configuration are handled)
  cairo-dock

To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) wrote :

Tested with cairo-dock and seems to work fine

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/FavoriteStoreGSettings.cpp'
2--- src/FavoriteStoreGSettings.cpp 2010-12-10 03:15:24 +0000
3+++ src/FavoriteStoreGSettings.cpp 2011-01-04 21:29:33 +0000
4@@ -24,7 +24,7 @@
5
6 #define SETTINGS_NAME "com.canonical.Unity.Launcher"
7
8-#define LATEST_SETTINGS_MIGRATION "3.2.0"
9+#define LATEST_SETTINGS_MIGRATION "3.2.10"
10
11 static void on_settings_updated (GSettings *settings, const gchar *key, FavoriteStoreGSettings *self);
12
13
14=== modified file 'tools/migrate_favorites.py'
15--- tools/migrate_favorites.py 2010-12-09 12:09:39 +0000
16+++ tools/migrate_favorites.py 2011-01-04 21:29:33 +0000
17@@ -16,7 +16,7 @@
18 import subprocess
19 from xdg import BaseDirectory
20
21-LAST_MIGRATION = '3.2.0'
22+LAST_MIGRATION = '3.2.10'
23
24 def get_log_file():
25 ''' open the log file and return it '''
26@@ -32,7 +32,7 @@
27 def migrating_chapter_log(name, apps_list, migration_list, log_file):
28 '''Log migration of new launchers'''
29
30- log(" Migration for %s.\n Current app list is: %s\n Candidates are: %s" % (name, apps_list, migration_list), log_file)
31+ log(" + Migration for %s.\n Current app list is: %s\n Candidates are: %s" % (name, apps_list, migration_list), log_file)
32
33
34 def log(message, log_file):
35@@ -67,10 +67,15 @@
36 # default distribution launcher don't go into that function (as don't have an aboslute path)
37 entry = ""
38 if os.path.exists(launcher_location):
39- log(" == %s: exists" % launcher_location, log_file)
40+ log(" == %s: exists" % launcher_location, log_file)
41 # try to strip the full path we had in unity mutter if it's part of a xdg path:
42 # or try to get that for other desktop file based on name.
43 candidate_desktop_filename = launcher_location.split("/")[-1]
44+ # some desktop file with modified exec key (like in cairo-dock contains 01desktopfilename.desktop, strip that)
45+ try:
46+ candidate_cairodock_desktop_filename = candidate_desktop_filename.split("01")[1]
47+ except IndexError:
48+ candidate_cairodock_desktop_filename = ""
49 for xdg_dir in BaseDirectory.xdg_data_dirs:
50 xdg_app_dir = os.path.join(xdg_dir, "applications", "")
51 if launcher_location.startswith(xdg_app_dir):
52@@ -78,25 +83,66 @@
53 # if really the xdg path is the path to the launcher
54 if not '/' in candidate_desktop_file:
55 entry = candidate_desktop_file
56+ log(" Direct match found for system desktop file", log_file)
57 break
58 # second chance: try to see if the desktop filename is in xdg path and so, assume it's a match
59- if os.path.exists("%s/%s" % (xdg_app_dir, candidate_desktop_filename)):
60+ if not entry and os.path.exists("%s/%s" % (xdg_app_dir, candidate_desktop_filename)):
61 entry = candidate_desktop_filename
62- break
63+ log(" Similar desktop file name with system desktop file", log_file)
64+ break
65+ # third chance: try to see if a tweaked cairo-dock like deskto file name is in xdg path
66+ if not entry and os.path.exists("%s/%s" % (xdg_app_dir, candidate_cairodock_desktop_filename)):
67+ entry = candidate_cairodock_desktop_filename
68+ log(" Similar Cairo-Dock -like desktop file name with system desktop file", log_file)
69+ break
70+ # fourth and last chance: try to find a corresponding Exec key.
71+ # Wait! scanning /usr/share/applications is heavy !!!
72+ # Don't panic, we have the bamf.index for that :)
73+ if not entry:
74+ exec_arg = ""
75+ try:
76+ for line in open(launcher_location):
77+ if "Exec=" in line:
78+ exec_arg = line.split("Exec=")[1]
79+ break
80+ except IOError:
81+ log(" Can't open %s for reading Exec" % launcher_location, log_file)
82+ if exec_arg:
83+ try:
84+ for line in open("/usr/share/applications/bamf.index"):
85+ if exec_arg in line:
86+ entry = line.split()[0]
87+ log(" Coherent exec key found with system desktop file", log_file)
88+ break
89+ except IOError:
90+ log(" No bamf.index file found on the system!", log_file)
91
92 if not entry:
93 entry = launcher_location
94- log(" %s: real entry is %s" % (launcher_location, entry), log_file)
95+ log(" %s: real entry is %s" % (launcher_location, entry), log_file)
96 if entry not in apps_list:
97- log(" --- adding %s as not in app_list" % entry, log_file)
98+ log(" --- adding %s as not in app_list" % entry, log_file)
99 apps_list.append(entry)
100 else:
101- log(" --- NOT adding %s as already in app_list" % entry, log_file)
102+ log(" --- NOT adding %s as already in app_list" % entry, log_file)
103 else:
104- log(" == %s: doesn't exist" % launcher_location, log_file)
105+ log(" == %s: doesn't exist" % launcher_location, log_file)
106
107 return apps_list
108
109+def save_gsettings_favorites(apps_list, log_file):
110+ ''' save the app list favorites to gsettings '''
111+
112+ #print apps_list
113+ return_code = subprocess.call(["gsettings", "set", "com.canonical.Unity.Launcher", "favorites", str(apps_list)])
114+
115+ if return_code != 0:
116+ print "Settings fail to transition to new unity compiz favorites"
117+ log("Settings fail to transition to new unity compiz favorites\n\n", log_file)
118+ if log_file:
119+ log_file.close()
120+ sys.exit(1)
121+
122 try:
123 migration_level = subprocess.Popen(["gsettings", "get", "com.canonical.Unity.Launcher", "favorite-migration"], stdout=subprocess.PIPE).communicate()[0].strip()[1:-1]
124 except OSError, e:
125@@ -162,29 +208,56 @@
126 # get GNOME desktop launchers
127 desktop_dir = get_desktop_dir()
128 desktop_items = glob.glob('%s/*.desktop' % desktop_dir)
129- migrating_chapter_log("deskop items in %s" % desktop_dir, apps_list, desktop_items, log_file)
130+ migrating_chapter_log("desktop items in %s" % desktop_dir, apps_list, desktop_items, log_file)
131 for launcher_location in glob.glob('%s/*.desktop' % desktop_dir):
132 # blacklist ubiquity as will have two ubiquity in the netbook live session then
133 if not "ubiquity" in launcher_location:
134 apps_list = register_new_app(launcher_location, apps_list, log_file)
135
136 # Now write to gsettings!
137- #print apps_list
138- return_code = subprocess.call(["gsettings", "set", "com.canonical.Unity.Launcher", "favorites", str(apps_list)])
139-
140- if return_code != 0:
141- print "Settings fail to transition to new unity compiz"
142- log("Settings fail to transition to new unity compiz\n\n", log_file)
143- if log_file:
144- log_file.close()
145- sys.exit(1)
146+ save_gsettings_favorites(apps_list, log_file)
147
148 # some autumn cleanage (gconf binding for recursive_unset seems broken)
149 subprocess.call(["gconftool-2", "--recursive-unset", "/apps/netbook-launcher"])
150 subprocess.call(["gconftool-2", "--recursive-unset", "/desktop/unity"])
151- print "Settings successfully transitionned to new unity compiz"
152-
153-log("Migration script ended sucessfully\n\n", log_file)
154+
155+# second migration: transition popular docks entry as well
156+if migration_level < '3.2.10':
157+ log("======= Migration to 3.2.10 =======\n", log_file)
158+
159+ # import awn favorites
160+ awn_favorites_list = client.get_list('/apps/awn-applet-taskmanager/launcher_paths', gconf.VALUE_STRING)
161+ migrating_chapter_log("awn favorites", apps_list, awn_favorites_list, log_file)
162+ for launcher_location in awn_favorites_list:
163+ apps_list = register_new_app(launcher_location, apps_list, log_file)
164+
165+ # import Docky favorites
166+ dock_list = client.get_list('/apps/docky-2/Docky/DockController/ActiveDocks', gconf.VALUE_STRING)
167+ for dock in dock_list:
168+ docky_favorites_list = client.get_list('/apps/docky-2/Docky/Interface/DockPreferences/%s/Launchers' % dock, gconf.VALUE_STRING)
169+ migrating_chapter_log("Docky favorites for %s" % dock, apps_list, docky_favorites_list, log_file)
170+ for launcher_location in docky_favorites_list:
171+ try:
172+ launcher_location = launcher_location.split("file://")[1]
173+ except IndexError:
174+ pass
175+ apps_list = register_new_app(launcher_location, apps_list, log_file)
176+
177+ # import Cairo-Dock favorites
178+ try:
179+ cairodock_path = "%s/cairo-dock/current_theme/launchers" % BaseDirectory.xdg_config_home
180+ cairodock_favorites_list = os.listdir(cairodock_path)
181+ migrating_chapter_log("Cairo-Dock favorites (in %s)" % cairodock_path, apps_list, cairodock_favorites_list, log_file)
182+ for launcher in cairodock_favorites_list:
183+ launcher_location = "%s/%s" % (cairodock_path, launcher)
184+ apps_list = register_new_app(launcher_location, apps_list, log_file)
185+ except OSError:
186+ log(" + Can't migrate Cairo-Dock as %s doesn't exist" % cairodock_path, log_file)
187+
188+ # Now write to gsettings!
189+ save_gsettings_favorites(apps_list, log_file)
190+
191+log("Migration script ended successfully\n\n", log_file)
192 if log_file:
193 log_file.close()
194