From f6341d69c348178f8487df76141f980f9a2d701a Mon Sep 17 00:00:00 2001 From: Ross Lagerwall Date: Mon, 4 Dec 2023 16:32:56 +0000 Subject: [PATCH] disktool: Optionally dump old/new partitions during commit If log=True is passed to commit, dump the old and new partition tables before applying the changes. At the same time, fix up the dump code to handle GPT partition tables. Signed-off-by: Ross Lagerwall (cherry picked from commit 7f5877188337915091738e88222593488b0e8039) --- disktools.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/disktools.py b/disktools.py index 4bc0fa7c..544204f0 100644 --- a/disktools.py +++ b/disktools.py @@ -703,6 +703,8 @@ def items(self): yield number, partition def commit(self, dryrun=False, log=False): + if log: + self.dump() self.writePartitionTable(dryrun, log) if not dryrun: # Update the revert point so this tool can be used repeatedly @@ -717,12 +719,12 @@ def dump(self): for number, partition in sorted(self.origPartitions.items()): output += "Old partition "+str(number)+":" for k, v in sorted(partition.items()): - output += ' '+k+'='+((k == 'id') and hex(v) or str(v)) + output += ' '+k+'='+((k == 'id' and type(v) == int) and hex(v) or str(v)) output += "\n" for number, partition in sorted(self.partitions.items()): output += "New partition "+str(number)+":" for k, v in sorted(partition.items()): - output += ' '+k+'='+((k == 'id') and hex(v) or str(v)) + output += ' '+k+'='+((k == 'id' and type(v) == int) and hex(v) or str(v)) output += "\n" logger.log(output)