From 397d32362d4bf36165aae93e538907e741698afa Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 1 Mar 2018 08:22:13 +0000 Subject: [PATCH] #1761 try to make more imports optional: only attempt to load stuff if we're going to use it git-svn-id: https://xpra.org/svn/Xpra/trunk@18654 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/client/mixins/audio.py | 37 ++++++++++++++-------- src/xpra/client/mixins/clipboard.py | 15 ++++++--- src/xpra/client/mixins/notifications.py | 10 ++++-- src/xpra/client/mixins/tray.py | 2 +- src/xpra/client/mixins/window_manager.py | 13 ++++++-- src/xpra/codecs/video_helper.py | 5 +-- src/xpra/platform/darwin/features.py | 3 +- src/xpra/platform/features.py | 4 +-- src/xpra/platform/win32/features.py | 2 -- src/xpra/server/mixins/clipboard_server.py | 3 +- 10 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/xpra/client/mixins/audio.py b/src/xpra/client/mixins/audio.py index e20c5e2056..d422017486 100644 --- a/src/xpra/client/mixins/audio.py +++ b/src/xpra/client/mixins/audio.py @@ -70,22 +70,31 @@ def sound_option_or_all(*_args): return [] if self.speaker_allowed or self.microphone_allowed: try: - from xpra.sound.common import sound_option_or_all - from xpra.sound.wrapper import query_sound - self.sound_properties = query_sound() - assert self.sound_properties, "query did not return any data" - def vinfo(k): - val = self.sound_properties.strlistget(k) - assert val, "%s not found in sound properties" % k - return ".".join(val[:3]) - bits = self.sound_properties.intget("python.bits", 32) - log.info("GStreamer version %s for Python %s %s-bit", vinfo("gst.version"), vinfo("python.version"), bits) - except Exception as e: - log("failed to query sound", exc_info=True) - log.error("Error: failed to query sound subsystem:") - log.error(" %s", e) + from xpra import sound + assert sound + except ImportError as e: + log.warn("Warning: sound module is not installed") + log.warn(" speaker and microphone are disabled") self.speaker_allowed = False self.microphone_allowed = False + else: + try: + from xpra.sound.common import sound_option_or_all + from xpra.sound.wrapper import query_sound + self.sound_properties = query_sound() + assert self.sound_properties, "query did not return any data" + def vinfo(k): + val = self.sound_properties.strlistget(k) + assert val, "%s not found in sound properties" % k + return ".".join(val[:3]) + bits = self.sound_properties.intget("python.bits", 32) + log.info("GStreamer version %s for Python %s %s-bit", vinfo("gst.version"), vinfo("python.version"), bits) + except Exception as e: + log("failed to query sound", exc_info=True) + log.error("Error: failed to query sound subsystem:") + log.error(" %s", e) + self.speaker_allowed = False + self.microphone_allowed = False encoders = self.sound_properties.strlistget("encoders", []) decoders = self.sound_properties.strlistget("decoders", []) self.speaker_codecs = sound_option_or_all("speaker-codec", opts.speaker_codec, decoders) diff --git a/src/xpra/client/mixins/clipboard.py b/src/xpra/client/mixins/clipboard.py index 160735022a..2a001e469f 100644 --- a/src/xpra/client/mixins/clipboard.py +++ b/src/xpra/client/mixins/clipboard.py @@ -13,10 +13,6 @@ from xpra.scripts.config import FALSE_OPTIONS from xpra.util import flatten_dict from xpra.os_util import bytestostr -try: - from xpra.clipboard.clipboard_base import ALL_CLIPBOARDS -except: - ALL_CLIPBOARDS = [] """ @@ -72,6 +68,13 @@ def get_caps(self): return caps def parse_server_capabilities(self): + try: + from xpra import clipboard + assert clipboard + except ImportError: + log.warn("Warning: clipboard module is missing") + self.clipboard_enabled = False + return c = self.server_capabilities self.server_clipboard = c.boolget("clipboard") self.server_clipboard_loop_uuids = c.dictget("clipboard.loop-uuids") @@ -89,6 +92,10 @@ def parse_server_capabilities(self): log.warn("Warning: incompatible clipboard direction settings") log.warn(" server setting: %s, client setting: %s", self.server_clipboard_direction, self.client_clipboard_direction) self.server_clipboard_enable_selections = c.boolget("clipboard.enable-selections") + try: + from xpra.clipboard.clipboard_base import ALL_CLIPBOARDS + except: + ALL_CLIPBOARDS = [] self.server_clipboards = c.strlistget("clipboards", ALL_CLIPBOARDS) log("server clipboard: supported=%s, direction=%s, supports enable selection=%s", self.server_clipboard, self.server_clipboard_direction, self.server_clipboard_enable_selections) diff --git a/src/xpra/client/mixins/notifications.py b/src/xpra/client/mixins/notifications.py index ba19688b87..74d30606e9 100644 --- a/src/xpra/client/mixins/notifications.py +++ b/src/xpra/client/mixins/notifications.py @@ -30,8 +30,14 @@ def __init__(self): self.tray = None def init(self, opts): - """ initialize variables from configuration """ - self.client_supports_notifications = opts.notifications + if opts.notifications: + try: + from xpra import notifications + assert notifications + except ImportError: + log.warn("Warning: notifications module not found") + else: + self.client_supports_notifications = True def init_ui(self): log("client_supports_notifications=%s", self.client_supports_notifications) diff --git a/src/xpra/client/mixins/tray.py b/src/xpra/client/mixins/tray.py index bd08d99821..4a21844473 100644 --- a/src/xpra/client/mixins/tray.py +++ b/src/xpra/client/mixins/tray.py @@ -6,7 +6,7 @@ from xpra.log import Logger log = Logger("tray") -from xpra.platform.gui import (get_native_tray_classes, get_native_tray_menu_helper_class) +from xpra.platform.gui import get_native_tray_classes, get_native_tray_menu_helper_class from xpra.os_util import bytestostr, strtobytes from xpra.util import nonl, envint, make_instance, CLIENT_EXIT, XPRA_APP_ID from xpra.client.mixins.stub_client_mixin import StubClientMixin diff --git a/src/xpra/client/mixins/window_manager.py b/src/xpra/client/mixins/window_manager.py index 36e75e2df9..c07f28c2bc 100644 --- a/src/xpra/client/mixins/window_manager.py +++ b/src/xpra/client/mixins/window_manager.py @@ -34,7 +34,6 @@ from xpra.make_thread import make_thread from xpra.os_util import BytesIOClass, Queue, bytestostr, monotonic_time, memoryview_to_bytes, OSX, POSIX, is_Ubuntu from xpra.util import iround, envint, envbool, typedict, make_instance, updict -from xpra.client.client_tray import ClientTray from xpra.client.mixins.stub_client_mixin import StubClientMixin @@ -123,7 +122,14 @@ def __init__(self): self._on_handshake = [] def init(self, opts): - self.client_supports_system_tray = opts.system_tray and SYSTEM_TRAY_SUPPORTED + if opts.system_tray and SYSTEM_TRAY_SUPPORTED: + try: + from xpra.client import client_tray + assert client_tray + except ImportError: + log.warn("Warning: the tray forwarding module is missing") + else: + self.client_supports_system_tray = True self.client_supports_cursors = opts.cursors self.client_supports_bell = opts.bell self.input_devices = opts.input_devices @@ -416,7 +422,7 @@ def cook_metadata(self, _new_window, metadata): ###################################################################### # system tray def _process_new_tray(self, packet): - assert SYSTEM_TRAY_SUPPORTED + assert self.client_supports_system_tray self._ui_event() wid, w, h = packet[1:4] w = max(1, self.sx(w)) @@ -492,6 +498,7 @@ def tray_exit(*args): traylog("setup_system_tray%s tray_widget=%s", (client, app_id, wid, w, h, title), tray_widget) assert tray_widget, "could not instantiate a system tray for tray id %s" % wid tray_widget.show() + from xpra.client.client_tray import ClientTray return ClientTray(client, wid, w, h, metadata, tray_widget, self.mmap_enabled, self.mmap) diff --git a/src/xpra/codecs/video_helper.py b/src/xpra/codecs/video_helper.py index 3d53c6f178..c10206ed71 100755 --- a/src/xpra/codecs/video_helper.py +++ b/src/xpra/codecs/video_helper.py @@ -426,13 +426,14 @@ def get_server_full_csc_modes_for_rgb(self, *target_rgb_modes): return self.get_server_full_csc_modes(*supported_csc_modes) -instance = VideoHelper() +instance = None def getVideoHelper(): global instance + if instance is None: + instance = VideoHelper() return instance - def main(): from xpra.codecs.loader import log as loader_log, load_codecs from xpra.util import print_nested_dict diff --git a/src/xpra/platform/darwin/features.py b/src/xpra/platform/darwin/features.py index c7513aa24d..60dde05e68 100644 --- a/src/xpra/platform/darwin/features.py +++ b/src/xpra/platform/darwin/features.py @@ -1,9 +1,8 @@ # This file is part of Xpra. -# Copyright (C) 2011-2017 Antoine Martin +# Copyright (C) 2011-2018 Antoine Martin # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. -SYSTEM_TRAY_SUPPORTED = True REINIT_WINDOWS = True # we access the GUI when running as a server (tray, etc) diff --git a/src/xpra/platform/features.py b/src/xpra/platform/features.py index 81356180b7..9336bbcb6e 100644 --- a/src/xpra/platform/features.py +++ b/src/xpra/platform/features.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # This file is part of Xpra. # Copyright (C) 2010 Nathaniel Smith -# Copyright (C) 2011-2017 Antoine Martin +# Copyright (C) 2011-2018 Antoine Martin # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. @@ -15,7 +15,7 @@ SHADOW_SUPPORTED = True CAN_DAEMONIZE = True MMAP_SUPPORTED = True -SYSTEM_TRAY_SUPPORTED = False +SYSTEM_TRAY_SUPPORTED = True REINIT_WINDOWS = False INPUT_DEVICES = ["auto"] diff --git a/src/xpra/platform/win32/features.py b/src/xpra/platform/win32/features.py index b17b18ff3e..2e1c17a7bd 100644 --- a/src/xpra/platform/win32/features.py +++ b/src/xpra/platform/win32/features.py @@ -6,8 +6,6 @@ # Platform-specific settings for Win32. CAN_DAEMONIZE = False -MMAP_SUPPORTED = True -SYSTEM_TRAY_SUPPORTED = True REINIT_WINDOWS = True CLIPBOARDS=["CLIPBOARD"] diff --git a/src/xpra/server/mixins/clipboard_server.py b/src/xpra/server/mixins/clipboard_server.py index bf560203fe..fadcdfe0bb 100644 --- a/src/xpra/server/mixins/clipboard_server.py +++ b/src/xpra/server/mixins/clipboard_server.py @@ -23,7 +23,7 @@ class ClipboardServer(StubServerMixin): def __init__(self): self.clipboard = False - self.clipboard_direction = "both" + self.clipboard_direction = "none" self.clipboard_filter_file = None def init(self, opts): @@ -103,6 +103,7 @@ def init_clipboard(self): except Exception: #log("gdk clipboard helper failure", exc_info=True) log.error("Error: failed to setup clipboard helper", exc_info=True) + self.clipboard = False def parse_hello_ui_clipboard(self, ss, c): #take the clipboard if no-one else has it yet: