def list_file(self, commit, path, history=None, include_contents=None):
        """
        Lists the files in a directory.

        Params:

        * commit: A tuple, string, or `Commit` object representing the commit.
        * path: The path to the directory.
        * history: An optional int that indicates to return jobs from
        historical versions of pipelines. Semantics are:
         0: Return jobs from the current version of the pipeline or pipelines.
         1: Return the above and jobs from the next most recent version
         2: etc.
        -1: Return jobs from all historical versions.
        * include_contents: An optional bool. If `True`, file contents are
        included.
        """

        req = proto.ListFileRequest(
            file=proto.File(commit=commit_from(commit), path=path),
            history=history,
            full=include_contents,
        )

        return self.stub.ListFileStream(req, metadata=self.metadata)
Ejemplo n.º 2
0
    def list_file(self, commit, path, recursive=False):
        """
        Lists the files in a directory.

        Params:
        * commit: A tuple, string, or Commit object representing the commit.
        * path: The path to the directory.
        * recursive: If True, continue listing the files for sub-directories.
        """
        req = proto.ListFileRequest(
            file=proto.File(commit=commit_from(commit), path=path))
        res = self.stub.ListFile(req, metadata=self.metadata)
        file_infos = res.file_info

        if recursive:
            dirs = [f for f in file_infos if f.file_type == proto.DIR]
            files = [f for f in file_infos if f.file_type == proto.FILE]
            return sum(
                [self.list_file(commit, d.file.path, recursive) for d in dirs],
                files)

        return list(file_infos)