Merge lp:~3v1n0/unity/unity-script-use-upstart into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 4097
Proposed branch: lp:~3v1n0/unity/unity-script-use-upstart
Merge into: lp:unity
Diff against target: 117 lines (+36/-21)
1 file modified
tools/unity.cmake (+36/-21)
To merge this branch: bzr merge lp:~3v1n0/unity/unity-script-use-upstart
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+290386@code.launchpad.net

Commit message

Unity: stop unity7 upstart instance if needed and restart it if not clearly requested

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tools/unity.cmake'
--- tools/unity.cmake 2015-12-17 23:30:10 +0000
+++ tools/unity.cmake 2016-03-30 02:47:25 +0000
@@ -28,6 +28,7 @@
28import sys28import sys
29import time29import time
3030
31DEFAULT_COMMAND = "compiz --replace"
31home_dir = os.path.expanduser("~%s" % os.getenv("SUDO_USER"))32home_dir = os.path.expanduser("~%s" % os.getenv("SUDO_USER"))
32supported_prefix = "/usr/local"33supported_prefix = "/usr/local"
3334
@@ -67,17 +68,20 @@
67 '''Reset the default launcher icon and restart it.'''68 '''Reset the default launcher icon and restart it.'''
68 subprocess.Popen(["gsettings", "reset" ,"com.canonical.Unity.Launcher" , "favorites"])69 subprocess.Popen(["gsettings", "reset" ,"com.canonical.Unity.Launcher" , "favorites"])
6970
70def process_and_start_unity (verbose, debug_mode, compiz_path, compiz_args, log_file):71def is_upstart_session():
72 return 'UPSTART_SESSION' in os.environ.keys() and len(os.environ['UPSTART_SESSION'])
73
74def process_and_start_unity (compiz_args):
71 '''launch unity under compiz (replace the current shell in any case)'''75 '''launch unity under compiz (replace the current shell in any case)'''
7276
73 cli = []77 cli = []
7478
75 if debug_mode > 0:79 if options.debug_mode > 0:
76 # we can do more check later as if it's in PATH...80 # we can do more check later as if it's in PATH...
77 if not os.path.isfile('/usr/bin/gdb'):81 if not os.path.isfile('/usr/bin/gdb'):
78 print("ERROR: you don't have gdb in your system. Please install it to run in advanced debug mode.")82 print("ERROR: you don't have gdb in your system. Please install it to run in advanced debug mode.")
79 sys.exit(1)83 sys.exit(1)
80 elif debug_mode == 1:84 elif options.debug_mode == 1:
81 cli.extend(['gdb', '-ex', 'run', '-ex', '"bt full"', '--batch', '--args'])85 cli.extend(['gdb', '-ex', 'run', '-ex', '"bt full"', '--batch', '--args'])
82 elif 'DESKTOP_SESSION' in os.environ:86 elif 'DESKTOP_SESSION' in os.environ:
83 print("ERROR: it seems you are under a graphical environment. That's incompatible with executing advanced-debug option. You should be in a tty.")87 print("ERROR: it seems you are under a graphical environment. That's incompatible with executing advanced-debug option. You should be in a tty.")
@@ -88,15 +92,19 @@
88 if options.compiz_path:92 if options.compiz_path:
89 cli.extend([options.compiz_path, '--replace'])93 cli.extend([options.compiz_path, '--replace'])
90 else:94 else:
91 cli.extend(['compiz', '--replace'])95 cli.extend(DEFAULT_COMMAND.split())
9296
93 if options.verbose:97 if options.verbose:
94 cli.append("--debug")98 cli.append("--debug")
95 if args:99 if args:
96 cli.extend(compiz_args)100 cli.extend(options.compiz_args)
97101
98 if log_file:102 if options.log:
99 cli.extend(['2>&1', '|', 'tee', log_file])103 cli.extend(['2>&1', '|', 'tee', options.log])
104
105 if is_upstart_session():
106 if b'start/running' in subprocess.check_output("status unity7".split()):
107 subprocess.call("stop unity7".split())
100108
101 # kill a previous compiz if was there (this is a hack as compiz can109 # kill a previous compiz if was there (this is a hack as compiz can
102 # sometimes get stuck and not exit on --replace)110 # sometimes get stuck and not exit on --replace)
@@ -110,24 +118,29 @@
110 if re.match(rb"^compiz\b", cmdline):118 if re.match(rb"^compiz\b", cmdline):
111 compiz_env = open(os.path.join(pid_path, "environ"), "rb").read()119 compiz_env = open(os.path.join(pid_path, "environ"), "rb").read()
112 if display in compiz_env.decode(sys.getdefaultencoding()):120 if display in compiz_env.decode(sys.getdefaultencoding()):
113 subprocess.call (["kill", "-9", pid])121 subprocess.call(["kill", "-9", pid])
114 except IOError:122 except IOError:
115 continue123 continue
116124
117 # shell = True as it's the simpest way to | tee.125 run_command = " ".join(cli)
118 # In this case, we need a string and not a list126
119 # FIXME: still some bug with 2>&1 not showing everything before wait()127 if is_upstart_session() and run_command == DEFAULT_COMMAND and not options.ignore_upstart:
120 return subprocess.Popen(" ".join(cli), env=dict(os.environ), shell=True)128 return subprocess.Popen("start unity7".split())
121129 else:
122130 # shell = True as it's the simpest way to | tee.
123def run_unity (verbose, debug, advanced_debug, compiz_path, compiz_args, log_file):131 # In this case, we need a string and not a list
132 # FIXME: still some bug with 2>&1 not showing everything before wait()
133 return subprocess.Popen(" ".join(cli), env=dict(os.environ), shell=True)
134
135
136def run_unity (compiz_args):
124 '''run the unity shell and handle Ctrl + C'''137 '''run the unity shell and handle Ctrl + C'''
125138
126 try:139 try:
127 debug_mode = 2 if advanced_debug else 1 if debug else 0140 options.debug_mode = 2 if options.advanced_debug else 1 if options.debug else 0
128 subprocess.call(["stop", "unity-panel-service"])141 if is_upstart_session(): subprocess.call(["stop", "unity-panel-service"])
129 unity_instance = process_and_start_unity (verbose, debug_mode, compiz_path, compiz_args, log_file)142 unity_instance = process_and_start_unity (compiz_args)
130 subprocess.call(["start", "unity-panel-service"])143 if is_upstart_session(): subprocess.call(["start", "unity-panel-service"])
131 unity_instance.wait()144 unity_instance.wait()
132 except KeyboardInterrupt as e:145 except KeyboardInterrupt as e:
133 try:146 try:
@@ -180,6 +193,8 @@
180 help="Store log under filename.")193 help="Store log under filename.")
181 parser.add_option("--replace", action="store_true",194 parser.add_option("--replace", action="store_true",
182 help="Run unity /!\ This is for compatibility with other desktop interfaces and acts the same as running unity without --replace")195 help="Run unity /!\ This is for compatibility with other desktop interfaces and acts the same as running unity without --replace")
196 parser.add_option("--ignore-upstart", action="store_true",
197 help="Run unity without upstart support")
183 parser.add_option("--reset", action="store_true",198 parser.add_option("--reset", action="store_true",
184 help="(deprecated: provided for backwards compatibility)")199 help="(deprecated: provided for backwards compatibility)")
185 parser.add_option("--reset-icons", action="store_true",200 parser.add_option("--reset-icons", action="store_true",
@@ -202,4 +217,4 @@
202 if options.replace:217 if options.replace:
203 print ("WARNING: This is for compatibility with other desktop interfaces please use unity without --replace")218 print ("WARNING: This is for compatibility with other desktop interfaces please use unity without --replace")
204219
205 run_unity (options.verbose, options.debug, options.advanced_debug, options.compiz_path, args, options.log)220 run_unity(args)