def start_server(host, port, ns_init_import_export=[], conn_opts={}): global _g_wake_server_function daemon_log("pid: %s" % (os.getpid(),)) # Initialise, import and export namespaces for task, ns, arg in ns_init_import_export: if task == "init": _init_local_namespace(ns, arg, force=True) elif task == "export": _init_local_namespace(ns, None, force=True) daemon_log('exporting "%s" to %s' % (ns, arg)) try: c = pythonshare.connection(arg) except Exception, e: daemon_log('connecting to %s failed: %s' % (arg, e)) return if c.export_ns(ns): _register_exported_namespace(ns, c) thread.start_new_thread( _serve_connection, (c, {"kill-server-on-close": True})) else: raise ValueError('Export namespace "%s" to "%s" failed' % (ns, arg)) elif task == "import": if (ns in _g_local_namespaces or ns in _g_remote_namespaces): raise ValueError('Import failed, namespace "%s" already exists' % (ns,)) c = pythonshare.connection(arg) if c.import_ns(ns): _init_remote_namespace(ns, c, c._to_server, c._from_server)
def start_server(host, port, ns_init_import_export=[], conn_opts={}): global _g_wake_server_function global _g_waker_lock daemon_log("pid: %s" % (os.getpid(),)) # Initialise, import and export namespaces for task, ns, arg in ns_init_import_export: if task == "init": _init_local_namespace(ns, arg, force=True) elif task == "export": _init_local_namespace(ns, None, force=True) daemon_log('exporting "%s" to %s' % (ns, arg)) try: c = pythonshare.connection(arg) except Exception, e: daemon_log('connecting to %s failed: %s' % (arg, e)) return if c.export_ns(ns): _register_exported_namespace(ns, c) thread.start_new_thread( _serve_connection, (c, {"kill-server-on-close": True})) else: raise ValueError('Export namespace "%s" to "%s" failed' % (ns, arg)) elif task == "import": if (ns in _g_local_namespaces or ns in _g_remote_namespaces): raise ValueError('Import failed, namespace "%s" already exists' % (ns,)) c = pythonshare.connection(arg) if c.import_ns(ns): _init_remote_namespace(ns, c, c._to_server, c._from_server)
def start_server(host, port, ns_init_import_export=[], conn_opts={}): daemon_log("pid: %s" % (os.getpid(),)) # Initialise, import and export namespaces for task, ns, arg in ns_init_import_export: if task == "init": _init_local_namespace(ns, arg, force=True) elif task == "export": _init_local_namespace(ns, None, force=True) c = pythonshare.connection(arg) if c.export_ns(ns): _register_exported_namespace(ns, c) thread.start_new_thread(_serve_connection, (c, {})) else: raise ValueError('Export namespace "%s" to "%s" failed' % (ns, arg)) elif task == "import": if (ns in _g_local_namespaces or ns in _g_remote_namespaces): raise ValueError('Import failed, namespace "%s" already exists' % (ns,)) c = pythonshare.connection(arg) if c.import_ns(ns): _init_remote_namespace(ns, c, c._to_server, c._from_server) try: addrinfos = socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM) for addrinfo in addrinfos: daemon_log("listen: %s:%s" % (addrinfo[4][0], addrinfo[4][1])) except socket.error: daemon_log("listen: %s:%s" % (host, port)) if isinstance(port, int): # Start listening to the port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if not on_windows: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((host, port)) s.listen(4) while 1: conn, _ = s.accept() thread.start_new_thread(_serve_connection, (conn, conn_opts)) elif port == "stdin": opt_debug_stdout_limit = 0 conn = client.Connection(sys.stdin, sys.stdout) _serve_connection(conn, conn_opts)
def __init__(self, connspec, password): fmbtgti.GUITestConnection.__init__(self) self._screenshotSize = (None, None) # autodetect self._agent_ns = "fmbtwindows-agent" self._agent = pythonshare.connection(connspec, password=password) agentFilename = os.path.join( os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), "fmbtwindows_agent.py") self._agent.exec_in(self._agent_ns, file(agentFilename).read()) self.setScreenToDisplayCoords(lambda x, y: (x, y)) self.setDisplayToScreenCoords(lambda x, y: (x, y))
def __init__(self, connspec): fmbtgti.GUITestConnection.__init__(self) # Assume that there is pythonshare-server running on the windows host, # it has "fmbtwindows-agent" namespace in place, and # fmbtwindows_agent.py has been imported into that namespace. # Launch such a process, for instance by # # pythonshare-server -n "fmbtwindows-agent" -i "import fmbtwindows_agent" self._agent_ns = "fmbtwindows-agent" self._agent = pythonshare.connection(connspec) version = self._agent.eval_in(self._agent_ns, "fmbtwindows_agent.version()") if not (type(version) == str and version): raise FMBTWindowsError("reading fmbtwindows agent version failed")
def open(self): myDir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) self.sendFilesInTar(myDir, ("fmbtx11_conn.py", "fmbtpng.py", "fmbtuinput.py"), "/tmp/fmbtchromiumos") if os.access(os.path.join(myDir, "pythonshare", "__init__.py"), os.R_OK): pythonshareDir = myDir elif os.access( os.path.join(myDir, "..", "pythonshare", "pythonshare", "__init__.py"), os.R_OK): pythonshareDir = os.path.join(myDir, "..", "pythonshare") self.sendFilesInTar( pythonshareDir, ("pythonshare/__init__.py", "pythonshare/server.py", "pythonshare/client.py", "pythonshare/messages.py"), "/tmp/fmbtchromiumos") if os.name != "nt": pythonshareServer = distutils.spawn.find_executable( "pythonshare-server") else: pythonshareServer = os.path.join(os.path.dirname(__file__), "..", "Scripts", "pythonshare-server") if not pythonshareServer or not os.access(pythonshareServer, os.R_OK): raise FMBTChromiumOsError( "cannot find pythonshare-server executable") self.sendFilesInTar(os.path.dirname(pythonshareServer), ("pythonshare-server", ), "/tmp/fmbtchromiumos") agentCmd = ( self._loginCommand + " sudo DISPLAY=:0 XAUTHORITY=/home/chronos/.Xauthority" + " LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:/usr/lib:/usr/lib64" + " python /tmp/fmbtchromiumos/pythonshare-server -p stdin") self._agent = pythonshare.connection("shell://" + agentCmd) self._agent_ns = "fmbtchromiumos-agent" try: self.agentExec("import fmbtx11_conn") except pythonshare.PythonShareError, e: raise FMBTChromiumOsError( "Cannot connect to pythonshare-server on device (%s): %s" % (e, agentCmd))
def open(self): myDir = os.path.dirname(os.path.abspath( inspect.getfile(inspect.currentframe()))) self.sendFilesInTar(myDir, ("fmbtx11_conn.py", "fmbtpng.py", "fmbtuinput.py"), "/tmp/fmbtchromiumos") if os.access(os.path.join(myDir, "pythonshare", "__init__.py"), os.R_OK): pythonshareDir = myDir elif os.access(os.path.join(myDir, "..", "pythonshare", "pythonshare", "__init__.py"), os.R_OK): pythonshareDir = os.path.join(myDir, "..", "pythonshare") self.sendFilesInTar(pythonshareDir, ("pythonshare/__init__.py", "pythonshare/server.py", "pythonshare/client.py", "pythonshare/messages.py"), "/tmp/fmbtchromiumos") if os.name != "nt": pythonshareServer = distutils.spawn.find_executable("pythonshare-server") else: pythonshareServer = os.path.join( os.path.dirname(__file__), "..", "Scripts", "pythonshare-server") if not pythonshareServer or not os.access(pythonshareServer, os.R_OK): raise FMBTChromiumOsError("cannot find pythonshare-server executable") self.sendFilesInTar(os.path.dirname(pythonshareServer), ("pythonshare-server",), "/tmp/fmbtchromiumos") agentCmd = (self._loginCommand + " sudo DISPLAY=:0 XAUTHORITY=/home/chronos/.Xauthority" + " LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:/usr/lib:/usr/lib64" + " python /tmp/fmbtchromiumos/pythonshare-server -p stdin") self._agent = pythonshare.connection("shell://" + agentCmd) self._agent_ns = "fmbtchromiumos-agent" try: self.agentExec("import fmbtx11_conn") except pythonshare.PythonShareError, e: raise FMBTChromiumOsError( "Cannot connect to pythonshare-server on device (%s): %s" % (e, agentCmd))
def start_server(host, port, ns_init_import_export=[]): daemon_log("pid: %s" % (os.getpid(),)) # Initialise, import and export namespaces for task, ns, arg in ns_init_import_export: if task == "init": _init_local_namespace(ns, arg, force=True) elif task == "export": _init_local_namespace(ns, None, force=True) c = pythonshare.connection(arg) if c.export_ns(ns): _register_exported_namespace(ns, c) thread.start_new_thread(_serve_connection, (c,)) else: raise ValueError('export namespace "%s" to "%s" failed' % (ns, arg)) elif task == "import": if (ns in _g_local_namespaces or ns in _g_remote_namespaces): raise ValueError('import failed, namespace "%s" already exists' % (ns,)) c = pythonshare.connection(arg) if c.import_ns(ns): _init_remote_namespace(ns, c, c._to_server, c._from_server) daemon_log("listen: %s:%s" % (host, port)) # Start listening to the port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(4) while 1: conn, _ = s.accept() thread.start_new_thread(_serve_connection, (conn,))