def load_hdl(self, bitfile): print bitfile name = os.path.basename(bitfile) copy(local.path(bitfile), self.remote_machine.path('/tmp')/ name) load = ( self.remote_machine['/bin/cat']['/tmp/{name}'.format(name=name)] > '/dev/xdevcfg') print load self.remote_machine.popen(str(load)).wait()
def __init__(self, remote_machine, server_class="rpyc.utils.server.ThreadedServer", extra_setup="", python_executable=None): self.proc = None self.tun = None self.remote_machine = remote_machine self._tmpdir_ctx = None rpyc_root = local.path(rpyc.__file__).up() self._tmpdir_ctx = remote_machine.tempdir() tmp = self._tmpdir_ctx.__enter__() copy(rpyc_root, tmp / "rpyc") script = (tmp / "deployed-rpyc.py") modname, clsname = server_class.rsplit(".", 1) script.write( SERVER_SCRIPT.replace("$MODULE$", modname).replace( "$SERVER$", clsname).replace("$EXTRA_SETUP$", extra_setup)) if python_executable: cmd = remote_machine[python_executable] else: major = sys.version_info[0] minor = sys.version_info[1] cmd = None for opt in [ "python%s.%s" % (major, minor), "python%s" % (major, ) ]: try: cmd = remote_machine[opt] except CommandNotFound: pass else: break if not cmd: cmd = remote_machine.python self.proc = cmd.popen(script, new_session=True) line = "" try: line = self.proc.stdout.readline() self.remote_port = int(line.strip()) except Exception: try: self.proc.terminate() except Exception: pass stdout, stderr = self.proc.communicate() raise ProcessExecutionError(self.proc.argv, self.proc.returncode, BYTES_LITERAL(line) + stdout, stderr) if hasattr(remote_machine, "connect_sock"): # Paramiko: use connect_sock() instead of tunnels self.local_port = None else: self.local_port = rpyc.utils.factory._get_free_port() self.tun = remote_machine.tunnel(self.local_port, self.remote_port)
def __init__(self, remote_machine, server_class = "rpyc.utils.server.ThreadedServer", extra_setup = "", python_executable=None): self.proc = None self.tun = None self.remote_machine = remote_machine self._tmpdir_ctx = None rpyc_root = local.path(rpyc.__file__).up() self._tmpdir_ctx = remote_machine.tempdir() tmp = self._tmpdir_ctx.__enter__() copy(rpyc_root, tmp / "rpyc") script = (tmp / "deployed-rpyc.py") modname, clsname = server_class.rsplit(".", 1) script.write(SERVER_SCRIPT.replace("$MODULE$", modname).replace("$SERVER$", clsname).replace("$EXTRA_SETUP$", extra_setup)) if python_executable: cmd = remote_machine[python_executable] else: major = sys.version_info[0] minor = sys.version_info[1] cmd = None for opt in ["python%s.%s" % (major, minor), "python%s" % (major,)]: try: cmd = remote_machine[opt] except CommandNotFound: pass else: break if not cmd: cmd = remote_machine.python self.proc = cmd.popen(script, new_session = True) line = "" try: line = self.proc.stdout.readline() self.remote_port = int(line.strip()) except Exception: try: self.proc.terminate() except Exception: pass stdout, stderr = self.proc.communicate() raise ProcessExecutionError(self.proc.argv, self.proc.returncode, BYTES_LITERAL(line) + stdout, stderr) if hasattr(remote_machine, "connect_sock"): # Paramiko: use connect_sock() instead of tunnels self.local_port = None else: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("localhost", 0)) self.local_port = s.getsockname()[1] s.close() self.tun = remote_machine.tunnel(self.local_port, self.remote_port)
def __init__(self, remote_machine, server_class = "rpyc.utils.server.ThreadedServer", serviceCls = None): BaseDeployedServer.__init__(self, remote_machine, server_class) serviceClsPath = local.path(getfile(serviceCls).replace(".pyc",".py")) copy(serviceClsPath, self._tmpdir_path) self._script_path.write(SERVER_SCRIPT%{ "module": self.srvModuleName, "server" : self.srvClsName, "serviceClsImportStr": "import "+serviceCls.__module__, "clsName" : serviceCls.__module__+"."+serviceCls.__name__ }) self._executeRemoteScript() self._getRemotePort() self._createTunnel()
def __init__(self, remote_machine, server_class = "rpyc.utils.server.ThreadedServer"): self.proc = None self.tun = None self.remote_port = None self.remote_machine = remote_machine self.remote_machine_type = remote_machine.__class__.__name__ self.srvModuleName, self.srvClsName = server_class.rsplit(".", 1) self._tmpdir_ctx = remote_machine.tempdir() self._tmpdir_path = self._tmpdir_ctx.__enter__() self._script_path = ( self._tmpdir_path / "deployed-rpyc.py") #Copy modules dir if self.remote_machine_type == "SshMachine": rpyc_root = local.path(rpyc.__file__).dirname else: rpyc_root = local.path(rpyc.__file__).up(2) copy(rpyc_root, self._tmpdir_path)
def __init__(self, remote_machine, server_class="rpyc.utils.server.ThreadedServer", extra_setup=""): self.proc = None self.tun = None self.remote_machine = remote_machine self._tmpdir_ctx = None rpyc_root = local.path(rpyc.__file__).up(2) self._tmpdir_ctx = remote_machine.tempdir() tmp = self._tmpdir_ctx.__enter__() copy(rpyc_root, tmp) script = (tmp / "deployed-rpyc.py") modname, clsname = server_class.rsplit(".", 1) script.write( SERVER_SCRIPT.replace("$MODULE$", modname).replace( "$SERVER$", clsname).replace("$EXTRA_SETUP$", extra_setup)) self.proc = remote_machine.python.popen(script, new_session=True) line = "" try: line = self.proc.stdout.readline() self.remote_port = int(line.strip()) except Exception: try: self.proc.terminate() except Exception: pass stdout, stderr = self.proc.communicate() raise ProcessExecutionError(self.proc.argv, self.proc.returncode, line + stdout, stderr) if hasattr(remote_machine, "connect_sock"): # Paramiko: use connect_sock() instead of tunnels self.local_port = None else: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("localhost", 0)) self.local_port = s.getsockname()[1] s.close() self.tun = remote_machine.tunnel(self.local_port, self.remote_port)
def __init__(self, remote_machine): self.remote_machine = remote_machine rpyc_root = local.path(rpyc.__file__).up() self._tmpdir_ctx = remote_machine.tempdir() tmp = self._tmpdir_ctx.__enter__() self.tmp = tmp copy(rpyc_root, tmp / "rpyc") self.copy_other_files(tmp) script = (tmp / "deployed-rpyc.py") server_class = "rpyc.utils.server.ThreadedServer" modname, clsname = server_class.rsplit(".", 1) script.write(SERVER_SCRIPT.replace("$MODULE$", modname).replace("$SERVER$", clsname).replace("$EXTRA_SETUP$", self.extra_setup)) cmd = remote_machine['/opt/usr/bin/python'] self.proc = cmd.popen(script, new_session = True) line = "" try: line = self.proc.stdout.readline() self.remote_port = int(line.strip()) except Exception: try: self.proc.terminate() except Exception: pass stdout, stderr = self.proc.communicate() raise ProcessExecutionError(self.proc.argv, self.proc.returncode, BYTES_LITERAL(line) + stdout, stderr) if hasattr(remote_machine, "connect_sock"): # Paramiko: use connect_sock() instead of tunnels self.local_port = None else: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("localhost", 0)) self.local_port = s.getsockname()[1] s.close() self.tun = remote_machine.tunnel(self.local_port, self.remote_port)
def copy_other_files(self, tmp): pyredpitaya_root = local.path(__file__).up().up() copy(pyredpitaya_root/'monitor/libmonitor.so', tmp / 'libmonitor.so') copy(pyredpitaya_root/'PyRedPitayaTest.py', tmp / 'PyRedPitayaTest.py') copy(pyredpitaya_root/'PyRedPitaya', tmp / 'PyRedPitaya')
def start(self): template = self.config.parameters.get("template") if template is not None: notebook_templates = (local.path(local.env["ERISYON_ROOT"]) / "projects/plaster/notebooks") path_utils.copy(notebook_templates / template, ".")