Merge "Support generating secondary OTAs from directories" into main
This commit is contained in:
@@ -460,48 +460,51 @@ def GetTargetFilesZipForSecondaryImages(input_file, skip_postinstall=False):
|
|||||||
target_file = common.MakeTempFile(prefix="targetfiles-", suffix=".zip")
|
target_file = common.MakeTempFile(prefix="targetfiles-", suffix=".zip")
|
||||||
target_zip = zipfile.ZipFile(target_file, 'w', allowZip64=True)
|
target_zip = zipfile.ZipFile(target_file, 'w', allowZip64=True)
|
||||||
|
|
||||||
with zipfile.ZipFile(input_file, 'r', allowZip64=True) as input_zip:
|
fileslist = []
|
||||||
infolist = input_zip.infolist()
|
for (root, dirs, files) in os.walk(input_file):
|
||||||
|
root = root.lstrip(input_file).lstrip("/")
|
||||||
|
fileslist.extend([os.path.join(root, d) for d in dirs])
|
||||||
|
fileslist.extend([os.path.join(root, d) for d in files])
|
||||||
|
|
||||||
input_tmp = common.UnzipTemp(input_file, UNZIP_PATTERN)
|
input_tmp = input_file
|
||||||
for info in infolist:
|
for filename in fileslist:
|
||||||
unzipped_file = os.path.join(input_tmp, *info.filename.split('/'))
|
unzipped_file = os.path.join(input_tmp, *filename.split('/'))
|
||||||
if info.filename == 'IMAGES/system_other.img':
|
if filename == 'IMAGES/system_other.img':
|
||||||
common.ZipWrite(target_zip, unzipped_file, arcname='IMAGES/system.img')
|
common.ZipWrite(target_zip, unzipped_file, arcname='IMAGES/system.img')
|
||||||
|
|
||||||
# Primary images and friends need to be skipped explicitly.
|
# Primary images and friends need to be skipped explicitly.
|
||||||
elif info.filename in ('IMAGES/system.img',
|
elif filename in ('IMAGES/system.img',
|
||||||
'IMAGES/system.map'):
|
'IMAGES/system.map'):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Copy images that are not in SECONDARY_PAYLOAD_SKIPPED_IMAGES.
|
# Copy images that are not in SECONDARY_PAYLOAD_SKIPPED_IMAGES.
|
||||||
elif info.filename.startswith(('IMAGES/', 'RADIO/')):
|
elif filename.startswith(('IMAGES/', 'RADIO/')):
|
||||||
image_name = os.path.basename(info.filename)
|
image_name = os.path.basename(filename)
|
||||||
if image_name not in ['{}.img'.format(partition) for partition in
|
if image_name not in ['{}.img'.format(partition) for partition in
|
||||||
SECONDARY_PAYLOAD_SKIPPED_IMAGES]:
|
SECONDARY_PAYLOAD_SKIPPED_IMAGES]:
|
||||||
common.ZipWrite(target_zip, unzipped_file, arcname=info.filename)
|
common.ZipWrite(target_zip, unzipped_file, arcname=filename)
|
||||||
|
|
||||||
# Skip copying the postinstall config if requested.
|
# Skip copying the postinstall config if requested.
|
||||||
elif skip_postinstall and info.filename == POSTINSTALL_CONFIG:
|
elif skip_postinstall and filename == POSTINSTALL_CONFIG:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif info.filename.startswith('META/'):
|
elif filename.startswith('META/'):
|
||||||
# Remove the unnecessary partitions for secondary images from the
|
# Remove the unnecessary partitions for secondary images from the
|
||||||
# ab_partitions file.
|
# ab_partitions file.
|
||||||
if info.filename == AB_PARTITIONS:
|
if filename == AB_PARTITIONS:
|
||||||
with open(unzipped_file) as f:
|
with open(unzipped_file) as f:
|
||||||
partition_list = f.read().splitlines()
|
partition_list = f.read().splitlines()
|
||||||
partition_list = [partition for partition in partition_list if partition
|
partition_list = [partition for partition in partition_list if partition
|
||||||
and partition not in SECONDARY_PAYLOAD_SKIPPED_IMAGES]
|
and partition not in SECONDARY_PAYLOAD_SKIPPED_IMAGES]
|
||||||
common.ZipWriteStr(target_zip, info.filename,
|
common.ZipWriteStr(target_zip, filename,
|
||||||
'\n'.join(partition_list))
|
'\n'.join(partition_list))
|
||||||
# Remove the unnecessary partitions from the dynamic partitions list.
|
# Remove the unnecessary partitions from the dynamic partitions list.
|
||||||
elif (info.filename == 'META/misc_info.txt' or
|
elif (filename == 'META/misc_info.txt' or
|
||||||
info.filename == DYNAMIC_PARTITION_INFO):
|
filename == DYNAMIC_PARTITION_INFO):
|
||||||
modified_info = GetInfoForSecondaryImages(unzipped_file)
|
modified_info = GetInfoForSecondaryImages(unzipped_file)
|
||||||
common.ZipWriteStr(target_zip, info.filename, modified_info)
|
common.ZipWriteStr(target_zip, filename, modified_info)
|
||||||
else:
|
else:
|
||||||
common.ZipWrite(target_zip, unzipped_file, arcname=info.filename)
|
common.ZipWrite(target_zip, unzipped_file, arcname=filename)
|
||||||
|
|
||||||
common.ZipClose(target_zip)
|
common.ZipClose(target_zip)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user