Merge lp:~amith/unity/unity-reset-fix into lp:unity

Proposed by amith kk
Status: Rejected
Rejected by: Christopher Townsend
Proposed branch: lp:~amith/unity/unity-reset-fix
Merge into: lp:unity
Diff against target: 156 lines (+81/-35)
1 file modified
tools/unity.cmake (+81/-35)
To merge this branch: bzr merge lp:~amith/unity/unity-reset-fix
Reviewer Review Type Date Requested Status
Timo Jyrinki Needs Fixing
Review via email: mp+130828@code.launchpad.net

Commit message

Restores unity --reset and fixes unity --reset-icons

Description of the change

== Problem ==
unity --reset depreciated in Unity 5. unity --reset_icons used to use subprocess

== Fix ==
Added def to reset unity when unity --reset is called. Replace bad subprocess calls with gsettings API

== Test ==
Run unity --reset and unity --reset-icons

Thanks to Barneedhar<email address hidden> and Mahesh<email address hidden>

To post a comment you must log in.
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Thanks for the patch!

As discussed on IRC, I think we will need some automated tests and stop relying on manual one. Please ping thomi and other people on #ubuntu-unity for the having an autopilot test for it (some unit one is possible as we already discussed on IRC).

Thanks again ;)

Revision history for this message
Timo Jyrinki (timo-jyrinki) wrote :

Needs fixing, to have automated test included.

review: Needs Fixing
Revision history for this message
Christopher Townsend (townsend) wrote :

This is a rather old MP now and no additional work has been done on it in years. Rejecting...

Unmerged revisions

2866. By amith kk

modified:
  tools/unity.cmake

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tools/unity.cmake'
2--- tools/unity.cmake 2012-09-19 07:19:37 +0000
3+++ tools/unity.cmake 2012-10-22 14:41:47 +0000
4@@ -27,6 +27,8 @@
5 import subprocess
6 import sys
7 import time
8+from gi.repository import Gio
9+import re
10
11 home_dir = os.path.expanduser("~%s" % os.getenv("SUDO_USER"))
12 supported_prefix = "/usr/local"
13@@ -65,7 +67,52 @@
14
15 def reset_launcher_icons ():
16 '''Reset the default launcher icon and restart it.'''
17- subprocess.Popen(["gsettings", "reset" ,"com.canonical.Unity.Launcher" , "favorites"])
18+
19+ gsettings=Gio.Settings("com.canonical.Unity.Launcher")
20+ if "favorites" in gsettings.list_keys():
21+ gsettings.reset("favorites")
22+ else:
23+ print "ERROR: Unable to reset Launcher icons"
24+ print "key 'favourites' in Schema 'com.canonical.Unity.Launcher' is missing"
25+def reset_unity ():
26+
27+ subprocess.Popen(["killall", "unity-panel-service"])
28+ subprocess.Popen(["killall", "compiz"])
29+ allSchemas=Gio.Settings.list_schemas()
30+ allRelocatableSchemas=Gio.Settings.list_relocatable_schemas()
31+
32+ def resetAllKeys(schema,path=None):
33+ """Reset all keys in given Schema."""
34+ if (schema not in allSchemas) and (schema not in allRelocatableSchemas):
35+ print "Ignoring missing Schema %s"%schema
36+ return
37+ gsettings=Gio.Settings(schema=schema,path=path)
38+ for key in gsettings.list_keys():
39+ gsettings.reset(key)
40+ print "Schema %s successfully reset"%schema
41+
42+ def resetPlugins():
43+ """Reset Compiz Plugins"""
44+ compizPluginRe=re.compile(r'(?P<plugin>org.compiz.)')
45+ for schema in allRelocatableSchemas:
46+ if compizPluginRe.match(schema):
47+ plugin=compizPluginRe.sub('',schema)
48+ schema='org.compiz.'+plugin
49+ path="/org/compiz/profiles/unity/plugins/"+plugin+"/"
50+ resetAllKeys(schema=schema,path=path)
51+
52+ def resetUnityChildren():
53+ """Reset keys in child schemas of Unity"""
54+ unitySchema='com.canonical.Unity'
55+ blacklists=['com.canonical.Unity.Launcher','com.canonical.Unity.webapps','com.canonical.Unity.Lenses']
56+ unityChildRe=re.compile(unitySchema)
57+ for schema in allSchemas:
58+ if (schema not in blacklists) and (unityChildRe.match(schema)):
59+ resetAllKeys(schema)
60+
61+ resetPlugins()
62+ resetUnityChildren()
63+
64
65 def process_and_start_unity (verbose, debug_mode, compiz_args, log_file):
66 '''launch unity under compiz (replace the current shell in any case)'''
67@@ -121,31 +168,31 @@
68 sys.exit(unity_instance.returncode)
69
70 def reset_to_distro():
71- ''' remove all known default local installation path '''
72-
73- # check if we are root, we need to be root
74- if os.getuid() != 0:
75- print "Error: You need to be root to remove your local unity installation"
76- return 1
77- error = False
78-
79- for filedir in well_known_local_path:
80- for elem in glob.glob(filedir):
81- try:
82- shutil.rmtree(elem)
83- except OSError, e:
84- if os.path.isfile(elem) or os.path.islink(elem):
85- os.remove(elem)
86- else:
87- print "ERROR: Cannot remove %s: %s" % (elem, e)
88- error = True
89-
90- if error:
91- print "See above: some error happened and you should clean them before trying to restart unity"
92- return 1
93- else:
94- print "Unity local install cleaned, you can now restart unity"
95- return 0
96+ ''' remove all known default local installation path '''
97+
98+ # check if we are root, we need to be root
99+ if os.getuid() != 0:
100+ print "Error: You need to be root to remove your local unity installation"
101+ return 1
102+ error = False
103+
104+ for filedir in well_known_local_path:
105+ for elem in glob.glob(filedir):
106+ try:
107+ shutil.rmtree(elem)
108+ except OSError, e:
109+ if os.path.isfile(elem) or os.path.islink(elem):
110+ os.remove(elem)
111+ else:
112+ print "ERROR: Cannot remove %s: %s" % (elem, e)
113+ error = True
114+
115+ if error:
116+ print "See above: some error happened and you should clean them before trying to restart unity"
117+ return 1
118+ else:
119+ print "Unity local install cleaned, you can now restart unity"
120+ return 0
121
122 if __name__ == '__main__':
123 usage = "usage: %prog [options]"
124@@ -162,7 +209,7 @@
125 parser.add_option("--replace", action="store_true",
126 help="Run unity /!\ This is for compatibility with other desktop interfaces and acts the same as running unity without --replace")
127 parser.add_option("--reset", action="store_true",
128- help="Reset is not supported anymore. Deprecated option")
129+ help="Reset all the settings of Unity except Launcher icons, webapps and remote lens")
130 parser.add_option("--reset-icons", action="store_true",
131 help="Reset the default launcher icon.")
132 parser.add_option("-v", "--verbose", action="store_true",
133@@ -172,16 +219,15 @@
134 set_unity_env()
135
136 if options.distro:
137- sys.exit(reset_to_distro())
138+ sys.exit(reset_to_distro())
139
140 if options.reset:
141- print ("ERROR: the reset option is now deprecated")
142- sys.exit(1)
143-
144+ reset_unity ()
145+
146 if options.reset_icons:
147 reset_launcher_icons ()
148-
149- if options.replace:
150- print ("WARNING: This is for compatibility with other desktop interfaces please use unity without --replace")
151-
152+
153+ if options.replace:
154+ print ("WARNING: This is for compatibility with other desktop interfaces please use unity without --replace")
155+
156 run_unity (options.verbose, options.debug, options.advanced_debug, args, options.log)