Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _path_stat(self, fn):
if self.uname not in ('Darwin', 'FreeBSD'):
stat_cmd = "stat -c '%F,%f,%i,%d,%h,%u,%g,%s,%X,%Y,%Z' "
else:
stat_cmd = "stat -f '%HT,%Xp,%i,%d,%l,%u,%g,%z,%a,%m,%c' "
rc, out, _ = self._session.run(stat_cmd + shquote(fn), retcode=None)
if rc != 0:
return None
statres = out.strip().split(",")
text_mode = statres.pop(0).lower()
res = StatRes((int(statres[0], 16), ) + tuple(
int(sr) for sr in statres[1:]))
res.text_mode = text_mode
return res
def _path_getuid(self, fn):
stat_cmd = "stat -c '%u,%U' " if self.uname not in (
'Darwin', 'FreeBSD') else "stat -f '%u,%Su' "
return self._session.run(stat_cmd + shquote(fn))[1].strip().split(",")
def _path_move(self, src, dst):
self._session.run("mv %s %s" % (shquote(src), shquote(dst)))
def popen(self, args, ssh_opts=(), **kwargs):
cmdline = []
cmdline.extend(ssh_opts)
cmdline.append(self._fqhost)
if args and hasattr(self, "env"):
envdelta = self.env.getdelta()
cmdline.extend(["cd", str(self.cwd), "&&"])
if envdelta:
cmdline.append("env")
cmdline.extend("%s=%s" % (k, shquote(v)) for k, v in envdelta.items())
if isinstance(args, (tuple, list)):
cmdline.extend(args)
else:
cmdline.append(args)
return self._ssh_command[tuple(cmdline)].popen(**kwargs)
def download(self, src, dst):
if isinstance(src, LocalPath):
raise TypeError("src of download cannot be %r" % (src, ))
if isinstance(src, RemotePath) and src.remote != self:
raise TypeError(
"src %r points to a different remote machine" % (src, ))
if isinstance(dst, RemotePath):
raise TypeError("dst of download cannot be %r" % (dst, ))
if IS_WIN32:
src = self._translate_drive_letter(src)
dst = self._translate_drive_letter(dst)
self._scp_command("%s:%s" % (self._fqhost, shquote(src)), dst)
def _path_chown(self, fn, owner, group, recursive):
args = ["chown"]
if recursive:
args.append("-R")
if owner is not None and group is not None:
args.append("%s:%s" % (owner, group))
elif owner is not None:
args.append(str(owner))
elif group is not None:
args.append(":%s" % (group, ))
args.append(shquote(fn))
self._session.run(" ".join(args))
def _path_chmod(self, mode, fn):
self._session.run("chmod %o %s" % (mode, shquote(fn)))
def _path_link(self, src, dst, symlink):
self._session.run(
"ln %s %s %s" % ("-s"
if symlink else "", shquote(src), shquote(dst)))
def _path_copy(self, src, dst):
self._session.run("cp -r %s %s" % (shquote(src), shquote(dst)))
def _path_mkdir(self, fn, mode=None, minus_p=True):
p_str = "-p " if minus_p else ""
cmd = "mkdir %s%s" % (p_str, shquote(fn))
self._session.run(cmd)