Merge "releasetools: Make _GetPropertyFilesString public"

This commit is contained in:
Zhomart Mukhamejanov 2018-05-04 21:17:54 +00:00 committed by Gerrit Code Review
commit f6806a7ff3
2 changed files with 24 additions and 23 deletions

View File

@ -1026,7 +1026,7 @@ class PropertyFiles(object):
A string with placeholders for the metadata offset/size info, e.g.
"payload.bin:679:343,payload_properties.txt:378:45,metadata: ".
"""
return self._GetPropertyFilesString(input_zip, reserve_space=True)
return self.GetPropertyFilesString(input_zip, reserve_space=True)
class InsufficientSpaceException(Exception):
pass
@ -1055,7 +1055,7 @@ class PropertyFiles(object):
InsufficientSpaceException: If the reserved length is insufficient to hold
the final string.
"""
result = self._GetPropertyFilesString(input_zip, reserve_space=False)
result = self.GetPropertyFilesString(input_zip, reserve_space=False)
if len(result) > reserved_length:
raise self.InsufficientSpaceException(
'Insufficient reserved space: reserved={}, actual={}'.format(
@ -1074,12 +1074,22 @@ class PropertyFiles(object):
Raises:
AssertionError: On finding a mismatch.
"""
actual = self._GetPropertyFilesString(input_zip)
actual = self.GetPropertyFilesString(input_zip)
assert actual == expected, \
"Mismatching streaming metadata: {} vs {}.".format(actual, expected)
def _GetPropertyFilesString(self, zip_file, reserve_space=False):
"""Constructs the property-files string per request."""
def GetPropertyFilesString(self, zip_file, reserve_space=False):
"""
Constructs the property-files string per request.
Args:
zip_file: The input ZIP file.
reserved_length: The reserved length of the property-files string.
Returns:
A property-files string including the metadata offset/size info, e.g.
"payload.bin:679:343,payload_properties.txt:378:45,metadata: ".
"""
def ComputeEntryOffsetSize(name):
"""Computes the zip entry offset and size."""

View File

@ -774,8 +774,7 @@ class PropertyFilesTest(unittest.TestCase):
zip_file = self.construct_zip_package(entries)
property_files = TestPropertyFiles()
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
# pylint: disable=protected-access
raw_metadata = property_files._GetPropertyFilesString(
raw_metadata = property_files.GetPropertyFilesString(
zip_fp, reserve_space=False)
streaming_metadata = property_files.Finalize(zip_fp, len(raw_metadata))
tokens = self._parse_property_files_string(streaming_metadata)
@ -798,8 +797,7 @@ class PropertyFilesTest(unittest.TestCase):
property_files = TestPropertyFiles()
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
# First get the raw metadata string (i.e. without padding space).
# pylint: disable=protected-access
raw_metadata = property_files._GetPropertyFilesString(
raw_metadata = property_files.GetPropertyFilesString(
zip_fp, reserve_space=False)
raw_length = len(raw_metadata)
@ -833,8 +831,7 @@ class PropertyFilesTest(unittest.TestCase):
property_files = TestPropertyFiles()
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
# First get the raw metadata string (i.e. without padding space).
# pylint: disable=protected-access
raw_metadata = property_files._GetPropertyFilesString(
raw_metadata = property_files.GetPropertyFilesString(
zip_fp, reserve_space=False)
# Should pass the test if verification passes.
@ -891,8 +888,7 @@ class StreamingPropertyFilesTest(PropertyFilesTest):
zip_file = self.construct_zip_package(entries)
property_files = StreamingPropertyFiles()
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
# pylint: disable=protected-access
raw_metadata = property_files._GetPropertyFilesString(
raw_metadata = property_files.GetPropertyFilesString(
zip_fp, reserve_space=False)
streaming_metadata = property_files.Finalize(zip_fp, len(raw_metadata))
tokens = self._parse_property_files_string(streaming_metadata)
@ -915,8 +911,7 @@ class StreamingPropertyFilesTest(PropertyFilesTest):
property_files = StreamingPropertyFiles()
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
# First get the raw metadata string (i.e. without padding space).
# pylint: disable=protected-access
raw_metadata = property_files._GetPropertyFilesString(
raw_metadata = property_files.GetPropertyFilesString(
zip_fp, reserve_space=False)
# Should pass the test if verification passes.
@ -1051,8 +1046,7 @@ class AbOtaPropertyFilesTest(PropertyFilesTest):
zip_file = self.construct_zip_package_withValidPayload(with_metadata=True)
property_files = AbOtaPropertyFiles()
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
# pylint: disable=protected-access
raw_metadata = property_files._GetPropertyFilesString(
raw_metadata = property_files.GetPropertyFilesString(
zip_fp, reserve_space=False)
property_files_string = property_files.Finalize(zip_fp, len(raw_metadata))
@ -1067,8 +1061,7 @@ class AbOtaPropertyFilesTest(PropertyFilesTest):
zip_file = self.construct_zip_package_withValidPayload(with_metadata=True)
property_files = AbOtaPropertyFiles()
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
# pylint: disable=protected-access
raw_metadata = property_files._GetPropertyFilesString(
raw_metadata = property_files.GetPropertyFilesString(
zip_fp, reserve_space=False)
property_files.Verify(zip_fp, raw_metadata)
@ -1101,8 +1094,7 @@ class NonAbOtaPropertyFilesTest(PropertyFilesTest):
zip_file = self.construct_zip_package(entries)
property_files = NonAbOtaPropertyFiles()
with zipfile.ZipFile(zip_file) as zip_fp:
# pylint: disable=protected-access
raw_metadata = property_files._GetPropertyFilesString(
raw_metadata = property_files.GetPropertyFilesString(
zip_fp, reserve_space=False)
property_files_string = property_files.Finalize(zip_fp, len(raw_metadata))
tokens = self._parse_property_files_string(property_files_string)
@ -1119,8 +1111,7 @@ class NonAbOtaPropertyFilesTest(PropertyFilesTest):
zip_file = self.construct_zip_package(entries)
property_files = NonAbOtaPropertyFiles()
with zipfile.ZipFile(zip_file) as zip_fp:
# pylint: disable=protected-access
raw_metadata = property_files._GetPropertyFilesString(
raw_metadata = property_files.GetPropertyFilesString(
zip_fp, reserve_space=False)
property_files.Verify(zip_fp, raw_metadata)