Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 1 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | """IO-related helper functions.""" |
| 5 | |
Andrew Lamb | 5d13205 | 2020-05-29 14:49:06 -0600 | [diff] [blame^] | 6 | import json |
| 7 | import pathlib |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 8 | |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 9 | from chromiumos.config.payload import config_bundle_pb2 |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 10 | |
David Burger | 54f704e | 2020-04-30 13:33:47 -0600 | [diff] [blame] | 11 | from google.protobuf import json_format |
| 12 | |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 13 | |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 14 | def read_config(path: str) -> config_bundle_pb2.ConfigBundle: |
David Burger | 54f704e | 2020-04-30 13:33:47 -0600 | [diff] [blame] | 15 | """Reads a json proto from a file. |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 16 | |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 17 | Args: |
David Burger | 54f704e | 2020-04-30 13:33:47 -0600 | [diff] [blame] | 18 | path: Path to the json proto. See note above about deprecated repo |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 19 | root behavior. |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 20 | """ |
David Burger | 54f704e | 2020-04-30 13:33:47 -0600 | [diff] [blame] | 21 | project_config = config_bundle_pb2.ConfigBundle() |
| 22 | with open(path, 'r') as f: |
| 23 | json_format.Parse(f.read(), project_config) |
| 24 | return project_config |
Andrew Lamb | 5d13205 | 2020-05-29 14:49:06 -0600 | [diff] [blame^] | 25 | |
| 26 | |
| 27 | def read_model_sku_json(factory_dir: pathlib.Path) -> dict: |
| 28 | """Reads and parses the model_sku.json file. |
| 29 | |
| 30 | Args: |
| 31 | factory_dir: Path to a project's factory dir. |
| 32 | """ |
| 33 | with open(factory_dir.joinpath('generated', 'model_sku.json')) as f: |
| 34 | return json.load(f) |