Cole Faust | e0fab08 | 2022-10-24 18:36:22 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Sasha Levitskiy | 83561d1 | 2016-10-10 22:48:10 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2016 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the 'License'); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an 'AS IS' BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
Cole Faust | e0fab08 | 2022-10-24 18:36:22 -0700 | [diff] [blame] | 18 | import argparse |
| 19 | import json |
| 20 | import sys |
Sasha Levitskiy | 83561d1 | 2016-10-10 22:48:10 -0700 | [diff] [blame] | 21 | |
| 22 | def PrintFileNames(path): |
| 23 | with open(path) as jf: |
| 24 | data = json.load(jf) |
| 25 | for line in data: |
| 26 | print(line["Name"]) |
| 27 | |
| 28 | def PrintCanonicalList(path): |
| 29 | with open(path) as jf: |
| 30 | data = json.load(jf) |
| 31 | for line in data: |
Cole Faust | e0fab08 | 2022-10-24 18:36:22 -0700 | [diff] [blame] | 32 | print(f"{line['Size']:12d} {line['Name']}") |
Sasha Levitskiy | 83561d1 | 2016-10-10 22:48:10 -0700 | [diff] [blame] | 33 | |
Cole Faust | e0fab08 | 2022-10-24 18:36:22 -0700 | [diff] [blame] | 34 | def main(): |
| 35 | parser = argparse.ArgumentParser() |
| 36 | parser.add_argument("-n", action="store_true", |
| 37 | help="produces list of files only") |
| 38 | parser.add_argument("-c", action="store_true", |
| 39 | help="produces classic installed-files.txt") |
| 40 | parser.add_argument("json_files_list") |
| 41 | args = parser.parse_args() |
Sasha Levitskiy | 83561d1 | 2016-10-10 22:48:10 -0700 | [diff] [blame] | 42 | |
Cole Faust | e0fab08 | 2022-10-24 18:36:22 -0700 | [diff] [blame] | 43 | if args.n and args.c: |
| 44 | sys.exit("Cannot specify both -n and -c") |
| 45 | elif args.n: |
| 46 | PrintFileNames(args.json_files_list) |
| 47 | elif args.c: |
| 48 | PrintCanonicalList(args.json_files_list) |
| 49 | else: |
| 50 | sys.exit("No conversion option specified") |
Sasha Levitskiy | 83561d1 | 2016-10-10 22:48:10 -0700 | [diff] [blame] | 51 | |
| 52 | if __name__ == '__main__': |
Cole Faust | e0fab08 | 2022-10-24 18:36:22 -0700 | [diff] [blame] | 53 | main() |