2008-11-01 15:45:00 -04:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2008-11-01 19:55:49 -04:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import signal
|
2008-11-01 15:45:00 -04:00
|
|
|
|
2008-11-01 19:55:49 -04:00
|
|
|
from launcher import Launcher
|
|
|
|
|
|
|
|
launcher = Launcher()
|
2008-11-01 15:45:00 -04:00
|
|
|
|
2008-11-04 17:40:52 -05:00
|
|
|
def find_cmd (cmd_list):
|
|
|
|
"""
|
|
|
|
Takes a list of command candidates and returns the first one that exists.
|
|
|
|
Raises a system exit if none of the commands exist.
|
|
|
|
"""
|
|
|
|
for cmd in cmd_list:
|
|
|
|
if os.path.exists(cmd):
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
raise SystemExit("None of the commands %s exist" % cmd_list)
|
|
|
|
|
2008-11-01 15:45:00 -04:00
|
|
|
try:
|
|
|
|
# Kill gnome-panel in a way that it won't autorespawn
|
2008-11-04 17:40:52 -05:00
|
|
|
pidof_cmd = find_cmd(["/sbin/pidof", "/bin/pidof", "/usr/bin/pidof"])
|
|
|
|
|
|
|
|
pidof = subprocess.Popen([pidof_cmd, "gnome-panel"], stdout=subprocess.PIPE)
|
2008-11-01 15:45:00 -04:00
|
|
|
pids = pidof.communicate()[0].split()
|
|
|
|
pidof.wait()
|
|
|
|
devnull = open("/dev/null", "w")
|
|
|
|
for pid in pids:
|
2008-11-04 17:40:52 -05:00
|
|
|
if launcher.is_verbose():
|
|
|
|
print "Terminating panel process %s" % pid
|
2008-11-01 15:45:00 -04:00
|
|
|
subprocess.call(["gdb", "-batch-silent",
|
|
|
|
"-ex", "call panel_session_do_not_restart()",
|
2008-11-02 00:18:36 -04:00
|
|
|
"-ex", "call exit(0)",
|
2008-11-01 15:45:00 -04:00
|
|
|
"-p", pid], stdout=devnull, stderr=devnull)
|
|
|
|
devnull.close()
|
2008-11-04 17:40:52 -05:00
|
|
|
|
|
|
|
if launcher.is_verbose():
|
|
|
|
print "Starting shell"
|
2008-11-01 19:55:49 -04:00
|
|
|
shell = launcher.start_shell()
|
2008-11-01 15:45:00 -04:00
|
|
|
|
2008-11-01 19:55:49 -04:00
|
|
|
# Wait for shell to exit
|
2008-11-01 15:45:00 -04:00
|
|
|
try:
|
2008-11-04 17:40:52 -05:00
|
|
|
if launcher.is_verbose():
|
|
|
|
print "Waiting for shell to exit"
|
2008-11-01 19:55:49 -04:00
|
|
|
shell.wait()
|
2008-11-04 17:40:52 -05:00
|
|
|
if launcher.is_verbose():
|
|
|
|
print "Shell is dead"
|
2008-11-01 15:45:00 -04:00
|
|
|
except KeyboardInterrupt, e:
|
2008-11-01 19:55:49 -04:00
|
|
|
os.kill(shell.pid, signal.SIGKILL)
|
|
|
|
shell.wait()
|
2008-11-04 17:40:52 -05:00
|
|
|
if launcher.is_verbose():
|
|
|
|
print "Shell killed"
|
2008-11-01 15:45:00 -04:00
|
|
|
finally:
|
|
|
|
# Restart gnome-panel and window manager
|
2008-11-04 17:40:52 -05:00
|
|
|
if launcher.is_verbose():
|
|
|
|
print "Restarting Metacity and Gnome Panel"
|
|
|
|
|
2008-11-01 15:45:00 -04:00
|
|
|
subprocess.Popen(["/usr/bin/metacity"])
|
|
|
|
subprocess.Popen(["/usr/bin/gnome-panel"])
|