예제 #1
0
    def _make_rsync_compatible_globs(self, path, is_local):
        """
        given an rsync-style path, returns a list of globbed paths that will
        hopefully provide equivalent behaviour for scp. Does not support the
        full range of rsync pattern matching behaviour, only that exposed in
        the get/send_file interface.
        """
        if len(path) == 0 or path[-1] != "/":
            return [path]

        if is_local:
            def glob_matches_files(path, pattern):
                return len(glob.glob(path + pattern)) > 0
        else:
            def glob_matches_files(path, pattern):
                result = self.run("ls \"%s\"%s" %
                            (utils.sh_escape(path), pattern),
                            stdout_tee=None, ignore_status=True)
                return result.exit_status == 0
        patterns = ["*", ".[!.]*"]
        patterns = [p for p in patterns if glob_matches_files(path, p)]

        # convert them into a set of paths suitable for the commandline
        if is_local:
            return ["\"%s\"%s" % (utils.sh_escape(path), pattern)
                    for pattern in patterns]
        else:
            return [utils.scp_remote_escape(path) + pattern
                    for pattern in patterns]
예제 #2
0
    def _make_rsync_compatible_globs(self, path, is_local):
        """
        given an rsync-style path, returns a list of globbed paths that will hopefully
        provide equivalent behaviour for scp. Does not support the full range of rsync
        pattern matching behaviour, only that exposed in the get/send_file interface.
        """
        if len(path)==0 or path[-1]!= "/":
            return [path]

        if is_local:
            def glob_matches_files(path, pattern):
                return len(glob.glob(path + pattern)) > 0
        else:
            def glob_matches_files(path, pattern):
                result = self.run("ls \"%s\"%s" % (utils.sh_escape(path), pattern),
                            stdout_tee=None, ignore_status=True)
                return result.exit_status == 0
        patterns = ["*", ".[!.]*"]
        patterns = [p for p in patterns if glob_matches_files(path, p)]

        # convert them into a set of paths suitable for the commandline
        if is_local:
            return ["\"%s\"%s" % (utils.sh_escape(path), pattern) for pattern in patterns]
        else:
            return [utils.scp_remote_escape(path) + pattern for pattern in patterns]
예제 #3
0
 def _encode_remote_paths(self, paths, escape=True):
     """
     Given a list of file paths, encodes it as a single remote path, in the
     style used by rsync and scp.
     """
     if escape:
         paths = [utils.scp_remote_escape(path) for path in paths]
     return '%s@%s:"%s"' % (self.user, self.hostname, " ".join(paths))
예제 #4
0
 def _encode_remote_paths(self, paths, escape=True):
     """
     Given a list of file paths, encodes it as a single remote path, in the
     style used by rsync and scp.
     """
     if escape:
         paths = [utils.scp_remote_escape(path) for path in paths]
     return '%s@%s:"%s"' % (self.user, self.hostname, " ".join(paths))