diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2023-03-07 12:34:29 +0100 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2023-03-10 11:26:42 +0100 |
commit | b58ccca48b6cecf357dbccc2ef744d1ea7c01939 (patch) | |
tree | 03cfada06aefeab2a057e3dd8c73edd239580167 /src/utils/legacy.py | |
parent | c9a3a763ddf91ccf3d382a29996c4f2f5e767d9a (diff) |
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).
Diffstat (limited to 'src/utils/legacy.py')
-rw-r--r-- | src/utils/legacy.py | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/utils/legacy.py b/src/utils/legacy.py index 51d98f3..6e191fc 100644 --- a/src/utils/legacy.py +++ b/src/utils/legacy.py @@ -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 |