Merge "releasetools: Make _GetPropertyFilesString public"
This commit is contained in:
@@ -1026,7 +1026,7 @@ class PropertyFiles(object):
|
|||||||
A string with placeholders for the metadata offset/size info, e.g.
|
A string with placeholders for the metadata offset/size info, e.g.
|
||||||
"payload.bin:679:343,payload_properties.txt:378:45,metadata: ".
|
"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):
|
class InsufficientSpaceException(Exception):
|
||||||
pass
|
pass
|
||||||
@@ -1055,7 +1055,7 @@ class PropertyFiles(object):
|
|||||||
InsufficientSpaceException: If the reserved length is insufficient to hold
|
InsufficientSpaceException: If the reserved length is insufficient to hold
|
||||||
the final string.
|
the final string.
|
||||||
"""
|
"""
|
||||||
result = self._GetPropertyFilesString(input_zip, reserve_space=False)
|
result = self.GetPropertyFilesString(input_zip, reserve_space=False)
|
||||||
if len(result) > reserved_length:
|
if len(result) > reserved_length:
|
||||||
raise self.InsufficientSpaceException(
|
raise self.InsufficientSpaceException(
|
||||||
'Insufficient reserved space: reserved={}, actual={}'.format(
|
'Insufficient reserved space: reserved={}, actual={}'.format(
|
||||||
@@ -1074,12 +1074,22 @@ class PropertyFiles(object):
|
|||||||
Raises:
|
Raises:
|
||||||
AssertionError: On finding a mismatch.
|
AssertionError: On finding a mismatch.
|
||||||
"""
|
"""
|
||||||
actual = self._GetPropertyFilesString(input_zip)
|
actual = self.GetPropertyFilesString(input_zip)
|
||||||
assert actual == expected, \
|
assert actual == expected, \
|
||||||
"Mismatching streaming metadata: {} vs {}.".format(actual, expected)
|
"Mismatching streaming metadata: {} vs {}.".format(actual, expected)
|
||||||
|
|
||||||
def _GetPropertyFilesString(self, zip_file, reserve_space=False):
|
def GetPropertyFilesString(self, zip_file, reserve_space=False):
|
||||||
"""Constructs the property-files string per request."""
|
"""
|
||||||
|
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):
|
def ComputeEntryOffsetSize(name):
|
||||||
"""Computes the zip entry offset and size."""
|
"""Computes the zip entry offset and size."""
|
||||||
|
@@ -774,8 +774,7 @@ class PropertyFilesTest(unittest.TestCase):
|
|||||||
zip_file = self.construct_zip_package(entries)
|
zip_file = self.construct_zip_package(entries)
|
||||||
property_files = TestPropertyFiles()
|
property_files = TestPropertyFiles()
|
||||||
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
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)
|
zip_fp, reserve_space=False)
|
||||||
streaming_metadata = property_files.Finalize(zip_fp, len(raw_metadata))
|
streaming_metadata = property_files.Finalize(zip_fp, len(raw_metadata))
|
||||||
tokens = self._parse_property_files_string(streaming_metadata)
|
tokens = self._parse_property_files_string(streaming_metadata)
|
||||||
@@ -798,8 +797,7 @@ class PropertyFilesTest(unittest.TestCase):
|
|||||||
property_files = TestPropertyFiles()
|
property_files = TestPropertyFiles()
|
||||||
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
||||||
# First get the raw metadata string (i.e. without padding space).
|
# 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)
|
zip_fp, reserve_space=False)
|
||||||
raw_length = len(raw_metadata)
|
raw_length = len(raw_metadata)
|
||||||
|
|
||||||
@@ -833,8 +831,7 @@ class PropertyFilesTest(unittest.TestCase):
|
|||||||
property_files = TestPropertyFiles()
|
property_files = TestPropertyFiles()
|
||||||
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
||||||
# First get the raw metadata string (i.e. without padding space).
|
# 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)
|
zip_fp, reserve_space=False)
|
||||||
|
|
||||||
# Should pass the test if verification passes.
|
# Should pass the test if verification passes.
|
||||||
@@ -891,8 +888,7 @@ class StreamingPropertyFilesTest(PropertyFilesTest):
|
|||||||
zip_file = self.construct_zip_package(entries)
|
zip_file = self.construct_zip_package(entries)
|
||||||
property_files = StreamingPropertyFiles()
|
property_files = StreamingPropertyFiles()
|
||||||
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
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)
|
zip_fp, reserve_space=False)
|
||||||
streaming_metadata = property_files.Finalize(zip_fp, len(raw_metadata))
|
streaming_metadata = property_files.Finalize(zip_fp, len(raw_metadata))
|
||||||
tokens = self._parse_property_files_string(streaming_metadata)
|
tokens = self._parse_property_files_string(streaming_metadata)
|
||||||
@@ -915,8 +911,7 @@ class StreamingPropertyFilesTest(PropertyFilesTest):
|
|||||||
property_files = StreamingPropertyFiles()
|
property_files = StreamingPropertyFiles()
|
||||||
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
||||||
# First get the raw metadata string (i.e. without padding space).
|
# 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)
|
zip_fp, reserve_space=False)
|
||||||
|
|
||||||
# Should pass the test if verification passes.
|
# Should pass the test if verification passes.
|
||||||
@@ -1051,8 +1046,7 @@ class AbOtaPropertyFilesTest(PropertyFilesTest):
|
|||||||
zip_file = self.construct_zip_package_withValidPayload(with_metadata=True)
|
zip_file = self.construct_zip_package_withValidPayload(with_metadata=True)
|
||||||
property_files = AbOtaPropertyFiles()
|
property_files = AbOtaPropertyFiles()
|
||||||
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
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)
|
zip_fp, reserve_space=False)
|
||||||
property_files_string = property_files.Finalize(zip_fp, len(raw_metadata))
|
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)
|
zip_file = self.construct_zip_package_withValidPayload(with_metadata=True)
|
||||||
property_files = AbOtaPropertyFiles()
|
property_files = AbOtaPropertyFiles()
|
||||||
with zipfile.ZipFile(zip_file, 'r') as zip_fp:
|
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)
|
zip_fp, reserve_space=False)
|
||||||
|
|
||||||
property_files.Verify(zip_fp, raw_metadata)
|
property_files.Verify(zip_fp, raw_metadata)
|
||||||
@@ -1101,8 +1094,7 @@ class NonAbOtaPropertyFilesTest(PropertyFilesTest):
|
|||||||
zip_file = self.construct_zip_package(entries)
|
zip_file = self.construct_zip_package(entries)
|
||||||
property_files = NonAbOtaPropertyFiles()
|
property_files = NonAbOtaPropertyFiles()
|
||||||
with zipfile.ZipFile(zip_file) as zip_fp:
|
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)
|
zip_fp, reserve_space=False)
|
||||||
property_files_string = property_files.Finalize(zip_fp, len(raw_metadata))
|
property_files_string = property_files.Finalize(zip_fp, len(raw_metadata))
|
||||||
tokens = self._parse_property_files_string(property_files_string)
|
tokens = self._parse_property_files_string(property_files_string)
|
||||||
@@ -1119,8 +1111,7 @@ class NonAbOtaPropertyFilesTest(PropertyFilesTest):
|
|||||||
zip_file = self.construct_zip_package(entries)
|
zip_file = self.construct_zip_package(entries)
|
||||||
property_files = NonAbOtaPropertyFiles()
|
property_files = NonAbOtaPropertyFiles()
|
||||||
with zipfile.ZipFile(zip_file) as zip_fp:
|
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)
|
zip_fp, reserve_space=False)
|
||||||
|
|
||||||
property_files.Verify(zip_fp, raw_metadata)
|
property_files.Verify(zip_fp, raw_metadata)
|
||||||
|
Reference in New Issue
Block a user