legacy: improve readability of ogGetImageInfo helper functions

Change the name of the helper functions used when getting opengnsys
image information (legacy ogGetImageInfo bash script). As of now the
process consist of decompressing the image file with lzop and feeding
that output to partclone.info.

Prefer a more explicit function name rather than "process_image_*"

Add comment about skipping the first two lines of partclone.info output.
Usually, partclone.info starts printing out these two lines that are not
related to the partclone image information:

	Partclone v0.3.23 http://partclone.org
	Showing info of image (-)

As long as partclone.info output doesn't change we'll be fine, but we
should not depend on human readable output. This might change in the
future (i.e. adding json output format to partclone.info).
more_events
Jose M. Guisado 2023-03-07 12:34:29 +01:00
parent c9a3a763dd
commit b58ccca48b
1 changed files with 13 additions and 14 deletions

View File

@ -50,14 +50,13 @@ def fill_imageinfo(line, image_info):
image_info.datasize = device_size
def process_output_partcloneinfo(output):
def image_info_from_partclone(partclone_output):
"""
Parses image information from partclone.info output.
Returns an ImageInfo object.
Return an ImageInfo object from partclone.info output.
"""
image_info = ImageInfo()
for n, line in enumerate(output.split('\n')):
for n, line in enumerate(partclone_output.split('\n')):
# Ignore first two lines of partclone.info output
if n < 2:
continue
if image_info.datasize and image_info.filesystem:
@ -72,14 +71,14 @@ def process_output_partcloneinfo(output):
return image_info
def process_image_partcloneinfo(filename):
def run_lzop_partcloneinfo(image_path):
"""
Decompress using lzop and executes partclone.info to
fetch a partition image's information.
Run lzop to decompress an OpenGnsys partition image, feed
lzop output to a partclone.info subprocess.
Returns partclone.info stdout and stderr.
Return the partclone.info subprocess output.
"""
cmd1 = f'{shutil.which("lzop")} -dc {filename}'
cmd1 = f'{shutil.which("lzop")} -dc {image_path}'
cmd2 = f'{shutil.which("partclone.info")} -s -'
args1 = shlex.split(cmd1)
args2 = shlex.split(cmd2)
@ -90,12 +89,12 @@ def process_image_partcloneinfo(filename):
p2_out, p2_err = p2.communicate()
if p2.returncode != 0:
raise ValueError('Unable to process image {filename}')
raise ValueError('Unable to process image {image_path}')
return p2_out
def ogGetImageInfo(filename):
def ogGetImageInfo(image_path):
"""
Obtain filesystem and device size information of an OpenGnsys partition
image.
@ -115,8 +114,8 @@ def ogGetImageInfo(filename):
>>> image_info.clonator
>>> 'PARTCLONE'
"""
out = process_image_partcloneinfo(filename)
image_info = process_output_partcloneinfo(out)
partclone_output = run_lzop_partcloneinfo(image_path)
image_info = image_info_from_partclone(partclone_output)
return image_info