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 | |
| 6 | import os |
| 7 | |
Andrew Lamb | 03a7786 | 2020-04-09 15:46:39 -0600 | [diff] [blame^] | 8 | from config.payload import config_bundle_pb2 |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 9 | |
| 10 | |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 11 | def read_config(path: str) -> config_bundle_pb2.ConfigBundle: |
| 12 | """Reads a binary proto from a file. |
| 13 | |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 14 | Args: |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 15 | path: Path to the binary proto. See note above about deprecated repo |
| 16 | root behavior. |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 17 | """ |
| 18 | project_config = config_bundle_pb2.ConfigBundle() |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 19 | with open(os.path.join(path), 'rb') as f: |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 20 | project_config.ParseFromString(f.read()) |
| 21 | return project_config |