def get_property(self, prop): #subclasses can define properties as attributes: attr_name = prop.replace("-", "_") if hasattr(self, attr_name): return getattr(self, attr_name) #otherwise fallback to default behaviour: if prop == "title": return prettify_plug_name( self.window.get_screen().get_display().get_name()) if prop == "client-machine": return socket.gethostname() if prop == "window-type": return ["NORMAL"] if prop == "fullscreen": return False if prop == "shadow": return True if prop == "depth": return 24 if prop == "scaling": return None if prop == "opacity": return None if prop == "size-hints": size = self.get_dimensions() return { "maximum-size": size, "minimum-size": size, "base-size": size, } if prop == "class-instance": osn = do_get_generic_os_name() if osn == "Linux": try: osn += "-" + get_linux_distribution()[0].replace(" ", "-") except Exception: # pragma: no cover pass return ("xpra-%s" % osn.lower(), "Xpra %s" % osn.replace("-", " ")) if prop == "icons": try: icon_name = get_icon_filename( (get_generic_os_name() or "").lower() + ".png") from PIL import Image img = Image.open(icon_name) log("Image(%s)=%s", icon_name, img) if img: icon_data = load_binary_file(icon_name) assert icon_data w, h = img.size img.close() icon = (w, h, "png", icon_data) icons = (icon, ) return icons except Exception: # pragma: no cover log("failed to return window icon") return () if prop == "content-type": return "desktop" raise ValueError("invalid property: %s" % prop)
def do_get_platform_info(): from xpra.os_util import platform_name, platform_release pp = sys.modules.get("platform", python_platform) def get_processor_name(): if pp.system() == "Windows": return pp.processor() elif pp.system() == "Darwin": os.environ['PATH'] = os.environ['PATH'] + os.pathsep + '/usr/sbin' command = "sysctl -n machdep.cpu.brand_string" import subprocess return subprocess.check_output(command).strip() elif pp.system() == "Linux": with open("/proc/cpuinfo") as f: data = f.read() import re for line in data.split("\n"): if "model name" in line: return re.sub(".*model name.*:", "", line, 1).strip() assert False info = {} ld = get_linux_distribution() if ld: info["linux_distribution"] = ld release = platform_release(pp.release()) info.update({ "": sys.platform, "name": platform_name(sys.platform, info.get("linux_distribution") or release), "release": pp.release(), "sysrelease": release, "platform": pp.platform(), "machine": pp.machine(), "processor": pp.processor(), "architecture": pp.architecture(), }) try: info["processor"] = get_processor_name() except: info["processor"] = pp.processor() return info
def get_default_systemd_run(): #don't use systemd-run on CentOS / RedHat #(it causes failures with "Failed to create bus connection: No such file or directory") from xpra.os_util import load_binary_file, strtobytes data = strtobytes(load_binary_file("/etc/redhat-release") or "") if data and (data.find(b"RedHat") >= 0 or data.find(b"CentOS") >= 0): return "no" if data and data.find(b"Fedora") >= 0: #systemd-run is broken in Fedora 26: #https://github.com/systemd/systemd/issues/3388 try: from xpra.os_util import get_linux_distribution ld = get_linux_distribution() if int(ld[1]) >= 26: return "no" except: pass return "auto"
def get_platform_name(): # better version info than standard python platform: if sys.platform.startswith("sun"): # couldn't find a better way to distinguish opensolaris from solaris... with open("/etc/release") as f: data = f.read() if data and str(data).lower().find("opensolaris"): return "OpenSolaris" return "Solaris" if sys.platform.find("darwin") >= 0: try: # ie: Mac OS X 10.5.8 return "Mac OS X %s" % platform.mac_ver()[0] except: return "Mac OS X" if sys.platform.find("openbsd") >= 0: return "OpenBSD" if sys.platform.startswith("win"): try: import wmi # @UnresolvedImport c = wmi.WMI() for os in c.Win32_OperatingSystem(): eq = os.Caption.find("=") if eq > 0: return (os.Caption[:eq]).strip() return os.Caption except: pass return "Microsoft Windows" if sys.platform.find("bsd") >= 0: return "BSD" try: from xpra.os_util import get_linux_distribution ld = get_linux_distribution() if ld: return "Linux %s" % (" ".join(ld)) except: pass return sys.platform
def get_platform_name(): #better version info than standard python platform: if sys.platform.startswith("sun"): #couldn't find a better way to distinguish opensolaris from solaris... with open("/etc/release") as f: data = f.read() if data and str(data).lower().find("opensolaris"): return "OpenSolaris" return "Solaris" if sys.platform.find("darwin") >= 0: try: #ie: Mac OS X 10.5.8 return "Mac OS X %s" % platform.mac_ver()[0] except: return "Mac OS X" if sys.platform.find("openbsd") >= 0: return "OpenBSD" if sys.platform.startswith("win"): #TODO: use something a bit faster: try: o = subprocess.Popen('systeminfo', stdout=subprocess.PIPE).communicate()[0] try: o = str(o, "latin-1") # Python 3+ except: pass return re.search("OS Name:\s*(.*)", o).group(1).strip() except: pass return "Microsoft Windows" if sys.platform.find("bsd") >= 0: return "BSD" try: from xpra.os_util import get_linux_distribution ld = get_linux_distribution() if ld: return "Linux %s" % (" ".join(ld)) except: pass return sys.platform
def get_platform_name(): #better version info than standard python platform: if sys.platform.startswith("sun"): #couldn't find a better way to distinguish opensolaris from solaris... with open("/etc/release") as f: data = f.read() if data and str(data).lower().find("opensolaris"): return "OpenSolaris" return "Solaris" if sys.platform.find("darwin")>=0: try: #ie: Mac OS X 10.5.8 return "Mac OS X %s" % platform.mac_ver()[0] except: return "Mac OS X" if sys.platform.find("openbsd")>=0: return "OpenBSD" if sys.platform.startswith("win"): try: import wmi #@UnresolvedImport c = wmi.WMI() for os in c.Win32_OperatingSystem(): eq = os.Caption.find("=") if eq>0: return (os.Caption[:eq]).strip() return os.Caption except: pass return "Microsoft Windows" if sys.platform.find("bsd")>=0: return "BSD" try: from xpra.os_util import get_linux_distribution ld = get_linux_distribution() if ld: return "Linux %s" % (" ".join(ld)) except: pass return sys.platform
def do_get_platform_info(): from xpra.os_util import platform_name, platform_release pp = sys.modules.get("platform", python_platform) def get_processor_name(): if pp.system() == "Windows": return pp.processor() elif pp.system() == "Darwin": os.environ['PATH'] = os.environ['PATH'] + os.pathsep + '/usr/sbin' command ="sysctl -n machdep.cpu.brand_string" import subprocess return subprocess.check_output(command).strip() elif pp.system() == "Linux": with open("/proc/cpuinfo") as f: data = f.read() import re for line in data.split("\n"): if "model name" in line: return re.sub(".*model name.*:", "", line,1).strip() assert False info = {} ld = get_linux_distribution() if ld: info["linux_distribution"] = ld release = platform_release(pp.release()) info.update({ "" : sys.platform, "name" : platform_name(sys.platform, info.get("linux_distribution") or release), "release" : pp.release(), "sysrelease": release, "platform" : pp.platform(), "machine" : pp.machine(), "processor" : pp.processor(), "architecture" : pp.architecture(), }) try: info["processor"] = get_processor_name() except: info["processor"] = pp.processor() return info