示例#1
0
 def move(self, dst):
     if isinstance(dst, RemotePath) and dst.remote is not self.remote:
         raise TypeError("dst points to a different remote machine")
     elif not isinstance(dst, six.string_types):
         raise TypeError(
             "dst must be a string or a RemotePath (to the same remote machine)"
         )
     self.remote._session.run("mv %s %s" % (shquote(self), shquote(dst)))
示例#2
0
 def copy(self, dst, override = False):
     if isinstance(dst, RemotePath):
         if dst.remote is not self.remote:
             raise TypeError("dst points to a different remote machine")
     elif not isinstance(dst, str):
         raise TypeError("dst must be a string or a RemotePath (to the same remote machine)", repr(dst))
     if override:
         if isinstance(dst, str):
             dst = RemotePath(self.remote, dst)
         dst.remove()
     self.remote._session.run("cp -r %s %s" % (shquote(self), shquote(dst)))
示例#3
0
 def copy(self, dst, override = False):
     if isinstance(dst, RemotePath):
         if dst.remote is not self.remote:
             raise TypeError("dst points to a different remote machine")
     elif not isinstance(dst, str):
         raise TypeError("dst must be a string or a RemotePath (to the same remote machine)", repr(dst))
     if override:
         if isinstance(dst, str):
             dst = RemotePath(self.remote, dst)
         dst.remove()
     self.remote._session.run("cp -r %s %s" % (shquote(self), shquote(dst)))
示例#4
0
 def popen(self, args, ssh_opts=(), **kwargs):
     cmdline = []
     cmdline.extend(ssh_opts)
     cmdline.append(self._fqhost)
     remote_cmdline = []
     if shell_cmd:
         formulate = arg.formulate() if isinstance(
             arg, BaseCommand) else (shquote(arg), )
         quote = shquote
     else:
         formulate = quote = lambda x: x
     if args:
         if hasattr(self, "env"):
             envdelta = self.env.getdelta()
             remote_cmdline.extend(["cd", quote(str(self.cwd)), "&&"])
             if envdelta:
                 remote_cmdline.append("env")
                 remote_cmdline.extend("%s=%s" % (quote(k), quote(v))
                                       for k, v in envdelta.items())
         if isinstance(args, (tuple, list)):
             for arg in args:
                 remote_cmdline.extend(formulate(arg))
         else:
             remote_cmdline.extend(formulate(args))
     if self._remote_shell:
         cmdline.append(self._remote_shell)
         if remote_cmdline:
             cmdline.append('-c')
             cmdline.append(quote(' '.join(remote_cmdline)))
     else:
         cmdline.extend(remote_cmdline)
     return self._ssh_command[tuple(cmdline)].popen(**kwargs)
示例#5
0
 def _path_getgid(self, fn):
     stat_cmd = (
         "stat -c '%g,%G' "
         if self.uname not in ("Darwin", "FreeBSD")
         else "stat -f '%g,%Sg' "
     )
     return self._session.run(stat_cmd + shquote(fn))[1].strip().split(",")
示例#6
0
 def _stat(self, path):
     rc, out, _ = self.remote._session.run(
         "stat -c '%F,%f,%i,%d,%h,%u,%g,%s,%X,%Y,%Z' " + shquote(path), retcode = None)
     if rc != 0:
         return None
     statres = out.strip().split(",")
     mode = statres.pop(0).lower()
     return mode, os.stat_result(statres)
示例#7
0
 def upload(self, src, dst):
     if isinstance(src, RemotePath):
         raise TypeError("src of upload cannot be %r" % (src,))
     if isinstance(dst, LocalPath):
         raise TypeError("dst of upload cannot be %r" % (dst,))
     if isinstance(dst, RemotePath) and dst.remote != self:
         raise TypeError("dst %r points to a different remote machine" % (dst,))
     self._scp_command(src, "%s:%s" % (self._fqhost, shquote(dst)))
示例#8
0
 def _stat(self, path):
     rc, out, _ = self.remote._session.run(
         "stat -c '%F,%f,%i,%d,%h,%u,%g,%s,%X,%Y,%Z' " + shquote(path), retcode = None)
     if rc != 0:
         return None
     statres = out.strip().split(",")
     mode = statres.pop(0).lower()
     return mode, os.stat_result(statres)
示例#9
0
 def upload(self, src, dst):
     if isinstance(src, RemotePath):
         raise TypeError("src of upload cannot be %r" % (src, ))
     if isinstance(dst, LocalPath):
         raise TypeError("dst of upload cannot be %r" % (dst, ))
     if isinstance(dst, RemotePath) and dst.remote != self:
         raise TypeError("dst %r points to a different remote machine" %
                         (dst, ))
     self._scp_command(src, "%s:%s" % (self._fqhost, shquote(dst)))
示例#10
0
 def _path_stat(self, fn):
     rc, out, _ = self._session.run(
         "stat -c '%F,%f,%i,%d,%h,%u,%g,%s,%X,%Y,%Z' " + shquote(fn),
         retcode=None)
     if rc != 0:
         return None
     statres = out.strip().split(",")
     text_mode = statres.pop(0).lower()
     res = StatRes(statres)
     res.text_mode = text_mode
     return res
示例#11
0
 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)
示例#12
0
 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))
示例#13
0
 def upload(self, src, dst):
     if isinstance(src, RemotePath):
         raise TypeError("src of upload cannot be {!r}".format(src))
     if isinstance(dst, LocalPath):
         raise TypeError("dst of upload cannot be {!r}".format(dst))
     if isinstance(dst, RemotePath) and dst.remote != self:
         raise TypeError(
             "dst {!r} points to a different remote machine".format(dst))
     if IS_WIN32:
         src = self._translate_drive_letter(src)
         dst = self._translate_drive_letter(dst)
     self._scp_command(src, "{}:{}".format(self._fqhost, shquote(dst)))
示例#14
0
 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))
示例#15
0
 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
示例#16
0
 def chown(self, owner=None, group=None, recursive=None):
     args = ["chown"]
     if recursive is None:
         recursive = self.isdir()
     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(self))
     self.remote._session.run(" ".join(args))
示例#17
0
 def chown(self, owner=None, group=None, recursive=None):
     args = ["chown"]
     if recursive is None:
         recursive = self.isdir()
     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(self))
     self.remote._session.run(" ".join(args))
示例#18
0
 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)
示例#19
0
    def which(self, progname):
        """Looks up a program in the ``PATH``. If the program is not found, raises
        :class:`CommandNotFound <plumbum.commands.CommandNotFound>`

        :param progname: The program's name. Note that if underscores (``_``) are present
                         in the name, and the exact name is not found, they will be replaced
                         by hyphens (``-``) and the name will be looked up again

        :returns: A :class:`RemotePath <plumbum.local_machine.RemotePath>`
        """
        alternatives = [progname]
        if "_" in progname:
            alternatives.append(progname.replace("_", "-"))
        for name in alternatives:
            rc, out, _ = self._session.run("which %s" % (shquote(name),), retcode = None)
            if rc == 0:
                return self.path(out.strip())

        raise CommandNotFound(progname, self.env.path)
示例#20
0
    def which(self, progname):
        """Looks up a program in the ``PATH``. If the program is not found, raises
        :class:`CommandNotFound <plumbum.commands.CommandNotFound>`

        :param progname: The program's name. Note that if underscores (``_``) are present
                         in the name, and the exact name is not found, they will be replaced
                         by hyphens (``-``) and the name will be looked up again

        :returns: A :class:`RemotePath <plumbum.local_machine.RemotePath>`
        """
        alternatives = [progname]
        if "_" in progname:
            alternatives.append(progname.replace("_", "-"))
        for name in alternatives:
            rc, out, _ = self._session.run("which %s" % (shquote(name), ),
                                           retcode=None)
            if rc == 0:
                return self.path(out.strip())

        raise CommandNotFound(progname, self.env.path)
示例#21
0
 def popen(self, args, ssh_opts=(), env=None, cwd=None, **kwargs):
     cmdline = []
     cmdline.extend(ssh_opts)
     cmdline.append(self._fqhost)
     if args:
         envdelta = {}
         if hasattr(self, "env"):
             envdelta.update(self.env.getdelta())
         if env:
             envdelta.update(env)
         if cwd is None:
             cwd = getattr(self, "cwd", None)
         if cwd:
             cmdline.extend(["cd", str(cwd), "&&"])
         if envdelta:
             cmdline.append("env")
             cmdline.extend("{}={}".format(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)
示例#22
0
 def _path_getgid(self, fn):
     return self._session.run("stat -c '%g,%G' " + shquote(fn))[1].strip().split(",")
示例#23
0
 def __setitem__(self, name, value):
     BaseEnv.__setitem__(self, name, value)
     self.remote._session.run("export %s=%s" % (name, shquote(value)))
示例#24
0
 def mkdir(self):
     self.remote._session.run("mkdir -p %s" % (shquote(self),))
示例#25
0
 def move(self, dst):
     if isinstance(dst, RemotePath) and dst.remote is not self.remote:
         raise TypeError("dst points to a different remote machine")
     elif not isinstance(dst, str):
         raise TypeError("dst must be a string or a RemotePath (to the same remote machine)")
     self.remote._session.run("mv %s %s" % (shquote(self), shquote(dst)))
示例#26
0
 def _path_chmod(self, mode, fn):
     self._session.run("chmod %o %s" % (mode, shquote(fn)))
示例#27
0
 def _path_delete(self, fn):
     self._session.run("rm -rf %s" % (shquote(fn), ))
示例#28
0
 def _path_getgid(self, fn):
     stat_cmd = "stat -c '%g,%G' " if self.uname != 'Darwin' else "stat -f '%g,%Sg' "
     return self._session.run(stat_cmd + shquote(fn))[1].strip().split(",")
示例#29
0
 def _path_listdir(self, fn):
     files = self._session.run("ls -a %s" % (shquote(fn), ))[1].splitlines()
     files.remove(".")
     files.remove("..")
     return files
示例#30
0
 def chdir(self, newdir):
     """Changes the current working directory to the given one"""
     self.remote._session.run("cd %s" % (shquote(newdir), ))
     self._path = self.remote._session.run("pwd")[1].strip()
示例#31
0
 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(",")
示例#32
0
 def _path_delete(self, fn):
     self._session.run("rm -rf %s" % (shquote(fn),))
示例#33
0
 def _path_copy(self, src, dst):
     self._session.run("cp -r %s %s" % (shquote(src), shquote(dst)))
示例#34
0
 def _path_move(self, src, dst):
     self._session.run("mv %s %s" % (shquote(src), shquote(dst)))
示例#35
0
 def update(self, *args, **kwargs):
     BaseEnv.update(self, *args, **kwargs)
     self.remote._session.run("export " +
         " ".join("%s=%s" % (k, shquote(v)) for k, v in self.getdict().items()))
示例#36
0
 def _path_copy(self, src, dst):
     self._session.run("cp -r %s %s" % (shquote(src), shquote(dst)))
示例#37
0
 def delete(self):
     if not self.exists():
         return
     self.remote._session.run("rm -rf %s" % (shquote(self),))
示例#38
0
 def _path_mkdir(self, fn):
     self._session.run("mkdir -p %s" % (shquote(fn), ))
示例#39
0
 def _path_chmod(self, mode, fn):
     self._session.run("chmod %o %s" % (mode, shquote(fn)))
示例#40
0
 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)
示例#41
0
 def chdir(self, newdir):
     """Changes the current working directory to the given one"""
     self.remote._session.run("cd %s" % (shquote(newdir),))
     self._path = self.remote._session.run("pwd")[1].strip()
示例#42
0
 def _path_link(self, src, dst, symlink):
     self._session.run(
         "ln %s %s %s" %
         ("-s" if symlink else "", shquote(src), shquote(dst)))
示例#43
0
 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)
示例#44
0
 def __setitem__(self, name, value):
     BaseEnv.__setitem__(self, name, value)
     self.remote._session.run("export %s=%s" % (name, shquote(value)))
示例#45
0
 def _path_listdir(self, fn):
     files = self._session.run("ls -a %s" % (shquote(fn),))[1].splitlines()
     files.remove(".")
     files.remove("..")
     return files
示例#46
0
 def update(self, *args, **kwargs):
     BaseEnv.update(self, *args, **kwargs)
     self.remote._session.run("export " +
                              " ".join("%s=%s" % (k, shquote(v))
                                       for k, v in self.getdict().items()))
示例#47
0
 def _path_stat(self, fn):
     rc, out, _ = self._session.run("stat -c '%F,%f,%i,%d,%h,%u,%g,%s,%X,%Y,%Z' " + 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
示例#48
0
文件: remote.py 项目: mwek/plumbum
 def chdir(self, newdir):
     """Changes the current working directory to the given one"""
     self.remote._session.run("cd %s" % (shquote(newdir), ))
     if hasattr(self.remote, '_cwd'):
         del self.remote._cwd
     return self.__class__(self.remote)
示例#49
0
 def _path_move(self, src, dst):
     self._session.run("mv %s %s" % (shquote(src), shquote(dst)))
示例#50
0
文件: remote.py 项目: eswald/dotfiles
 def _path_getgid(self, fn):
     stat_cmd = "stat -c '%g,%G' " if self.uname not in ('Darwin', 'FreeBSD') else "stat -f '%g,%Sg' "
     return self._session.run(stat_cmd + shquote(fn))[1].strip().split(",")
示例#51
0
 def _path_mkdir(self, fn):
     self._session.run("mkdir -p %s" % (shquote(fn),))
示例#52
0
 def gid(self):
     gid, name = self.remote._session.run("stat -c '%g,%G' " + shquote(self))[1].strip().split(",")
     return FSUser(int(gid), name)
示例#53
0
 def chdir(self, newdir):
     """Changes the current working directory to the given one"""
     self.remote._session.run("cd %s" % (shquote(newdir),))
     del self.remote._cwd
     return self.__class__(self.remote)
示例#54
0
 def chmod(self, mode):
     args = ["chmod", '%o' % mode, shquote(self)]
     self.remote._session.run(" ".join(args))
示例#55
0
 def _path_link(self, src, dst, symlink):
     self._session.run("ln -s %s %s" % ("-s" if symlink else "", shquote(src), shquote(dst)))
示例#56
0
 def _path_getgid(self, fn):
     return self._session.run("stat -c '%g,%G' " +
                              shquote(fn))[1].strip().split(",")
示例#57
0
 def uid(self):
     uid, name = self.remote._session.run("stat -c '%u,%U' " + shquote(self))[1].strip().split(",")
     return FSUser(int(uid), name)
示例#58
0
 def _path_getuid(self, fn):
     stat_cmd = "stat -c '%u,%U' " if self.uname != "Darwin" else "stat -f '%u,%Su' "
     return self._session.run(stat_cmd + shquote(fn))[1].strip().split(",")