• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import argparse
4import os
5import sys
6import zipfile
7from typing import List
8
9def list_files_in_zip(zipfile_path: str) -> List[str]:
10    with zipfile.ZipFile(zipfile_path, 'r') as zf:
11        return zf.namelist()
12
13def main():
14    parser = argparse.ArgumentParser(
15        description='Lists paths to all files inside an EXTRA_INSTALL_ZIPS zip file relative to a partition staging directory. '
16        'This script is just a helper because its difficult to implement this logic in make code.'
17    )
18    parser.add_argument('staging_dir',
19        help='Path to the partition staging directory')
20    parser.add_argument('extra_install_zips', nargs='*',
21        help='The value of EXTRA_INSTALL_ZIPS from make. '
22        'It should be a list of primary_file:extraction_dir:zip_file trios. '
23        'The primary file will be ignored by this script, you should ensure that '
24        'the list of trios given to this script is already filtered by relevant primary files.')
25    args = parser.parse_args()
26
27    staging_dir = args.staging_dir.removesuffix('/') + '/'
28
29    for zip_trio in args.extra_install_zips:
30        _, d, z = zip_trio.split(':')
31        d = d.removesuffix('/') + '/'
32
33        if d.startswith(staging_dir):
34            d = os.path.relpath(d, staging_dir)
35            if d == '.':
36                d = ''
37            for f in list_files_in_zip(z):
38                print(os.path.join(d, f))
39
40
41if __name__ == "__main__":
42    main()
43