Esempio n. 1
    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 (trailing slashes).

        The is_local param is flag indicating if the paths should be
        interpreted as local or remote paths. """

        # non-trailing slash paths should just work
        if len(path) == 0 or path[-1] != "/":
            return [path]

        # make a function to test if a pattern matches any files
        if is_local:
            def glob_matches_files(path, pattern):
                return len(glob.glob(path + pattern)) > 0
            def glob_matches_files(path, pattern):
                result ="ls \"%s\"%s" % (utils.sh_escape(path),
                                  stdout_tee=None, ignore_status=True)
                return result.exit_status == 0

        # take a set of globs that cover all files, and see which are needed
        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]
            return [utils.scp_remote_escape(path) + pattern
                    for pattern in patterns]
Esempio n. 2
 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))