checker.py: Take a path to a binary proto instead of repo root.
- Right now it assumes the binary proto is under
"generated/config.binaryproto" in the repo root. Taking a full
path to the binary proto will give more flexibility if projects or
programs don't follow this convention.
- If a repo root path is passed, still handle this by appending
"generated/config.binaryproto". Eventually, this behavior will
be removed (it raises a warning right now).
BUG=chromium:1058057
TEST=python unittests
Change-Id: I46f823939b063f79eb7c5230423536c94e4af164
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/config/+/2090284
Tested-by: Andrew Lamb <andrewlamb@chromium.org>
Reviewed-by: Sean McAllister <smcallis@google.com>
Reviewed-by: David Burger <dburger@chromium.org>
Commit-Queue: Andrew Lamb <andrewlamb@chromium.org>
diff --git a/payload_utils/checker/io_utils.py b/payload_utils/checker/io_utils.py
index 7c665c3..1567c9a 100644
--- a/payload_utils/checker/io_utils.py
+++ b/payload_utils/checker/io_utils.py
@@ -4,18 +4,29 @@
"""IO-related helper functions."""
import os
+import warnings
from bindings.api import config_bundle_pb2
-def read_repo_config(repo_path: str) -> config_bundle_pb2.ConfigBundle:
- """Reads a binary proto from a file in a program or project repo.
+def read_config(path: str) -> config_bundle_pb2.ConfigBundle:
+ """Reads a binary proto from a file.
+
+ Note that passing paths to repo roots is deprecated, and will raise a
+ warning. If a repo root is passed, it is assumed the config can be found at
+ 'generated/config.binaryproto'.
Args:
- repo_path: Path to the root of the program or project repo.
+ path: Path to the binary proto. See note above about deprecated repo
+ root behavior.
"""
+ if os.path.isdir(path):
+ warnings.warn(
+ ('Passing a path to a repo root is deprecated, please pass a full path'
+ ' to a binary proto. Path: {}'.format(path)), FutureWarning)
+ path = os.path.join(path, 'generated', 'config.binaryproto')
+
project_config = config_bundle_pb2.ConfigBundle()
- with open(os.path.join(repo_path, 'generated', 'config.binaryproto'),
- 'rb') as f:
+ with open(os.path.join(path), 'rb') as f:
project_config.ParseFromString(f.read())
return project_config