def exec_get_keyboard_data(self, cmd): # Find the client's current keymap so we can send it to the server: try: from xpra.scripts.exec_util import safe_exec returncode, out, _ = safe_exec(cmd) if returncode==0: return out.decode('utf-8') log.error("'%s' failed with exit code %s", cmd, returncode) except Exception, e: log.error("error running '%s': %s", cmd, e)
def exec_get_keyboard_data(self, cmd): # Find the client's current keymap so we can send it to the server: try: from xpra.scripts.exec_util import safe_exec returncode, out, _ = safe_exec(cmd) if returncode == 0: return out.decode('utf-8') log.error("'%s' failed with exit code %s", cmd, returncode) except Exception, e: log.error("error running '%s': %s", cmd, e)
def pactl_output(*pactl_args): pactl_bin = get_pactl_bin() if not pactl_bin: return -1, None #ie: "pactl list" cmd = [pactl_bin] + list(pactl_args) try: code, out, _ = safe_exec(cmd) return code, out except Exception, e: log.error("failed to execute %s: %s", cmd, e) return -1, None
def pactl_output(pactl_cmd): pactl_bin = get_pactl_bin() if not pactl_bin: return -1, None #ie: "pactl list" cmd = [pactl_bin, pactl_cmd] try: code, out, _ = safe_exec(cmd) return code, out except Exception, e: log.error("failed to execute %s: %s", cmd, e) return -1, None
def pactl_output(*pactl_args): pactl_bin = get_pactl_bin() if not pactl_bin: return -1, None #ie: "pactl list" cmd = [pactl_bin] + list(pactl_args) try: code, out, _ = safe_exec(cmd) debug("pactl_output%s returned %s", pactl_args, code) return code, out except Exception, e: log.error("failed to execute %s: %s", cmd, e) return -1, None
def cleanup_pa(): log("cleanup_pa() process.poll()=%s, pid=%s, dead_pids=%s", pa_proc.poll(), pa_proc.pid, child_reaper._dead_pids) if pa_proc.poll( ) is None and pa_proc.pid not in child_reaper._dead_pids: log.info("stopping pulseaudio with pid %s", pa_proc.pid) try: #first we try pactl (required on Ubuntu): from xpra.scripts.exec_util import safe_exec r, _, _ = safe_exec(["pactl", "exit"]) #warning: pactl will return 0 whether it succeeds or not... #but we can't kill the process because Ubuntu starts a new one if r != 0: #fallback to using SIGINT: pa_proc.terminate() except: log.warn("error trying to stop pulseaudio", exc_info=True)
def which(name): if sys.platform.startswith("win"): return "" cmd = ["which", name] try: returncode, out, _ = safe_exec(cmd, log_errors=False) if returncode != 0 or not out: return "" c = out.replace("\n", "").replace("\r", "") if os.path.exists(c) and os.path.isfile(c): if os.name == "posix" and not os.access(c, os.X_OK): #odd, it's there but we can't run it!? return "" return c return "" except: pass return ""
def which(name): if sys.platform.startswith("win"): return "" cmd = ["which", name] try: returncode, out, _ = safe_exec(cmd, log_errors=False) if returncode!=0 or not out: return "" c = out.replace("\n", "").replace("\r", "") if os.path.exists(c) and os.path.isfile(c): if os.name=="posix" and not os.access(c, os.X_OK): #odd, it's there but we can't run it!? return "" return c return "" except: pass return ""
def cleanup_pa(): log( "cleanup_pa() process.poll()=%s, pid=%s, dead_pids=%s", pa_proc.poll(), pa_proc.pid, child_reaper._dead_pids ) if pa_proc.poll() is None and pa_proc.pid not in child_reaper._dead_pids: log.info("stopping pulseaudio with pid %s", pa_proc.pid) try: # first we try pactl (required on Ubuntu): from xpra.scripts.exec_util import safe_exec r, _, _ = safe_exec(["pactl", "exit"]) # warning: pactl will return 0 whether it succeeds or not... # but we can't kill the process because Ubuntu starts a new one if r != 0: # fallback to using SIGINT: pa_proc.terminate() except: log.warn("error trying to stop pulseaudio", exc_info=True)
def exec_keymap_command(args, stdin=None): try: from xpra.scripts.exec_util import safe_exec returncode, _, _ = safe_exec(args, stdin) def logstdin(): if not stdin or len(stdin)<500: return nonl(stdin) return nonl(stdin[:500])+".." if returncode==0: if not stdin: log("%s", args) else: log("%s with stdin=%s", args, logstdin()) else: log.error("%s with stdin=%s, failed with exit code %s", args, logstdin(), returncode) return returncode except Exception as e: log.error("error calling '%s': %s" % (str(args), e)) return -1
def exec_keymap_command(args, stdin=None): try: from xpra.scripts.exec_util import safe_exec returncode, _, _ = safe_exec(args, stdin) def logstdin(): if not stdin or len(stdin)<32: return stdin return stdin[:30].replace("\n", "\\n")+".." if returncode==0: if not stdin: log("%s", args) else: log("%s with stdin=%s", args, logstdin()) else: log.error("%s with stdin=%s, failed with exit code %s", args, logstdin(), returncode) return returncode except Exception, e: log.error("error calling '%s': %s" % (str(args), e)) return -1
def pactl_output(log_errors=True, *pactl_args): pactl_bin = get_pactl_bin() if not pactl_bin: return -1, None, None #ie: "pactl list" cmd = [pactl_bin] + list(pactl_args) #force "C" locale so that we can parse the output as expected env = os.environ.copy() env["LC_ALL"] = "C" kwargs = {"env" : env} try: code, out, err = safe_exec(cmd, log_errors=log_errors, **kwargs) log("pactl_output%s returned %s", pactl_args, code) return code, out, err except Exception as e: if log_errors: log.error("failed to execute %s: %s", cmd, e) else: log("failed to execute %s: %s", cmd, e) return -1, None, None
def pactl_output(log_errors=True, *pactl_args): pactl_bin = get_pactl_bin() if not pactl_bin: return -1, None, None #ie: "pactl list" cmd = [pactl_bin] + list(pactl_args) #force "C" locale so that we can parse the output as expected env = os.environ.copy() env["LC_ALL"] = "C" kwargs = {"env" : env} try: code, out, err = safe_exec(cmd, log_errors=log_errors, **kwargs) log("pactl_output%s returned %s", pactl_args, code) return code, out, err except Exception, e: if log_errors: log.error("failed to execute %s: %s", cmd, e) else: log("failed to execute %s: %s", cmd, e) return -1, None, None
def which(name): if sys.platform.startswith("win"): return "" cmd = ["which", name] try: returncode, out, _ = safe_exec(cmd, log_errors=False) log("safe_exec(%s)=%s", cmd, (returncode, out)) if returncode!=0 or not out: return "" c = out.decode("utf8").replace("\n", "").replace("\r", "") if os.path.exists(c) and os.path.isfile(c): if os.name=="posix" and not os.access(c, os.X_OK): #odd, it's there but we can't run it!? return "" return c return "" except Exception as e: log.error("Error: failed to run '%s'", " ".join(cmd)) log.error(" %s", e) log("which(%s) error", name, exc_info=True) return ""
def which(name): if sys.platform.startswith("win"): return "" cmd = ["which", name] try: returncode, out, _ = safe_exec(cmd, log_errors=False) log("safe_exec(%s)=%s", cmd, (returncode, out)) if returncode != 0 or not out: return "" c = out.decode("utf8").replace("\n", "").replace("\r", "") if os.path.exists(c) and os.path.isfile(c): if os.name == "posix" and not os.access(c, os.X_OK): #odd, it's there but we can't run it!? return "" return c return "" except Exception as e: log.error("Error: failed to run '%s'", " ".join(cmd)) log.error(" %s", e) log("which(%s) error", name, exc_info=True) return ""