diff options
author | Joel Galenson <jgalenson@google.com> | 2021-09-03 19:02:29 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-09-03 19:02:29 +0000 |
commit | 1e5ed2ec89b3c3b7901ad3024b6acffb4745aedb (patch) | |
tree | b1c8cf9b9c2130a3f90ba8a143ade0096f268cc8 | |
parent | 55b2d6a61a098ba1502b17c0dd7d408f25eb2f1f (diff) | |
parent | 416484d1cc52bc04ad36cec44e6271c51de49603 (diff) | |
download | external_updater-1e5ed2ec89b3c3b7901ad3024b6acffb4745aedb.tar.gz |
Allow the check command to use globs. am: 0c510259d8 am: a5c12bb9a7 am: c8f54824e9 am: 93b2f8f308 am: 416484d1cc
Original change: https://android-review.googlesource.com/c/platform/tools/external_updater/+/1817659
Change-Id: I8473137bbed571359711ce307a704fa3037c54e3
-rw-r--r-- | external_updater.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/external_updater.py b/external_updater.py index b4091c4..7518380 100644 --- a/external_updater.py +++ b/external_updater.py @@ -197,23 +197,33 @@ def _list_all_metadata() -> Iterator[str]: dirs.sort(key=lambda d: d.lower()) +def get_paths(paths: List[str]) -> List[str]: + """Expand paths via globs.""" + # We want to use glob to get all the paths, so we first convert to absolute. + abs_paths = [fileutils.get_absolute_project_path(Path(path)) + for path in paths] + return [path for abs_path in abs_paths + for path in sorted(glob.glob(str(abs_path)))] + + +def write_json(json_file: str, results: Dict[str, Dict[str, str]]) -> List[str]: + """Output a JSON report.""" + with Path(json_file).open('w') as res_file: + json.dump(results, res_file, sort_keys=True, indent=4) + + def check(args: argparse.Namespace) -> None: """Handler for check command.""" - paths = _list_all_metadata() if args.all else args.paths + paths = _list_all_metadata() if args.all else get_paths(args.paths) results = check_and_update_path(args, paths, False, args.delay) if args.json_output is not None: - with Path(args.json_output).open('w') as res_file: - json.dump(results, res_file, sort_keys=True, indent=4) + write_json(args.json_output, results) def update(args: argparse.Namespace) -> None: """Handler for update command.""" - # We want to use glob to get all the paths, so we first convert to absolute. - abs_paths = [fileutils.get_absolute_project_path(Path(path)) - for path in args.paths] - all_paths = sorted([path for abs_path in abs_paths - for path in glob.glob(str(abs_path))]) + all_paths = get_paths(args.paths) # Remove excluded paths. excludes = set() if args.exclude is None else set(args.exclude) filtered_paths = [path for path in all_paths @@ -222,8 +232,7 @@ def update(args: argparse.Namespace) -> None: results = check_and_update_path(args, filtered_paths, True, 0) if args.json_output is not None: - with Path(args.json_output).open('w') as res_file: - json.dump(results, res_file, sort_keys=True, indent=4) + write_json(args.json_output, results) def parse_args() -> argparse.Namespace: |