def rsync(src, dst, password=None, extraopts=None, logfile=None): """rsync(src, dst, [password, [extraopts, [logfile]]]) Usage: rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST or rsync [OPTION]... [USER@]HOST:SRC DEST or rsync [OPTION]... SRC [SRC]... DEST or rsync [OPTION]... [USER@]HOST::SRC [DEST] or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST] You might want to set the RSYNC_RSH environment variable first. """ opts = "-q" if extraopts: opts += extraopts CMD = "%s %s %s %s" % (RSYNC, opts, src, dst) rsync = proctools.spawnpty(CMD, logfile=logfile) # assume a password will be requested if one is supplied here if password is not None: from pycopia import expect ersync = expect.Expect(rsync) ersync.expect("password:", timeout=2.0) ersync.writeln(password) del ersync rsync.wait() return rsync.exitstatus # user can check exit status for success
def __init__(self, devspec, logfile=None, **kwargs): fo = tty.SerialPort(devspec.port) fo.set_serial(devspec.serial) self._timeout = devspec.get("timeout", 30.0) self._exp = expect.Expect(fo, prompt=devspec.prompt, timeout=self._timeout, logfile=logfile) self.Initialize(devspec, **kwargs)
def __call__(self): fo = self._sock.makefile("w+", 1) exp = expect.Expect(fo, prompt=self.EOL) self.initialize() self.run(exp) self.finalize() fo.flush() fo.close() self._sock.close()
def initialize(self): eq = self._equipment self.host = eq["hostname"].encode("ascii") self.user = eq["login"].encode("ascii") self.password = eq["password"].encode("ascii") cshost, csphyport = eq["console_server"] tn = telnet.Telnet(logfile=self._logfile) tn.open(cshost, self.TCP_BASE_PORT + csphyport) self._intf = expect.Expect(tn, prompt=self.PROMPT) self.login()
def __init__(self, sock, logfile=None): self._sock = sock self.fsm = expect.Expect(self._sock, prompt=self.EOL, logfile=logfile) self.initialize()
self.ring_indicator, self.delta_dataset_ready, self.delta_clear_to_send, ) def get_telnet(host, port=TELNET_PORT, logfile=None): return Telnet(host, port, logfile) if __name__ == '__main__': from pycopia import autodebug from pycopia import expect logging.loglevel_debug() host = "venus" port = 6001 prompt = "$ " tn = Telnet(host, port) #, logfile=sys.stderr) sess = expect.Expect(tn, prompt=prompt) sess.write("\r") sess.expect("login:"******"tester\r") sess.expect("assword:") sess.send("testme\r") sess.wait_for_prompt() print(sess.fileobject().upload("/etc/hosts")) sess.send_slow("exit\r") print("linestate:", tn.linestate) print("modemstate:", tn.modemstate) sess.close()