releasetools: Add dict-like setter to BuildInfo.
BuildInfo already has dict-like getters. This CL adds the matching
setter method to keep it backward compatible with device-specific
scripts that expect a dict.
It also adds items() method that allows iterating the items.
Bug: 111087332
Test: python -m unittest test_ota_from_target_files.BuildInfoTest
Test: Generate an incremental OTA that sets info_dict in device-specific
releasetools script.
Change-Id: Idd033f98a9186740f9da1a300d4c2bdddd9c1345
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index a8c821f..0e25c7e 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -250,12 +250,14 @@
def __init__(self, info_dict, oem_dicts):
"""Initializes a BuildInfo instance with the given dicts.
+ Note that it only wraps up the given dicts, without making copies.
+
Arguments:
info_dict: The build-time info dict.
oem_dicts: A list of OEM dicts (which is parsed from --oem_settings). Note
that it always uses the first dict to calculate the fingerprint or the
device name. The rest would be used for asserting OEM properties only
- (e.g. one package can be installed on one of these devices).
+ (e.g. one package can be installed on one of these devices).
"""
self.info_dict = info_dict
self.oem_dicts = oem_dicts
@@ -289,9 +291,15 @@
def __getitem__(self, key):
return self.info_dict[key]
+ def __setitem__(self, key, value):
+ self.info_dict[key] = value
+
def get(self, key, default=None):
return self.info_dict.get(key, default)
+ def items(self):
+ return self.info_dict.items()
+
def GetBuildProp(self, prop):
"""Returns the inquired build property."""
try: