1#!/usr/bin/env python3
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
18import argparse
19import json
20import sys
21
22def PrintFileNames(path):
23  with open(path) as jf:
24    data = json.load(jf)
25  for line in data:
26    print(line["Name"])
27
28def PrintCanonicalList(path):
29  with open(path) as jf:
30    data = json.load(jf)
31  for line in data:
32    print(f"{line['Size']:12d}  {line['Name']}")
33
34def 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()
42
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")
51
52if __name__ == '__main__':
53  main()
54