From 6a226c34bae95f5c896c1e7d6de4205d4abd4c4b Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sat, 25 Nov 2017 11:55:21 +0000 Subject: [PATCH] * fix py3k strings.. * catch signals in mdns / sessions gui and return a non-zero exit_code git-svn-id: https://xpra.org/svn/Xpra/trunk@17498 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/client/gtk_base/mdns_gui.py | 10 +++++++--- src/xpra/client/gtk_base/sessions_gui.py | 20 ++++++++++++++++---- src/xpra/scripts/main.py | 6 +++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/xpra/client/gtk_base/mdns_gui.py b/src/xpra/client/gtk_base/mdns_gui.py index 8d4e7657e3..0598bdfa8c 100644 --- a/src/xpra/client/gtk_base/mdns_gui.py +++ b/src/xpra/client/gtk_base/mdns_gui.py @@ -4,6 +4,8 @@ # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. +import sys + from xpra.gtk_common.gobject_compat import import_gtk, import_glib gtk = import_gtk() glib = import_glib() @@ -57,14 +59,16 @@ def do_main(opts): if not get_listener_class(): command_error("no mDNS support in this build") return 1 - mdns_sessions(opts) + gui = mdns_sessions(opts) gtk_main() + return gui.exit_code def main(): from xpra.scripts.config import make_defaults_struct opts = make_defaults_struct() - do_main(opts) + return do_main(opts) if __name__ == "__main__": - main() + r = main() + sys.exit(r) diff --git a/src/xpra/client/gtk_base/sessions_gui.py b/src/xpra/client/gtk_base/sessions_gui.py index 441e286884..44d4f1c29d 100644 --- a/src/xpra/client/gtk_base/sessions_gui.py +++ b/src/xpra/client/gtk_base/sessions_gui.py @@ -32,6 +32,7 @@ class SessionsGUI(gtk.Window): def __init__(self, options, title="Xpra Session Browser"): gtk.Window.__init__(self) + self.exit_code = 0 self.set_title(title) self.set_border_width(20) self.set_resizable(True) @@ -83,6 +84,9 @@ def __init__(self, options, title="Xpra Session Browser"): glib.timeout_add(5*1000, self.poll_local_sessions) self.populate_table() + import signal + signal.signal(signal.SIGINT, self.app_signal) + signal.signal(signal.SIGTERM, self.app_signal) self.show_all() def quit(self, *args): @@ -93,6 +97,11 @@ def do_quit(self): log("do_quit()") gtk.main_quit() + def app_signal(self, signum, _frame): + self.exit_code = 128 + signum + log("app_signal(%s, %s) exit_code=%i", signum, _frame, self.exit_code) + self.do_quit() + def poll_local_sessions(self): #TODO: run in a thread so we don't block the UI thread! @@ -155,7 +164,7 @@ def get_session_info(self, sockpath): out = strtobytes(stdout) info = {} for line in out.splitlines(): - parts = line.split("=", 1) + parts = line.split(b"=", 1) if len(parts)==2: info[parts[0]] = parts[1] return info @@ -316,14 +325,17 @@ def do_main(opts): from xpra.log import enable_color with program_context("Xpra-Session-Browser", "Xpra Session Browser"): enable_color() - SessionsGUI(opts) + gui = SessionsGUI(opts) gtk_main() + log.info("do_main() gui.exit_code=%i", gui.exit_code) + return gui.exit_code def main(): from xpra.scripts.config import make_defaults_struct opts = make_defaults_struct() - do_main(opts) + return do_main(opts) if __name__ == "__main__": - main() + r = main() + sys.exit(r) diff --git a/src/xpra/scripts/main.py b/src/xpra/scripts/main.py index fa9aaf7b4a..780ac83617 100755 --- a/src/xpra/scripts/main.py +++ b/src/xpra/scripts/main.py @@ -1580,7 +1580,7 @@ def parse_display_name(error_cb, opts, display_name): pos +=1 if protocol=="socket": #socket paths may start with a slash! - #in which case the slash is part of the path, not the seperator! + #in which case the last slash is part of the path, not the seperator! if psep==":/" or psep==":///": psep = psep[:-1] pos -= 1 @@ -3040,7 +3040,7 @@ def run_sessions_gui(error_cb, options): if mdns: return run_mdns_gui(error_cb, options) from xpra.client.gtk_base import sessions_gui - sessions_gui.do_main(options) + return sessions_gui.do_main(options) def run_mdns_gui(error_cb, options): from xpra.net.mdns import get_listener_class @@ -3048,7 +3048,7 @@ def run_mdns_gui(error_cb, options): if not listener: error_cb("sorry, 'mdns-gui' is not supported on this platform yet") from xpra.client.gtk_base import mdns_gui - mdns_gui.do_main(options) + return mdns_gui.do_main(options) def run_list_mdns(error_cb, extra_args): no_gtk()