misc.python.materialize.file_util

File utilities.

 1# Copyright Materialize, Inc. and contributors. All rights reserved.
 2#
 3# Use of this software is governed by the Business Source License
 4# included in the LICENSE file at the root of this repository.
 5#
 6# As of the Change Date specified in that file, in accordance with
 7# the Business Source License, use of this software will be governed
 8# by the Apache License, Version 2.0.
 9
10"""File utilities."""
11import glob
12from pathlib import Path
13
14from materialize import MZ_ROOT, spawn
15
16
17def get_recursive_file_list(path: str | Path, root_dir: Path = MZ_ROOT) -> list[str]:
18    result = spawn.capture(["find", path, "-type", "f"], cwd=root_dir)
19    return _file_list_output_to_list(result)
20
21
22def resolve_path_with_wildcard(path: str, root_dir: str | Path = MZ_ROOT) -> set[str]:
23    return set(glob.glob(path, root_dir=root_dir))
24
25
26def resolve_paths_with_wildcard(
27    paths: set[str], root_dir: str | Path = MZ_ROOT
28) -> set[str]:
29    result = set()
30
31    for path in paths:
32        result = result.union(resolve_path_with_wildcard(path, root_dir))
33
34    return result
35
36
37def _file_list_output_to_list(output: str) -> list[str]:
38    files = output.split("\n")
39    return [file for file in files if file != ""]
def get_recursive_file_list( path: str | pathlib.Path, root_dir: pathlib.Path = PosixPath('/var/lib/buildkite-agent/builds/buildkite-15f2293-i-0fd014cc4b97c0422-1/materialize/deploy')) -> list[str]:
18def get_recursive_file_list(path: str | Path, root_dir: Path = MZ_ROOT) -> list[str]:
19    result = spawn.capture(["find", path, "-type", "f"], cwd=root_dir)
20    return _file_list_output_to_list(result)
def resolve_path_with_wildcard( path: str, root_dir: str | pathlib.Path = PosixPath('/var/lib/buildkite-agent/builds/buildkite-15f2293-i-0fd014cc4b97c0422-1/materialize/deploy')) -> set[str]:
23def resolve_path_with_wildcard(path: str, root_dir: str | Path = MZ_ROOT) -> set[str]:
24    return set(glob.glob(path, root_dir=root_dir))
def resolve_paths_with_wildcard( paths: set[str], root_dir: str | pathlib.Path = PosixPath('/var/lib/buildkite-agent/builds/buildkite-15f2293-i-0fd014cc4b97c0422-1/materialize/deploy')) -> set[str]:
27def resolve_paths_with_wildcard(
28    paths: set[str], root_dir: str | Path = MZ_ROOT
29) -> set[str]:
30    result = set()
31
32    for path in paths:
33        result = result.union(resolve_path_with_wildcard(path, root_dir))
34
35    return result