sparse_img.py --get_partition_size return size of partition

Also, move code from build_super_image.py to sparse_img.py.

Test: sparse_img.py on sparse and non-sparse images
Bug: 122377935
Change-Id: Ie91fdfdbb54298ea27eb20d1b5363aeb1470356e
This commit is contained in:
Yifan Hong
2019-04-04 10:57:39 -07:00
parent bd4301e190
commit 7ad83b634e
2 changed files with 24 additions and 9 deletions

View File

@@ -58,16 +58,8 @@ logger = logging.getLogger(__name__)
UNZIP_PATTERN = ["IMAGES/*", "META/*"]
def GetPartitionSizeFromImage(img):
try:
simg = sparse_img.SparseImage(img)
return simg.blocksize * simg.total_blocks
except ValueError:
return os.path.getsize(img)
def GetArgumentsForImage(partition, group, image=None):
image_size = GetPartitionSizeFromImage(image) if image else 0
image_size = sparse_img.GetImagePartitionSize(image) if image else 0
cmd = ["--partition",
"{}:readonly:{}:{}".format(partition, image_size, group)]