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
1=== modified file 'tools/unity.cmake'
2--- tools/unity.cmake 2015-12-17 23:30:10 +0000
3+++ tools/unity.cmake 2016-03-30 02:47:25 +0000
4@@ -28,6 +28,7 @@
5 import sys
6 import time
7
8+DEFAULT_COMMAND = "compiz --replace"
9 home_dir = os.path.expanduser("~%s" % os.getenv("SUDO_USER"))
10 supported_prefix = "/usr/local"
11
12@@ -67,17 +68,20 @@
13 '''Reset the default launcher icon and restart it.'''
14 subprocess.Popen(["gsettings", "reset" ,"com.canonical.Unity.Launcher" , "favorites"])
15
16-def process_and_start_unity (verbose, debug_mode, compiz_path, compiz_args, log_file):
17+def is_upstart_session():
18+ return 'UPSTART_SESSION' in os.environ.keys() and len(os.environ['UPSTART_SESSION'])
19+
20+def process_and_start_unity (compiz_args):
21 '''launch unity under compiz (replace the current shell in any case)'''
22
23 cli = []
24
25- if debug_mode > 0:
26+ if options.debug_mode > 0:
27 # we can do more check later as if it's in PATH...
28 if not os.path.isfile('/usr/bin/gdb'):
29 print("ERROR: you don't have gdb in your system. Please install it to run in advanced debug mode.")
30 sys.exit(1)
31- elif debug_mode == 1:
32+ elif options.debug_mode == 1:
33 cli.extend(['gdb', '-ex', 'run', '-ex', '"bt full"', '--batch', '--args'])
34 elif 'DESKTOP_SESSION' in os.environ:
35 print("ERROR: it seems you are under a graphical environment. That's incompatible with executing advanced-debug option. You should be in a tty.")
36@@ -88,15 +92,19 @@
37 if options.compiz_path:
38 cli.extend([options.compiz_path, '--replace'])
39 else:
40- cli.extend(['compiz', '--replace'])
41+ cli.extend(DEFAULT_COMMAND.split())
42
43 if options.verbose:
44 cli.append("--debug")
45 if args:
46- cli.extend(compiz_args)
47-
48- if log_file:
49- cli.extend(['2>&1', '|', 'tee', log_file])
50+ cli.extend(options.compiz_args)
51+
52+ if options.log:
53+ cli.extend(['2>&1', '|', 'tee', options.log])
54+
55+ if is_upstart_session():
56+ if b'start/running' in subprocess.check_output("status unity7".split()):
57+ subprocess.call("stop unity7".split())
58
59 # kill a previous compiz if was there (this is a hack as compiz can
60 # sometimes get stuck and not exit on --replace)
61@@ -110,24 +118,29 @@
62 if re.match(rb"^compiz\b", cmdline):
63 compiz_env = open(os.path.join(pid_path, "environ"), "rb").read()
64 if display in compiz_env.decode(sys.getdefaultencoding()):
65- subprocess.call (["kill", "-9", pid])
66+ subprocess.call(["kill", "-9", pid])
67 except IOError:
68 continue
69
70- # shell = True as it's the simpest way to | tee.
71- # In this case, we need a string and not a list
72- # FIXME: still some bug with 2>&1 not showing everything before wait()
73- return subprocess.Popen(" ".join(cli), env=dict(os.environ), shell=True)
74-
75-
76-def run_unity (verbose, debug, advanced_debug, compiz_path, compiz_args, log_file):
77+ run_command = " ".join(cli)
78+
79+ if is_upstart_session() and run_command == DEFAULT_COMMAND and not options.ignore_upstart:
80+ return subprocess.Popen("start unity7".split())
81+ else:
82+ # shell = True as it's the simpest way to | tee.
83+ # In this case, we need a string and not a list
84+ # FIXME: still some bug with 2>&1 not showing everything before wait()
85+ return subprocess.Popen(" ".join(cli), env=dict(os.environ), shell=True)
86+
87+
88+def run_unity (compiz_args):
89 '''run the unity shell and handle Ctrl + C'''
90
91 try:
92- debug_mode = 2 if advanced_debug else 1 if debug else 0
93- subprocess.call(["stop", "unity-panel-service"])
94- unity_instance = process_and_start_unity (verbose, debug_mode, compiz_path, compiz_args, log_file)
95- subprocess.call(["start", "unity-panel-service"])
96+ options.debug_mode = 2 if options.advanced_debug else 1 if options.debug else 0
97+ if is_upstart_session(): subprocess.call(["stop", "unity-panel-service"])
98+ unity_instance = process_and_start_unity (compiz_args)
99+ if is_upstart_session(): subprocess.call(["start", "unity-panel-service"])
100 unity_instance.wait()
101 except KeyboardInterrupt as e:
102 try:
103@@ -180,6 +193,8 @@
104 help="Store log under filename.")
105 parser.add_option("--replace", action="store_true",
106 help="Run unity /!\ This is for compatibility with other desktop interfaces and acts the same as running unity without --replace")
107+ parser.add_option("--ignore-upstart", action="store_true",
108+ help="Run unity without upstart support")
109 parser.add_option("--reset", action="store_true",
110 help="(deprecated: provided for backwards compatibility)")
111 parser.add_option("--reset-icons", action="store_true",
112@@ -202,4 +217,4 @@
113 if options.replace:
114 print ("WARNING: This is for compatibility with other desktop interfaces please use unity without --replace")
115
116- run_unity (options.verbose, options.debug, options.advanced_debug, options.compiz_path, args, options.log)
117+ run_unity(args)