fd = open(filename, "r+b")
try:
for name, handler, num_args, desc in cmds:
@@ -151,11 +159,14 @@ def main(filename, cmd, args):
def usage():
- print("Usage: %s <file> <cmd> [<arg>, ...]" % sys.argv[0])
+ print("Usage: %s <file> <cmd> [<arg>, ...] [<key>, ...]" %
sys.argv[0])
print("")
print("Supported commands:")
for name, handler, num_args, desc in cmds:
print(" %-20s - %s" % (name, desc))
+ print("")
+ print("Supported keys:")
+ print(" %-20s - %s" % ('-j', 'Dump in JSON format'))
if __name__ == '__main__':
diff --git a/tests/qemu-iotests/qcow2_format.py
b/tests/qemu-iotests/qcow2_format.py
index 2c78d46..e0e14b5 100644
--- a/tests/qemu-iotests/qcow2_format.py
+++ b/tests/qemu-iotests/qcow2_format.py
@@ -109,7 +109,7 @@ class Qcow2Struct(metaclass=Qcow2StructMeta):
self.__dict__ = dict((field[2], values[i])
for i, field in enumerate(self.fields))
- def dump(self):
+ def dump(self, dump_json=None):
for f in self.fields:
value = self.__dict__[f[2]]
if isinstance(f[1], str):
@@ -145,8 +145,8 @@ class Qcow2BitmapExt(Qcow2Struct):
[Qcow2BitmapDirEntry(fd, cluster_size=self.cluster_size)
for _ in range(self.nb_bitmaps)]
- def dump(self):
- super().dump()
+ def dump(self, dump_json=None):
strange to make None the default value for boolean. Why not just False?
Also, why not call it just "json"? We are already in "dump" context,
no needs to add prefix to the name.
+ super().dump(dump_json)
for entry in self.bitmap_directory:
print()
entry.dump()
How will it work? You are interleaving json dump and non-json?
Looking at this, I think that json and non-json dumps has more
differences than similarities, and it probably simpler to make a
separate function dump_json.. But I'm absolutely against an option, if
it will be done consistently.
@@ -190,7 +190,7 @@ class Qcow2BitmapDirEntry(Qcow2Struct):
self.bitmap_table = Qcow2BitmapTable(raw_table=table,
cluster_size=self.cluster_size)
- def dump(self):
+ def dump(self, dump_json=None):
print(f'{"Bitmap name":<25} {self.name}')
super(Qcow2BitmapDirEntry, self).dump()
self.bitmap_table.dump()
Here the new option just not passed to the nested dump() calls..
@@ -291,13 +291,13 @@ class QcowHeaderExtension(Qcow2Struct):
data_str = '<binary>'
self.data_str = data_str
- def dump(self):
+ def dump(self, dump_json=None):
super().dump()
if self.obj is None:
print(f'{"data":<25} {self.data_str}')
else:
- self.obj.dump()
+ self.obj.dump(dump_json)
@classmethod
def create(cls, magic, data):
@@ -396,8 +396,8 @@ class QcowHeader(Qcow2Struct):
buf = buf[0:header_bytes-1]
fd.write(buf)
- def dump_extensions(self):
+ def dump_extensions(self, dump_json=None):
for ex in self.extensions:
print('Header extension:')
- ex.dump()
+ ex.dump(dump_json)
print()