[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/15] qcow2_format.py: QcowHeaderExtension: add dump method
From: |
Eric Blake |
Subject: |
[PULL 11/15] qcow2_format.py: QcowHeaderExtension: add dump method |
Date: |
Tue, 9 Jun 2020 15:52:41 -0500 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Obviously, for-loop body in dump_extensions should be the dump method
of extension.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Message-Id: <20200606081806.23897-11-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
tests/qemu-iotests/qcow2_format.py | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/tests/qemu-iotests/qcow2_format.py
b/tests/qemu-iotests/qcow2_format.py
index 74a82f9263d4..d4ad5431b296 100644
--- a/tests/qemu-iotests/qcow2_format.py
+++ b/tests/qemu-iotests/qcow2_format.py
@@ -108,6 +108,17 @@ class QcowHeaderExtension:
self.length = length
self.data = data
+ def dump(self):
+ data = self.data[:self.length]
+ if all(c in string.printable.encode('ascii') for c in data):
+ data = f"'{ data.decode('ascii') }'"
+ else:
+ data = '<binary>'
+
+ print(f'{"magic":<25} {self.magic:#x}')
+ print(f'{"length":<25} {self.length}')
+ print(f'{"data":<25} {data}')
+
@classmethod
def create(cls, magic, data):
return QcowHeaderExtension(magic, len(data), data)
@@ -210,15 +221,6 @@ class QcowHeader(Qcow2Struct):
def dump_extensions(self):
for ex in self.extensions:
-
- data = ex.data[:ex.length]
- if all(c in string.printable.encode('ascii') for c in data):
- data = f"'{ data.decode('ascii') }'"
- else:
- data = '<binary>'
-
print('Header extension:')
- print(f'{"magic":<25} {ex.magic:#x}')
- print(f'{"length":<25} {ex.length}')
- print(f'{"data":<25} {data}')
+ ex.dump()
print()
--
2.27.0
- [PULL 03/15] qcow2.py: add licensing blurb, (continued)
- [PULL 03/15] qcow2.py: add licensing blurb, Eric Blake, 2020/06/09
- [PULL 04/15] qcow2.py: move qcow2 format classes to separate module, Eric Blake, 2020/06/09
- [PULL 10/15] qcow2_format.py: add field-formatting class, Eric Blake, 2020/06/09
- [PULL 07/15] qcow2_format.py: use modern string formatting, Eric Blake, 2020/06/09
- [PULL 09/15] qcow2_format.py: separate generic functionality of structure classes, Eric Blake, 2020/06/09
- [PULL 02/15] qcow2.py: python style fixes, Eric Blake, 2020/06/09
- [PULL 12/15] qcow2_format: refactor QcowHeaderExtension as a subclass of Qcow2Struct, Eric Blake, 2020/06/09
- [PULL 15/15] iotests: Fix 291 across more file systems, Eric Blake, 2020/06/09
- [PULL 06/15] qcow2_format.py: use tuples instead of lists for fields, Eric Blake, 2020/06/09
- [PULL 08/15] qcow2_format.py: use strings to specify c-type of struct fields, Eric Blake, 2020/06/09
- [PULL 11/15] qcow2_format.py: QcowHeaderExtension: add dump method,
Eric Blake <=
- [PULL 14/15] qcow2_format.py: dump bitmaps header extension, Eric Blake, 2020/06/09
- [PULL 13/15] qcow2: QcowHeaderExtension print names for extension magics, Eric Blake, 2020/06/09
- Re: [PULL 00/15] bitmaps patches for 2020-06-09, Peter Maydell, 2020/06/11