Skip to content

Commit

Permalink
#1761 try to make more imports optional: only attempt to load stuff i…
Browse files Browse the repository at this point in the history
…f we're going to use it

git-svn-id: https://xpra.org/svn/Xpra/trunk@18654 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Mar 1, 2018
1 parent 3a2e311 commit 397d323
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 33 deletions.
37 changes: 23 additions & 14 deletions src/xpra/client/mixins/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions src/xpra/client/mixins/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []


"""
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions src/xpra/client/mixins/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/xpra/client/mixins/window_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)


Expand Down
5 changes: 3 additions & 2 deletions src/xpra/codecs/video_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/xpra/platform/darwin/features.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# This file is part of Xpra.
# Copyright (C) 2011-2017 Antoine Martin <[email protected]>
# Copyright (C) 2011-2018 Antoine Martin <[email protected]>
# 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)
Expand Down
4 changes: 2 additions & 2 deletions src/xpra/platform/features.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# This file is part of Xpra.
# Copyright (C) 2010 Nathaniel Smith <[email protected]>
# Copyright (C) 2011-2017 Antoine Martin <[email protected]>
# Copyright (C) 2011-2018 Antoine Martin <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

Expand All @@ -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"]
Expand Down
2 changes: 0 additions & 2 deletions src/xpra/platform/win32/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

# Platform-specific settings for Win32.
CAN_DAEMONIZE = False
MMAP_SUPPORTED = True
SYSTEM_TRAY_SUPPORTED = True
REINIT_WINDOWS = True

CLIPBOARDS=["CLIPBOARD"]
Expand Down
3 changes: 2 additions & 1 deletion src/xpra/server/mixins/clipboard_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 397d323

Please sign in to comment.