Move shell-running machinery to a function
Move the code that starts gnome-shell and waits for it to exit to a function in preparation for running it multiple times when doing iterations of a performance test. https://bugzilla.gnome.org/show_bug.cgi?id=618189
This commit is contained in:
parent
08b8b39a5d
commit
5d0536d732
@ -1,4 +1,5 @@
|
|||||||
#!@PYTHON@
|
#!@PYTHON@
|
||||||
|
# -*- mode: Python; indent-tabs-mode: nil; -*-
|
||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
import optparse
|
import optparse
|
||||||
@ -213,6 +214,68 @@ def start_shell():
|
|||||||
args.append('--sync')
|
args.append('--sync')
|
||||||
return subprocess.Popen(args, env=env)
|
return subprocess.Popen(args, env=env)
|
||||||
|
|
||||||
|
def run_shell():
|
||||||
|
if options.debug:
|
||||||
|
# Record initial terminal state so we can reset it to that
|
||||||
|
# later, in case we kill gdb at a bad time
|
||||||
|
termattrs = termios.tcgetattr(0);
|
||||||
|
|
||||||
|
normal_exit = False
|
||||||
|
|
||||||
|
if options.verbose:
|
||||||
|
print "Starting shell"
|
||||||
|
|
||||||
|
try:
|
||||||
|
shell = None
|
||||||
|
if options.xephyr:
|
||||||
|
xephyr = start_xephyr()
|
||||||
|
# This makes us not grab the org.gnome.Panel or
|
||||||
|
# org.freedesktop.Notifications D-Bus names
|
||||||
|
os.environ['GNOME_SHELL_NO_REPLACE'] = '1'
|
||||||
|
shell = start_shell()
|
||||||
|
else:
|
||||||
|
xephyr = None
|
||||||
|
shell = start_shell()
|
||||||
|
|
||||||
|
# Wait for shell to exit
|
||||||
|
if options.verbose:
|
||||||
|
print "Waiting for shell to exit"
|
||||||
|
shell.wait()
|
||||||
|
|
||||||
|
except KeyboardInterrupt, e:
|
||||||
|
try:
|
||||||
|
os.kill(shell.pid, signal.SIGKILL)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
shell.wait()
|
||||||
|
finally:
|
||||||
|
# Clean up Xephyr if it outlived the shell
|
||||||
|
if xephyr:
|
||||||
|
try:
|
||||||
|
os.kill(xephyr.pid, signal.SIGKILL)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if shell is None:
|
||||||
|
print "Failed to start shell"
|
||||||
|
elif shell.returncode == 0:
|
||||||
|
normal_exit = True
|
||||||
|
if options.verbose:
|
||||||
|
print "Shell exited normally"
|
||||||
|
elif shell.returncode < 0:
|
||||||
|
# Python has no mapping for strsignal; not worth using
|
||||||
|
# ctypes for this.
|
||||||
|
print "Shell killed with signal %d" % - shell.returncode
|
||||||
|
else:
|
||||||
|
# Normal reason here would be losing connection the X server
|
||||||
|
if options.verbose:
|
||||||
|
print "Shell exited with return code %d" % shell.returncode
|
||||||
|
|
||||||
|
if options.debug:
|
||||||
|
termios.tcsetattr(0, termios.TCSANOW, termattrs);
|
||||||
|
|
||||||
|
return normal_exit
|
||||||
|
|
||||||
def restore_gnome():
|
def restore_gnome():
|
||||||
# Do imports lazily to save time and memory
|
# Do imports lazily to save time and memory
|
||||||
import gio
|
import gio
|
||||||
@ -405,69 +468,13 @@ else:
|
|||||||
# tfp does not work correctly in Xephyr
|
# tfp does not work correctly in Xephyr
|
||||||
use_tfp = not options.xephyr
|
use_tfp = not options.xephyr
|
||||||
|
|
||||||
if options.verbose:
|
|
||||||
print "Starting shell"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if options.debug:
|
|
||||||
# Record initial terminal state so we can reset it to that
|
|
||||||
# later, in case we kill gdb at a bad time
|
|
||||||
termattrs = termios.tcgetattr(0);
|
|
||||||
|
|
||||||
# We only respawn the previous environment on abnormal exit;
|
# We only respawn the previous environment on abnormal exit;
|
||||||
# for a clean exit, we assume that gnome-shell was replaced with
|
# for a clean exit, we assume that gnome-shell was replaced with
|
||||||
# something else.
|
# something else.
|
||||||
normal_exit = False
|
normal_exit = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
shell = None
|
normal_exit = run_shell()
|
||||||
if options.xephyr:
|
|
||||||
xephyr = start_xephyr()
|
|
||||||
# This makes us not grab the org.gnome.Panel or
|
|
||||||
# org.freedesktop.Notifications D-Bus names
|
|
||||||
os.environ['GNOME_SHELL_NO_REPLACE'] = '1'
|
|
||||||
shell = start_shell()
|
|
||||||
else:
|
|
||||||
xephyr = None
|
|
||||||
shell = start_shell()
|
|
||||||
|
|
||||||
# Wait for shell to exit
|
|
||||||
if options.verbose:
|
|
||||||
print "Waiting for shell to exit"
|
|
||||||
shell.wait()
|
|
||||||
|
|
||||||
except KeyboardInterrupt, e:
|
|
||||||
try:
|
|
||||||
os.kill(shell.pid, signal.SIGKILL)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
shell.wait()
|
|
||||||
finally:
|
finally:
|
||||||
# Clean up Xephyr if it outlived the shell
|
|
||||||
if xephyr:
|
|
||||||
try:
|
|
||||||
os.kill(xephyr.pid, signal.SIGKILL)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if shell is None:
|
|
||||||
print "Failed to start shell"
|
|
||||||
elif shell.returncode == 0:
|
|
||||||
normal_exit = True
|
|
||||||
if options.verbose:
|
|
||||||
print "Shell exited normally"
|
|
||||||
elif shell.returncode < 0:
|
|
||||||
# Python has no mapping for strsignal; not worth using
|
|
||||||
# ctypes for this.
|
|
||||||
print "Shell killed with signal %d" % - shell.returncode
|
|
||||||
else:
|
|
||||||
# Normal reason here would be losing connection the X server
|
|
||||||
if options.verbose:
|
|
||||||
print "Shell exited with return code %d" % shell.returncode
|
|
||||||
|
|
||||||
if options.debug:
|
|
||||||
termios.tcsetattr(0, termios.TCSANOW, termattrs);
|
|
||||||
|
|
||||||
if not options.xephyr and options.replace and not normal_exit:
|
if not options.xephyr and options.replace and not normal_exit:
|
||||||
restore_gnome()
|
restore_gnome()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user