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 scp(srchost=None, srcpath=None, dsthost=None, dstpath=None, user=None, password=None, prompt=None, callback=None, logfile=None): """scp(source, destination, [password]) Copies the file from source to destination. these parameters are strings that are passed directly to the scp command, and should follow the syntax for this command. """ opts = "-q" src = location(srchost, user, srcpath) dst = location(dsthost, user, dstpath) CMD = "%s %s %s '%s' '%s'" % (SCP, SSH_OPTIONS, opts, src, dst) if logfile: logfile.write(CMD + "\n") scp = proctools.spawnpty(CMD, logfile=logfile) if password is not None: escp = SSHExpect(scp) scp.set_callback(callback or escp.death_callback) escp.login(password) discard = escp.read() else: discard = scp.read() es = scp.wait() return es
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 scp( srchost=None, srcpath=None, dsthost=None, dstpath=None, user=None, password=None, prompt=None, callback=None, logfile=None, ): """Copies the file from source to destination. these parameters are strings that are passed directly to the scp command, and should follow the syntax for this command. """ opts = "-q" src = location(srchost, user, srcpath) dst = location(dsthost, user, dstpath) CMD = "%s %s %s '%s' '%s'" % (SCP, SSH_OPTIONS, opts, src, dst) if logfile: logfile.write(CMD + "\n") scp = proctools.spawnpty(CMD, logfile=logfile) if password is not None: escp = SSHExpect(scp) scp.set_callback(callback or escp.death_callback) escp.login(password) escp.read() else: scp.read() es = scp.wait() return es
def runtest(self, testlist, environmentname="default", reportname=None, options=None): """Run a test using the external runtest program.""" if self.report_rx is not None: self._emit("message", "Test still running") return report = ReportForm() self.report_rx = clientserver.ReportReceiver(report) self._w.body = report if reportname: altreport = ",{}".format(reportname) else: altreport = "" tc = " ".join(testlist) if options: optlist = " ".join("--{}={!r}".format(*t) for t in options.items()) else: optlist = "" cmd = "runtest --reportname=remote{} --environmentname={} {} {}".format(altreport, environmentname, optlist, tc) proctools.spawnpty(cmd, callback=self._test_end)
def sendmail(self, From, rcpt_to, msg, mopts=None, rcptopts=None): from pycopia import proctools cmd = "/usr/sbin/sendmail" for rcpt in rcpt_to: cmd += ' "%s"' % rcpt proc = proctools.spawnpty(cmd) proc.write(msg) proc.write("\n") proc.send_eof() proc.wait() return proc.exitstatus
def sendmail(self, From, rcpt_to, msg, mopts=None, rcptopts=None): from pycopia import proctools cmd = "/usr/sbin/sendmail" for rcpt in rcpt_to: cmd += ' "%s"' % rcpt proc = proctools.spawnpty(cmd) proc.write(msg) proc.write("\n") proc.send_eof() proc.wait() return proc.exitstatus
def runtest(self, testlist, environmentname="default", reportname=None, options=None): """Run a test using the external runtest program.""" if self.report_rx is not None: self._emit("message", "Test still running") return report = ReportForm() self.report_rx = clientserver.ReportReceiver(report) self._w.body = report if reportname: altreport = ",{}".format(reportname) else: altreport = "" tc = " ".join(testlist) if options: optlist = " ".join("--{}={!r}".format(*t) for t in options.items()) else: optlist = "" cmd = "runtest --reportname=remote{} --environmentname={} {} {}".format( altreport, environmentname, optlist, tc) proctools.spawnpty(cmd, callback=self._test_end)
def get_vimvar(): from pycopia import proctools proc = proctools.spawnpty("vim") proc.write(":echo $VIM\r") proc.write(":exit\r") var = proc.read() proc.wait() proctools.remove_procmanager() start = 0 s = [] for c in var: if not start: if c != "/": # find start of path. continue else: start = 1 if c.isalnum() or c.isspace() or c == "/": s.append(c) else: break return "".join(s)
def get_vimvar(): from pycopia import proctools proc = proctools.spawnpty("vim") proc.write(":echo $VIM\r") proc.write(":exit\r") var = proc.read() proc.wait() proctools.remove_procmanager() start = 0 s = [] for c in var: if not start: if c != "/": # find start of path. continue else: start = 1 if c.isalnum() or c.isspace() or c == "/": s.append(c) else: break return "".join(s)