Autodetect where the 'pidof' command lives and enable optional verbose logging inside start-replace
scripts/start-replace: Detect if 'pidof' lives in /sbin, /bin, or /usr/bin. Add conditional verbose logging if -v is passed on the command line scripts/launcher.py: Add method is_verbose() to Launcher class svn path=/trunk/; revision=31
This commit is contained in:
parent
e86920147b
commit
0f966eabbf
@ -79,6 +79,9 @@ class Launcher:
|
|||||||
args.extend(['metacity', '--mutter-plugins=' + plugin, '--replace'])
|
args.extend(['metacity', '--mutter-plugins=' + plugin, '--replace'])
|
||||||
return subprocess.Popen(args, env=env)
|
return subprocess.Popen(args, env=env)
|
||||||
|
|
||||||
|
def is_verbose (self):
|
||||||
|
"""Returns whether the Launcher was started in verbose mode"""
|
||||||
|
return self.options.verbose
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,29 +8,54 @@ from launcher import Launcher
|
|||||||
|
|
||||||
launcher = Launcher()
|
launcher = Launcher()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Kill gnome-panel in a way that it won't autorespawn
|
# Kill gnome-panel in a way that it won't autorespawn
|
||||||
pidof = subprocess.Popen(["/sbin/pidof", "gnome-panel"], stdout=subprocess.PIPE)
|
pidof_cmd = find_cmd(["/sbin/pidof", "/bin/pidof", "/usr/bin/pidof"])
|
||||||
|
|
||||||
|
pidof = subprocess.Popen([pidof_cmd, "gnome-panel"], stdout=subprocess.PIPE)
|
||||||
pids = pidof.communicate()[0].split()
|
pids = pidof.communicate()[0].split()
|
||||||
pidof.wait()
|
pidof.wait()
|
||||||
devnull = open("/dev/null", "w")
|
devnull = open("/dev/null", "w")
|
||||||
for pid in pids:
|
for pid in pids:
|
||||||
|
if launcher.is_verbose():
|
||||||
|
print "Terminating panel process %s" % pid
|
||||||
subprocess.call(["gdb", "-batch-silent",
|
subprocess.call(["gdb", "-batch-silent",
|
||||||
"-ex", "call panel_session_do_not_restart()",
|
"-ex", "call panel_session_do_not_restart()",
|
||||||
"-ex", "call exit(0)",
|
"-ex", "call exit(0)",
|
||||||
"-p", pid], stdout=devnull, stderr=devnull)
|
"-p", pid], stdout=devnull, stderr=devnull)
|
||||||
devnull.close()
|
devnull.close()
|
||||||
|
|
||||||
|
if launcher.is_verbose():
|
||||||
|
print "Starting shell"
|
||||||
shell = launcher.start_shell()
|
shell = launcher.start_shell()
|
||||||
|
|
||||||
# Wait for shell to exit
|
# Wait for shell to exit
|
||||||
try:
|
try:
|
||||||
|
if launcher.is_verbose():
|
||||||
|
print "Waiting for shell to exit"
|
||||||
shell.wait()
|
shell.wait()
|
||||||
|
if launcher.is_verbose():
|
||||||
|
print "Shell is dead"
|
||||||
except KeyboardInterrupt, e:
|
except KeyboardInterrupt, e:
|
||||||
os.kill(shell.pid, signal.SIGKILL)
|
os.kill(shell.pid, signal.SIGKILL)
|
||||||
shell.wait()
|
shell.wait()
|
||||||
|
if launcher.is_verbose():
|
||||||
|
print "Shell killed"
|
||||||
finally:
|
finally:
|
||||||
# Restart gnome-panel and window manager
|
# Restart gnome-panel and window manager
|
||||||
|
if launcher.is_verbose():
|
||||||
|
print "Restarting Metacity and Gnome Panel"
|
||||||
|
|
||||||
subprocess.Popen(["/usr/bin/metacity"])
|
subprocess.Popen(["/usr/bin/metacity"])
|
||||||
subprocess.Popen(["/usr/bin/gnome-panel"])
|
subprocess.Popen(["/usr/bin/gnome-panel"])
|
||||||
|
Loading…
Reference in New Issue
Block a user