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.""" 11 12import glob 13from pathlib import Path 14 15from materialize import MZ_ROOT, spawn 16 17 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) 21 22 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)) 25 26 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 36 37 38def _file_list_output_to_list(output: str) -> list[str]: 39 files = output.split("\n") 40 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-0560a51e825af34b5-1/materialize/deploy')) -> list[str]:
def
resolve_path_with_wildcard( path: str, root_dir: str | pathlib.Path = PosixPath('/var/lib/buildkite-agent/builds/buildkite-15f2293-i-0560a51e825af34b5-1/materialize/deploy')) -> set[str]:
def
resolve_paths_with_wildcard( paths: set[str], root_dir: str | pathlib.Path = PosixPath('/var/lib/buildkite-agent/builds/buildkite-15f2293-i-0560a51e825af34b5-1/materialize/deploy')) -> set[str]: