Flutter Engine
The Flutter Engine
convert_manifest_to_json.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright 2013 The Flutter Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6'''Reads the contents of a kernel manifest generated by the build and
7 converts it to a format suitable for distribution_entries
8'''
9
10import argparse
11import collections
12import json
13import os
14import sys
15
16Entry = collections.namedtuple('Entry', ['source', 'dest'])
17
18
19def collect(path_prefix, lines):
20 '''Reads the kernel manifest and creates an array of Entry objects.
21 - lines: a list of lines from the manifest
22 '''
23 entries = []
24 for line in lines:
25 values = line.split("=", 1)
26 entries.append(Entry(source=path_prefix + values[1], dest=values[0]))
27
28 return entries
29
30
31def main():
32 parser = argparse.ArgumentParser(description=__doc__)
33 parser.add_argument(
34 '--path_prefix', help='Directory path containing the manifest entry sources', required=True
35 )
36 parser.add_argument('--input', help='Path to original manifest', required=True)
37 parser.add_argument('--output', help='Path to the updated json file', required=True)
38 args = parser.parse_args()
39
40 with open(args.input, 'r') as input_file:
41 contents = input_file.read().splitlines()
42
43 entries = collect(args.path_prefix, contents)
44
45 if entries is None:
46 return 1
47
48 with open(args.output, 'w') as output_file:
49 json.dump([e._asdict() for e in entries],
50 output_file,
51 indent=2,
52 sort_keys=True,
53 separators=(',', ': '))
54
55 return 0
56
57
58if __name__ == '__main__':
59 sys.exit(main())
def collect(path_prefix, lines)
Definition: main.py:1