def import_gst(): global gst if gst is not None: return gst #hacks to locate gstreamer plugins on win32 and osx: if WIN32: frozen = hasattr(sys, "frozen") and sys.frozen in ("windows_exe", "console_exe", True) log("gstreamer_util: frozen=%s", frozen) if frozen: #on win32, we keep separate trees #because GStreamer 0.10 and 1.x were built using different and / or incompatible version of the same libraries: from xpra.platform.paths import get_app_dir gi_dir = os.path.join(get_app_dir(), "lib", "girepository-1.0") gst_dir = os.path.join(get_app_dir(), "lib", "gstreamer-1.0") #ie: C:\Program Files\Xpra\lib\gstreamer-1.0 gst_bin_dir = os.path.join(get_app_dir(), "bin") #ie: C:\Program Files\Xpra\bin if not os.path.exists(gst_dir): #fallback to old build locations: gi_dir = os.path.join(get_app_dir(), "girepository-1.0") gst_dir = os.path.join(get_app_dir(), "gstreamer-1.0") gst_bin_dir = os.path.join(gst_dir, "bin") #ie: C:\Program Files\Xpra\gstreamer-0.10\bin os.environ["GI_TYPELIB_PATH"] = gi_dir os.environ["GST_PLUGIN_PATH"] = gst_dir os.environ["PATH"] = os.pathsep.join(x for x in (gst_bin_dir, os.environ.get("PATH", "")) if x) sys.path.insert(0, gst_bin_dir) scanner = os.path.join(gst_bin_dir, "gst-plugin-scanner.exe") if os.path.exists(scanner): os.environ["GST_PLUGIN_SCANNER"] = scanner elif OSX: bundle_contents = os.environ.get("GST_BUNDLE_CONTENTS") log("OSX: GST_BUNDLE_CONTENTS=%s", bundle_contents) if bundle_contents: os.environ["GST_PLUGIN_PATH"] = os.path.join(bundle_contents, "Resources", "lib", "gstreamer-1.0") os.environ["GST_PLUGIN_SCANNER"] = os.path.join(bundle_contents, "Resources", "bin", "gst-plugin-scanner-1.0") #typelib path should have been set in PythonExecWrapper if not os.environ.get("GI_TYPELIB_PATH"): gi_dir = os.path.join(bundle_contents, "Resources", "lib", "girepository-1.0") os.environ["GI_TYPELIB_PATH"] = gi_dir log("GStreamer 1.x environment: %s", dict((k,v) for k,v in os.environ.items() if (k.startswith("GST") or k.startswith("GI") or k=="PATH"))) log("GStreamer 1.x sys.path=%s", csv(sys.path)) try: log("import gi") import gi gi.require_version('Gst', '1.0') from gi.repository import Gst #@UnresolvedImport log("Gst=%s", Gst) Gst.init(None) gst = Gst except Exception as e: log("Warning failed to import GStreamer 1.x", exc_info=True) log.warn("Warning: failed to import GStreamer 1.x:") log.warn(" %s", e) return None return gst
def import_gst(): global gst, has_gst, gst_vinfo if has_gst is not None: return gst #hacks to locate gstreamer plugins on win32 and osx: if WIN32: frozen = hasattr(sys, "frozen") and sys.frozen in ("windows_exe", "console_exe", True) log("gstreamer_util: frozen=%s", frozen) if frozen: #on win32, we keep separate trees #because GStreamer 0.10 and 1.x were built using different and / or incompatible version of the same libraries: from xpra.platform.paths import get_app_dir gst_dir = os.path.join(get_app_dir(), "gstreamer-1.0") #ie: C:\Program Files\Xpra\gstreamer-0.10 os.environ["GST_PLUGIN_PATH"] = gst_dir gst_bin_dir = os.path.join(gst_dir, "bin") #ie: C:\Program Files\Xpra\gstreamer-0.10\bin os.environ["PATH"] = os.pathsep.join(x for x in (gst_bin_dir, os.environ.get("PATH", "")) if x) sys.path.insert(0, gst_bin_dir) scanner = os.path.join(gst_bin_dir, "gst-plugin-scanner.exe") if os.path.exists(scanner): os.environ["GST_PLUGIN_SCANNER"] = scanner gi_dir = os.path.join(get_app_dir(), "girepository-1.0") os.environ["GI_TYPELIB_PATH"] = gi_dir elif OSX: bundle_contents = os.environ.get("GST_BUNDLE_CONTENTS") log("OSX: GST_BUNDLE_CONTENTS=%s", bundle_contents) if bundle_contents: os.environ["GST_PLUGIN_PATH"] = os.path.join(bundle_contents, "Resources", "lib", "gstreamer-1.0") os.environ["GST_PLUGIN_SCANNER"] = os.path.join(bundle_contents, "Resources", "bin", "gst-plugin-scanner-1.0") gi_dir = os.path.join(bundle_contents, "Resources", "lib", "girepository-1.0") os.environ["GI_TYPELIB_PATH"] = gi_dir log("GStreamer 1.x environment: %s", dict((k,v) for k,v in os.environ.items() if (k.startswith("GST") or k.startswith("GI") or k=="PATH"))) log("GStreamer 1.x sys.path=%s", csv(sys.path)) try: _gst = import_gst1() v = _gst.version() if v[-1]==0: v = v[:-1] gst_vinfo = ".".join((str(x) for x in v)) gst = _gst except Exception as e: log("Warning failed to import GStreamer 1.x", exc_info=True) log.warn("Warning: failed to import GStreamer 1.x:") log.warn(" %s", e) return None has_gst = gst is not None return gst
def get_CUDA_function(device_id, function_name): """ Returns the compiled kernel for the given device and kernel key. """ global KERNELS data = KERNELS.get(function_name) if data is None: from xpra.platform.paths import get_app_dir from xpra.os_util import load_binary_file cubin_file = os.path.join(get_app_dir(), "cuda", "%s.fatbin" % function_name) log("get_CUDA_function(%s, %s) cubin file=%s", device_id, function_name, cubin_file) data = load_binary_file(cubin_file) if not data: log.error("Error: failed to load CUDA bin file '%s'", cubin_file) return None log(" loaded %s bytes", len(data)) KERNELS[function_name] = data #now load from cubin: start = monotonic_time() try: mod = driver.module_from_buffer(data) except Exception as e: log("module_from_buffer(%s)", data, exc_info=True) log.error("Error: failed to load module from buffer for '%s'", function_name) log.error(" %s", e) return None log("get_CUDA_function(%s, %s) module=%s", device_id, function_name, mod) try: CUDA_function = mod.get_function(function_name) except driver.LogicError as e: raise Exception("failed to load '%s' from %s: %s" % (function_name, mod, e)) end = monotonic_time() log("loading function %s from pre-compiled cubin took %.1fms", function_name, 1000.0*(end-start)) return CUDA_function
def exec_command(command): log("exec_command(%s)", command) from xpra.platform.win32.create_process_lib import Popen, CREATIONINFO, CREATION_TYPE_TOKEN, LOGON_WITH_PROFILE, CREATE_NEW_PROCESS_GROUP, STARTUPINFO creation_info = CREATIONINFO() creation_info.dwCreationType = CREATION_TYPE_TOKEN creation_info.dwLogonFlags = LOGON_WITH_PROFILE creation_info.dwCreationFlags = CREATE_NEW_PROCESS_GROUP creation_info.hToken = logon_info.Token log("creation_info=%s", creation_info) startupinfo = STARTUPINFO() startupinfo.lpDesktop = "WinSta0\\Default" startupinfo.lpTitle = "Xpra-Shadow" cwd = get_app_dir() from subprocess import PIPE env = self.get_proxy_env() log("env=%s", env) proc = Popen(command, stdout=PIPE, stderr=PIPE, cwd=cwd, env=env, startupinfo=startupinfo, creationinfo=creation_info) log("Popen(%s)=%s", command, proc) log("poll()=%s", proc.poll()) try: log("stdout=%s", proc.stdout.read()) log("stderr=%s", proc.stderr.read()) except: pass if proc.poll() is not None: return None self.child_reaper.add_process(proc, "server-%s" % username, "xpra shadow", True, True) return proc
def do_get_sshpass_command(): from xpra.platform.paths import get_app_dir base = get_app_dir() p = os.path.join(base, "Helpers", "sshpass") if os.path.exists(p): return p return None
def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon): from xpra.platform.darwin import osx_notifier osx_notifier_file = osx_notifier.__file__ if osx_notifier_file.endswith("pyc"): osx_notifier_file = osx_notifier_file[:-1] import time #osx_notifier_file = "/Users/osx/osx_notifier.py" from xpra.platform.paths import get_app_dir base = get_app_dir() #python_bin = "/usr/bin/python" python_bin = os.path.join(base, "Resources", "bin", "python") cmd = [ python_bin, osx_notifier_file, "%s-%s" % (int(time.time()), nid), summary, body ] from xpra.child_reaper import getChildReaper import subprocess env = os.environ.copy() for x in ("DYLD_LIBRARY_PATH", "XDG_CONFIG_DIRS", "XDG_DATA_DIRS", "GTK_DATA_PREFIX", "GTK_EXE_PREFIX", "GTK_PATH", "GTK2_RC_FILES", "GTK_IM_MODULE_FILE", "GDK_PIXBUF_MODULE_FILE", "PANGO_RC_FILE", "PANGO_LIBDIR", "PANGO_SYSCONFDIR", "CHARSETALIASDIR", "GST_BUNDLE_CONTENTS", "PYTHON", "PYTHONHOME", "PYTHONPATH"): if x in env: del env[x] notifylog("running %s with env=%s", cmd, env) proc = subprocess.Popen(cmd, env=env) proc.wait() notifylog("returned %i", proc.poll()) getChildReaper().add_process(proc, "notifier-%s" % nid, cmd, True, True)
def exec_command(username, command, env): log("exec_command%s", (username, command, env)) from xpra.platform.win32.lsa_logon_lib import logon_msv1_s4u logon_info = logon_msv1_s4u(username) log("logon_msv1_s4u(%s)=%s", username, logon_info) from xpra.platform.win32.create_process_lib import ( Popen, CREATIONINFO, CREATION_TYPE_TOKEN, LOGON_WITH_PROFILE, CREATE_NEW_PROCESS_GROUP, STARTUPINFO, ) creation_info = CREATIONINFO() creation_info.dwCreationType = CREATION_TYPE_TOKEN creation_info.dwLogonFlags = LOGON_WITH_PROFILE creation_info.dwCreationFlags = CREATE_NEW_PROCESS_GROUP creation_info.hToken = logon_info.Token log("creation_info=%s", creation_info) startupinfo = STARTUPINFO() startupinfo.lpDesktop = "WinSta0\\Default" startupinfo.lpTitle = "Xpra-Shadow" cwd = get_app_dir() from subprocess import PIPE log("env=%s", env) proc = Popen(command, stdout=PIPE, stderr=PIPE, cwd=cwd, env=env, startupinfo=startupinfo, creationinfo=creation_info) log("Popen(%s)=%s", command, proc) return proc
def print_files(printer, filenames, title, options): log("win32.print_files%s", (printer, filenames, title, options)) global JOB_ID, PROCESSES, GSVIEW_DIR, GSPRINT_EXE, GSWINXXC_EXE assert GSVIEW_DIR, "cannot print files without gsprint!" processes = [] for filename in filenames: cwd = get_app_dir() command = ["PDFIUM_Print.exe", filename, printer, title] log("print command: %s", command) startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = 0 #aka win32.con.SW_HIDE process = subprocess.Popen(command, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, startupinfo=startupinfo) process.print_filename = filename #we just let it run, no need for reaping the process on win32 processes.append(process) JOB_ID += 1 PROCESSES[JOB_ID] = processes log("win32.print_files(..)=%s (%s)", JOB_ID, processes) return JOB_ID
def __init__(self, **kwargs): log("exec.Authenticator(%s)", kwargs) self.command = kwargs.pop("command", "") self.timeout = kwargs.pop("timeout", TIMEOUT) self.timer = None self.proc = None self.timeout_event = False if not self.command: if os.name == "posix": auth_dialog = "/usr/libexec/xpra/auth_dialog" else: from xpra.platform.paths import get_app_dir #pylint: disable=import-outside-toplevel auth_dialog = os.path.join(get_app_dir(), "auth_dialog") if EXECUTABLE_EXTENSION: #ie: add ".exe" on MS Windows auth_dialog += ".%s" % EXECUTABLE_EXTENSION log("auth_dialog=%s", auth_dialog) if os.path.exists(auth_dialog): self.command = auth_dialog assert self.command, "exec authentication module is not configured correctly: no command specified" connection = kwargs.get("connection") log("exec connection info: %s", connection) assert connection, "connection object is missing" self.connection_str = str(connection) super().__init__(**kwargs)
def do_get_sshpass_command(): from xpra.platform.paths import get_app_dir base = get_app_dir() p = os.path.join(base, "Resources", "bin", "sshpass") if os.path.exists(p): return p return None
def do_get_sound_command(): from xpra.sound.gstreamer_util import GSTREAMER1 if GSTREAMER1: from xpra.platform.paths import get_app_dir app_dir = get_app_dir() #is there a python3 bundled sound subdirectory sound_exe = os.path.join(app_dir, "Sound", "xpra_cmd.exe") return [sound_exe] return ["xpra_cmd.exe"]
def do_get_sound_command(): #try to use the subapp: from xpra.platform.paths import get_app_dir base = get_app_dir() subapp = os.path.join(base, "Xpra_NoDock.app", "Contents") if os.path.exists(subapp) and os.path.isdir(subapp): base = subapp helper = os.path.join(subapp, "MacOS", "Xpra") return [helper]
def start_win32_shadow(self, username, new_session_dict): log("start_win32_shadow%s", (username, new_session_dict)) from xpra.platform.paths import get_app_dir from xpra.platform.win32.lsa_logon_lib import logon_msv1_s4u logon_info = logon_msv1_s4u(username) log("logon_msv1_s4u(%s)=%s", username, logon_info) #hwinstaold = set_window_station("winsta0") def exec_command(command): log("exec_command(%s)", command) from xpra.platform.win32.create_process_lib import Popen, CREATIONINFO, CREATION_TYPE_TOKEN, LOGON_WITH_PROFILE, CREATE_NEW_PROCESS_GROUP, STARTUPINFO creation_info = CREATIONINFO() creation_info.dwCreationType = CREATION_TYPE_TOKEN creation_info.dwLogonFlags = LOGON_WITH_PROFILE creation_info.dwCreationFlags = CREATE_NEW_PROCESS_GROUP creation_info.hToken = logon_info.Token log("creation_info=%s", creation_info) startupinfo = STARTUPINFO() startupinfo.lpDesktop = "WinSta0\\Default" startupinfo.lpTitle = "Xpra-Shadow" cwd = get_app_dir() from subprocess import PIPE env = self.get_proxy_env() log("env=%s", env) proc = Popen(command, stdout=PIPE, stderr=PIPE, cwd=cwd, env=env, startupinfo=startupinfo, creationinfo=creation_info) log("Popen(%s)=%s", command, proc) log("poll()=%s", proc.poll()) try: log("stdout=%s", proc.stdout.read()) log("stderr=%s", proc.stderr.read()) except: pass if proc.poll() is not None: return None self.child_reaper.add_process(proc, "server-%s" % username, "xpra shadow", True, True) return proc #whoami = os.path.join(get_app_dir(), "whoami.exe") #exec_command([whoami]) port = 10000 xpra_command = os.path.join(get_app_dir(), "xpra.exe") command = [ xpra_command, "shadow", "--bind-tcp=0.0.0.0:%i" % port, "-d", "win32" ] proc = exec_command(command) if not proc: return None, None #exec_command(["C:\\Windows\notepad.exe"]) return "tcp/localhost:%i" % port, proc
def load_content_type_defs(): global content_type_defs if content_type_defs is None: content_type_defs = OrderedDict() content_type_dir = os.path.join(get_app_dir(), "content-type") log("load_content_type_defs() content_type_dir=%s", content_type_dir) load_content_type_dir(content_type_dir) for d in get_user_conf_dirs(): load_content_type_dir(d) return content_type_defs
def do_get_xpra_command(): if sys.argv and sys.argv[0].lower().endswith("/xpra"): return [sys.argv[0]] #try to use the one from the app bundle: from xpra.platform.paths import get_app_dir base = get_app_dir() xpra_cmd = os.path.join(base, "MacOS", "Xpra") if os.path.exists(xpra_cmd): return [xpra_cmd] return ["xpra"]
def do_get_resources_dir(): from xpra.platform.paths import get_app_dir app_dir = get_app_dir() prefix = os.environ.get("MINGW_PREFIX") for d in (app_dir, prefix): if not d or not os.path.isdir(d): continue share_xpra = os.path.join(d, "share", "xpra") if os.path.exists(share_xpra): return share_xpra return app_dir
def main(): from xpra.platform.win32.common import user32 def click_callback(button, pressed): menu = CreatePopupMenu() AppendMenu(menu, win32con.MF_STRING, 1024, u"Generate balloon") AppendMenu(menu, win32con.MF_STRING, 1025, u"Exit") pos = POINT() GetCursorPos(byref(pos)) hwnd = tray.hwnd user32.SetForegroundWindow(hwnd) user32.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos.x, pos.y, 0, hwnd, None) PostMessageA(hwnd, win32con.WM_NULL, 0, 0) def command_callback(hwnd, cid): if cid == 1024: from xpra.platform.win32.win32_balloon import notify from xpra.os_util import BytesIOClass try: from PIL import Image #@UnresolvedImport img = Image.open("icons\\printer.png") buf = BytesIOClass() img.save(buf, "PNG") data = buf.getvalue() buf.close() icon = (b"png", img.size[0], img.size[1], data) except Exception as e: print("could not find icon: %s" % (e,)) icon = None else: pass notify(hwnd, 0, "hello", "world", timeout=1000, icon=icon) elif cid == 1025: print("Goodbye") DestroyWindow(hwnd) else: print("OnCommand for ID=%s" % cid) def win32_quit(): PostQuitMessage(0) # Terminate the app. from xpra.platform.paths import get_app_dir idir = os.path.abspath(get_app_dir()) wdir = os.path.join(idir, "win32") if os.path.exists(wdir): idir = wdir iconPathName = os.path.join(idir, "xpra.ico") tray = win32NotifyIcon(0, "test", move_callbacks=None, click_callback=click_callback, exit_callback=win32_quit, command_callback=command_callback, iconPathName=iconPathName) #pump messages: msg = ctypes.wintypes.MSG() pMsg = ctypes.pointer(msg) while user32.GetMessageA(pMsg, win32con.NULL, 0, 0) != 0: user32.TranslateMessage(pMsg) user32.DispatchMessageA(pMsg)
def do_get_sound_command(): from xpra.platform.paths import get_app_dir app_dir = get_app_dir() for apaths in ( ("Audio", "Xpra_Audio.exe"), #python3 bundled sound subdirectory ("Xpra_Audio.exe", ), #same directory, but with a nicer name: ("xpra_cmd.exe", ), #fallback for older build method ): sound_exe = os.path.join(app_dir, *apaths) if os.path.exists(sound_exe): return [sound_exe] return do_get_xpra_command()
def do_get_sound_command(): #try to use the subapp: from xpra.platform.paths import get_app_dir base = get_app_dir() subapp = os.path.join(base, "Xpra_NoDock.app", "Contents") if os.path.exists(subapp) and os.path.isdir(subapp): base = subapp #appstore builds have script wrappers: helper = os.path.join(base, "Resources", "scripts", "Xpra") if not os.path.exists(helper): helper = os.path.join(base, "Helpers", "Xpra") return [helper]
def do_get_sound_command(): from xpra.platform.paths import get_app_dir app_dir = get_app_dir() #is there a python3 bundled sound subdirectory sound_exe = os.path.join(app_dir, "Audio", "Xpra_Audio.exe") #same directory, but with a nicer name: if not os.path.exists(sound_exe): sound_exe = os.path.join(app_dir, "Xpra_Audio.exe") #fallback for older build method: if not os.path.exists(sound_exe): sound_exe = os.path.join(app_dir, "xpra_cmd.exe") return [sound_exe]
def load_content_type_defs(): global content_type_defs if content_type_defs is None: content_type_defs = OrderedDict() content_type_dir = os.path.join(get_app_dir(), "content-type") log("load_content_type_defs() content_type_dir=%s", content_type_dir) load_content_type_dir(content_type_dir) for d in get_user_conf_dirs(): load_content_type_dir(d) for e in CONTENT_TYPE_DEFS.split(","): if not process_content_type_entry(e): log.warn(" invalid entry in environment variable") return content_type_defs
def init_printing(callback=None): global printers_modified_callback, GSVIEW_DIR, GSPRINT_EXE, GSWIN32C_EXE log("init_printing(%s) printers_modified_callback=%s", callback, printers_modified_callback) printers_modified_callback = callback #ensure we can find gsprint.exe in a subdirectory: from xpra.platform.paths import get_app_dir GSVIEW_DIR = os.path.join(get_app_dir(), "gsview") assert os.path.exists(GSVIEW_DIR) and os.path.isdir(GSVIEW_DIR), "cannot find gsview directory in '%s'" % GSVIEW_DIR GSPRINT_EXE = os.path.join(GSVIEW_DIR, "gsprint.exe") assert os.path.exists(GSPRINT_EXE), "cannot find gsprint.exe in '%s'" % GSVIEW_DIR GSWIN32C_EXE = os.path.join(GSVIEW_DIR, "gswin32c.exe") assert os.path.exists(GSWIN32C_EXE), "cannot find gswin32c.exe in '%s'" % GSVIEW_DIR try: init_winspool_listener() except Exception: log.error("Error: failed to register for print spooler changes", exc_info=True)
def do_get_nodock_command(): #try to use the subapp: from xpra.platform.paths import get_app_dir base = get_app_dir() subapp = os.path.join(base, "Xpra_NoDock.app", "Contents") if os.path.exists(subapp) and os.path.isdir(subapp): base = subapp #appstore builds have script wrappers: helper = os.path.join(base, "Resources", "scripts", "Xpra") if not os.path.exists(helper): helper = os.path.join(base, "Helpers", "Xpra") if not os.path.exists(helper): #having a dock is still better than #trying to run a command that does not exist! from xpra.platform.paths import get_xpra_command return get_xpra_command() return [helper]
def do_import_gst(): global gst if gst is not None: return gst #hacks to locate gstreamer plugins on win32 and osx: if WIN32: frozen = getattr(sys, "frozen", None) in ("windows_exe", "console_exe", True) log("gstreamer_util: frozen=%s", frozen) if frozen: from xpra.platform.paths import get_app_dir gst_dir = os.path.join( get_app_dir(), "lib", "gstreamer-1.0") #ie: C:\Program Files\Xpra\lib\gstreamer-1.0 os.environ["GST_PLUGIN_PATH"] = gst_dir elif OSX: bundle_contents = os.environ.get("GST_BUNDLE_CONTENTS") log("OSX: GST_BUNDLE_CONTENTS=%s", bundle_contents) if bundle_contents: rsc_dir = os.path.join(bundle_contents, "Resources") os.environ["GST_PLUGIN_PATH"] = os.path.join( rsc_dir, "lib", "gstreamer-1.0") os.environ["GST_PLUGIN_SCANNER"] = os.path.join( rsc_dir, "bin", "gst-plugin-scanner-1.0") log( "GStreamer 1.x environment: %s", dict((k, v) for k, v in os.environ.items() if (k.startswith("GST") or k.startswith("GI") or k == "PATH"))) log("GStreamer 1.x sys.path=%s", csv(sys.path)) try: log("import gi") import gi gi.require_version('Gst', '1.0') from gi.repository import Gst #@UnresolvedImport log("Gst=%s", Gst) Gst.init(None) gst = Gst except Exception as e: log("Warning failed to import GStreamer 1.x", exc_info=True) log.warn("Warning: failed to import GStreamer 1.x:") log.warn(" %s", e) return None return gst
def load_categories_to_type(): d = os.path.join(get_app_dir(), "content-categories") if not os.path.exists(d) or not os.path.isdir(d): log("load_categories_to_type() directory '%s' not found", d) return {} categories_to_type = {} for f in sorted(os.listdir(d)): if f.endswith(".conf"): cc_file = os.path.join(d, f) if os.path.isfile(cc_file): try: categories_to_type.update(load_content_categories_file(cc_file)) except Exception as e: log("load_content_type_file(%s)", cc_file, exc_info=True) log.error("Error loading content-type data from '%s'", cc_file) log.error(" %s", e) log("load_categories_to_type()=%s", categories_to_type) return categories_to_type
def _get_xpra_exe_command(*cmd_options): from xpra.platform.paths import get_app_dir exe_dir = get_app_dir() mingw = os.environ.get("MINGW_PREFIX") for cmd in cmd_options: exe_name = "%s.exe" % cmd if sys.executable.lower().endswith(exe_name): #prefer the same executable we were launched from: return [sys.executable] #try to find it in exe dir: exe = os.path.join(exe_dir, exe_name) if os.path.exists(exe) and os.path.isfile(exe): return [exe] #without ".exe" extension: script = os.path.join(exe_dir, cmd) if os.path.exists(script) and os.path.isfile(script): return [script] if mingw: #the python interpreter to use with the scripts: py = os.path.join(mingw, "bin", "python3.exe") if os.path.exists(py): if cmd.lower() in ("python", "python3"): return [py] #ie: /e/Xpra/trunk/src/dist/scripts/xpra script = os.path.join(os.getcwd(), "scripts", cmd.lower()) if os.path.exists(script) and os.path.isfile(script): return [py, script] #ie: /mingw64/bin/xpra script = os.path.join(mingw, "bin", cmd.lower()) if os.path.exists(script) and os.path.isfile(script): return [py, script] from xpra.platform.paths import default_do_get_xpra_command d = default_do_get_xpra_command() if len(d) == 1: #ie: d="xpra" if not d[0].lower().endswith(".exe"): return [sys.executable, d[0]] return d
def init_printing(callback=None): global printers_modified_callback, GSVIEW_DIR, GSPRINT_EXE, GSWINXXC_EXE log("init_printing(%s) printers_modified_callback=%s", callback, printers_modified_callback) printers_modified_callback = callback #ensure we can find gsprint.exe in a subdirectory: GSVIEW_DIR = os.path.join(get_app_dir(), "gsview") assert os.path.exists(GSVIEW_DIR) and os.path.isdir( GSVIEW_DIR), "cannot find gsview directory in '%s'" % GSVIEW_DIR GSPRINT_EXE = os.path.join(GSVIEW_DIR, "gsprint.exe") assert os.path.exists( GSPRINT_EXE), "cannot find gsprint.exe in '%s'" % GSVIEW_DIR for bits in (32, 64): GSWINXXC_EXE = os.path.join(GSVIEW_DIR, "gswin%sc.exe" % bits) if os.path.exists(GSWINXXC_EXE): break assert os.path.exists( GSWINXXC_EXE), "cannot find gswin??c.exe in '%s'" % GSVIEW_DIR try: init_winspool_listener() except Exception: log.error("Error: failed to register for print spooler changes", exc_info=True)
def print_files(printer, filenames, title, options): log("win32.print_files%s", (printer, filenames, title, options)) global JOB_ID, PROCESSES, GSVIEW_DIR, GSPRINT_EXE, GSWINXXC_EXE assert GSVIEW_DIR, "cannot print files without gsprint!" processes = [] for filename in filenames: #command = ["C:\\Program Files\\Xpra\\gsview\\gsprint.exe"] if PDFIUM_PRINT: cwd = get_app_dir() command = ["PDFIUM_Print.exe", filename, printer, title] else: cwd = GSVIEW_DIR command = [GSPRINT_EXE, "-ghostscript", GSWINXXC_EXE, "-colour"] if printer: command += ["-printer", printer] command += [filename] #add gsview directory PATH = os.environ.get("PATH") os.environ["PATH"] = str(PATH + ";" + GSVIEW_DIR) log("environment: %s", os.environ) log("print command: %s", command) startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = 0 #aka win32.con.SW_HIDE process = subprocess.Popen(command, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, startupinfo=startupinfo) process.print_filename = filename #we just let it run, no need for reaping the process on win32 processes.append(process) JOB_ID += 1 PROCESSES[JOB_ID] = processes log("win32.print_files(..)=%s (%s)", JOB_ID, processes) return JOB_ID
def start_win32_shadow(self, username, new_session_dict): log("start_win32_shadow%s", (username, new_session_dict)) #hwinstaold = set_window_station("winsta0") #whoami = os.path.join(get_app_dir(), "whoami.exe") #exec_command([whoami]) xpra_command = os.path.join(get_app_dir(), "Xpra-Shadow.exe") named_pipe = username.replace(" ", "_") command = [ xpra_command, "--bind=%s" % named_pipe, #"--tray=no", ] from xpra.log import debug_enabled_categories if debug_enabled_categories: command += ["-d", ",".join(tuple(debug_enabled_categories))] #command += ["-d", "all"] env = self.get_proxy_env() #env["XPRA_ALL_DEBUG"] = "1" #env["XPRA_REDIRECT_OUTPUT"] = "1" #env["XPRA_LOG_FILENAME"] = "E:\\Shadow-Instance.log" proc = exec_command(username, command, env) r = pollwait(proc, 1) if r: log("poll()=%s", r) try: log("stdout=%s", proc.stdout.read()) log("stderr=%s", proc.stderr.read()) except (OSError, IOError, AttributeError): log("failed to read stdout / stderr of subprocess", exc_info=True) raise Exception("shadow subprocess failed with exit code %s" % r) self.child_reaper.add_process(proc, "server-%s" % username, "xpra shadow", True, True) #TODO: poll the named pipe log("sleep wait..") import time time.sleep(2) return proc, "named-pipe://%s" % named_pipe, "Main"
def do_get_default_conf_dirs(): #ie: C:\Program Files\Xpra\ from xpra.platform.paths import get_app_dir return [os.path.join(get_app_dir(), "etc", "xpra")]
logging.getLogger("comtypes").setLevel(logging.INFO) loggers = [logging.getLogger(x) for x in ("comtypes.client._code_cache", "comtypes.client._generate")] saved_levels = [x.getEffectiveLevel() for x in loggers] try: for logger in loggers: logger.setLevel(logging.WARNING) import comtypes #@UnresolvedImport from comtypes.client import GetModule, CreateObject #@UnresolvedImport from comtypes import CoClass, GUID #@UnresolvedImport from comtypes.automation import VARIANT #@UnresolvedImport from comtypes.persist import IPropertyBag, IErrorLog #@UnresolvedImport from ctypes import POINTER comtypes.client._generate.__verbose__ = False #load directshow: module_dir = get_app_dir() #so we can run from the source tree: if os.path.exists(os.path.join(module_dir, "win32")): module_dir = os.path.join(module_dir, "win32") directshow_tlb = os.path.join(module_dir, "DirectShow.tlb") log("loading module from %s", directshow_tlb) directshow = GetModule(directshow_tlb) log("directshow=%s", directshow) finally: for i, logger in enumerate(loggers): logger.setLevel(saved_levels[i]) CLSID_VideoInputDeviceCategory = GUID("{860BB310-5D01-11d0-BD3B-00A0C911CE86}") CLSID_SystemDeviceEnum = GUID('{62BE5D10-60EB-11d0-BD3B-00A0C911CE86}') class DeviceEnumerator(CoClass):
def do_get_icon_dir(): from xpra.platform.paths import get_app_dir return os.path.join(get_app_dir(), "icons")
def do_get_resources_dir(): from xpra.platform.paths import get_app_dir return get_app_dir()
def do_get_websockify_command(): from xpra.platform.paths import get_app_dir helpers_dir = os.path.join(get_app_dir(), "Helpers") if os.path.exists(helpers_dir) and os.path.isdir(helpers_dir): return [os.path.join(helpers_dir, "websockify")] return ["Websockify"]
def import_gst(): global gst, has_gst, gst_vinfo, gst_major_version if has_gst is not None: return gst PYTHON3 = sys.version_info[0]>=3 if PYTHON3: imports = [ (import_gst1, 1) ] elif GSTREAMER1: imports = [ (import_gst1, 1), (import_gst0_10, 0), ] else: imports = [ (import_gst0_10, 0), (import_gst1, 1), ] errs = {} saved_sys_path = sys.path[:] saved_os_environ = os.environ.copy() for import_function, MV in imports: #restore os.environ and sys.path sys.path = saved_sys_path[:] os.environ.clear() os.environ.update(saved_os_environ) vstr = get_version_str(MV) #hacks to locate gstreamer plugins on win32 and osx: if WIN32: frozen = hasattr(sys, "frozen") and sys.frozen in ("windows_exe", "console_exe", True) log("gstreamer_util: frozen=%s", frozen) if frozen: #on win32, we keep separate trees #because GStreamer 0.10 and 1.x were built using different and / or incompatible version of the same libraries: from xpra.platform.paths import get_app_dir gst_dir = os.path.join(get_app_dir(), "gstreamer-%s" % vstr) #ie: C:\Program Files\Xpra\gstreamer-0.10 os.environ["GST_PLUGIN_PATH"] = gst_dir if MV==1: gst_bin_dir = os.path.join(gst_dir, "bin") #ie: C:\Program Files\Xpra\gstreamer-0.10\bin os.environ["PATH"] = os.pathsep.join(x for x in (gst_bin_dir, os.environ.get("PATH", "")) if x) sys.path.insert(0, gst_bin_dir) scanner = os.path.join(gst_bin_dir, "gst-plugin-scanner.exe") if os.path.exists(scanner): os.environ["GST_PLUGIN_SCANNER"] = scanner gi_dir = os.path.join(get_app_dir(), "girepository-%s" % vstr) os.environ["GI_TYPELIB_PATH"] = gi_dir elif OSX: bundle_contents = os.environ.get("GST_BUNDLE_CONTENTS") log("OSX: GST_BUNDLE_CONTENTS=%s", bundle_contents) if bundle_contents: os.environ["GST_PLUGIN_PATH"] = os.path.join(bundle_contents, "Resources", "lib", "gstreamer-%s" % vstr) os.environ["GST_PLUGIN_SCANNER"] = os.path.join(bundle_contents, "Helpers", "gst-plugin-scanner-%s" % vstr) if MV==1: gi_dir = os.path.join(bundle_contents, "Resources", "lib", "girepository-%s" % vstr) os.environ["GI_TYPELIB_PATH"] = gi_dir if MV<1: #we should not be loading the gi bindings try: del os.environ["GI_TYPELIB_PATH"] except: pass log("GStreamer %s environment: %s", vstr, dict((k,v) for k,v in os.environ.items() if (k.startswith("GST") or k.startswith("GI") or k=="PATH"))) log("GStreamer %s sys.path=%s", vstr, csv(sys.path)) try: log("trying to import GStreamer %s using %s", get_version_str(MV), import_function) _gst = import_function() v = _gst.version() if v[-1]==0: v = v[:-1] gst_vinfo = ".".join((str(x) for x in v)) gst_major_version = MV gst = _gst break except Exception as e: log("Warning failed to import GStreamer %s", vstr, exc_info=True) errs[vstr] = e if gst: log("Python GStreamer version %s for Python %s.%s", gst_vinfo, sys.version_info[0], sys.version_info[1]) else: log.warn("Warning: failed to import GStreamer:") for vstr,e in errs.items(): log.warn(" GStreamer %s: %s", vstr, e) has_gst = gst is not None return gst
def do_get_default_conf_dirs(): #ie: C:\Program Files\Xpra\ from xpra.platform.paths import get_app_dir return [get_app_dir()]
# Copyright (C) 2014, 2015 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. from xpra.log import Logger log = Logger("printing") import subprocess import win32print #@UnresolvedImport import win32con #@UnresolvedImport #ensure we can find gsprint.exe in a subdirectory: try: from xpra.platform.paths import get_app_dir import os.path gsview_dir = os.path.join(get_app_dir(), "gsview") gsprint_exe = os.path.join(gsview_dir, "gsprint.exe") gswin32c_exe = os.path.join(gsview_dir, "gswin32c.exe") assert os.path.exists(gsview_dir), "cannot find gsview directory in '%s'" % gsview_dir assert os.path.exists(gsprint_exe), "cannot find gsprint_exe in '%s'" % gsview_dir assert os.path.exists(gswin32c_exe), "cannot find gswin32c_exe in '%s'" % gsview_dir except Exception as e: log.warn("failed to setup gsprint path: %s", e) gsview_dir, gsprint_exe, gswin32c_exe = None, None, None #allows us to skip some printers we don't want to export SKIPPED_PRINTERS = os.environ.get("XPRA_SKIPPED_PRINTERS", "Microsoft XPS Document Writer").split(",") #emulate pycups job id
gst = None has_gst = False all_plugin_names = [] pygst_version = "" gst_version = "" #ugly win32 hack to make it find the gstreamer plugins: if sys.platform.startswith("win") and hasattr(sys, "frozen") and sys.frozen in ("windows_exe", "console_exe", True): from xpra.platform.paths import get_app_dir if sys.version_info[0]<3: #gstreamer-0.10 v = (0, 10) else: #gstreamer-1.0 v = (1, 0) os.environ["GST_PLUGIN_PATH"] = os.path.join(get_app_dir(), "gstreamer-%s" % (".".join([str(x) for x in v]))) def import_gst1(): import gi from gi.repository import Gst #@UnresolvedImport #gi.require_version('Gst', '0.10') gi.require_version('Gst', '1.0') Gst.init(None) #make it look like pygst (gstreamer-0.10): Gst.registry_get_default = Gst.Registry.get Gst.get_pygst_version = lambda: gi.version_info Gst.get_gst_version = lambda: Gst.version() def new_buffer(data): buf = Gst.Buffer.new_allocate(None, len(data), None) buf.fill(0, data)