• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Fetches artifacts from Android Build."""
2import argparse
3import os
4
5from treble.fetcher import fetcher_lib
6
7
8def main():
9  parser = argparse.ArgumentParser(
10      description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
11  parser.add_argument(
12      '--json_keyfile',
13      help='JSON keyfile containing credentials. '
14      '(Default: Use default credential file)')
15  parser.add_argument(
16      '--target', required=True, help='The target name to download from.')
17  parser.add_argument(
18      '--artifact',
19      action='append',
20      default=[],
21      help='The name of the artifact to download. '
22      'Can be specified multiple times.')
23  parser.add_argument(
24      '--regex',
25      action='append',
26      default=[],
27      help='A regex pattern to compare to the names of the artifact to '
28      'download. Can be specified multiple times.')
29
30  parser.add_argument(
31      '--out_dir',
32      default='out/artifacts/',
33      help='Path to store fetched artifact to.')
34
35  group = parser.add_mutually_exclusive_group(required=True)
36  group.add_argument(
37      '--branch', help='Download from the latest build of this branch.')
38  group.add_argument('--build_id', help='Download from the specified build.')
39
40  args = parser.parse_args()
41  client = fetcher_lib.create_client_from_json_keyfile(
42      json_keyfile_name=args.json_keyfile)
43
44  build_id = fetcher_lib.get_latest_build_id(
45      client=client, branch=args.branch,
46      target=args.target) if args.branch else args.build_id
47
48  for artifact in args.artifact:
49    fetcher_lib.fetch_artifact(
50        client=client,
51        build_id=build_id,
52        target=args.target,
53        resource_id=artifact,
54        dest=os.path.join(args.out_dir, artifact))
55
56  for re in args.regex:
57    fetcher_lib.fetch_artifacts(
58        client=client,
59        build_id=build_id,
60        target=args.target,
61        pattern=re,
62        out_dir=args.out_dir)
63
64
65if __name__ == '__main__':
66  main()
67