예제 #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
파일: remote.py 프로젝트: McLutzifer/Python
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 def _path_getgid(self, fn):
     return self._session.run("stat -c '%g,%G' " + shquote(fn))[1].strip().split(",")
예제 #23
0
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 def _path_delete(self, fn):
     self._session.run("rm -rf %s" % (shquote(fn),))
예제 #33
0
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: AntoineD/plumbum
 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
파일: remote.py 프로젝트: tigrawap/plumbum
 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(",")