qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v10 08/10] qcow2.py: Introduce '-j' key to dump in JSON forma


From: Andrey Shinkevich
Subject: Re: [PATCH v10 08/10] qcow2.py: Introduce '-j' key to dump in JSON format
Date: Thu, 16 Jul 2020 17:44:37 +0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.9.0

On 16.07.2020 17:38, Vladimir Sementsov-Ogievskiy wrote:
16.07.2020 17:36, Andrey Shinkevich wrote:
On 16.07.2020 13:20, Vladimir Sementsov-Ogievskiy wrote:
14.07.2020 00:36, Andrey Shinkevich wrote:
Add the command key to the qcow2.py arguments list to dump QCOW2
metadata in JSON format. Here is the suggested way to do that. The
implementation of the dump in JSON format is in the patch that follows.

Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
  tests/qemu-iotests/qcow2.py        | 19 +++++++++++++++----
  tests/qemu-iotests/qcow2_format.py | 16 ++++++++--------
  2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py
index 0910e6a..7402279 100755
...
@@ -134,6 +137,11 @@ cmds = [
      def main(filename, cmd, args):
+    global dump_json
+    dump_json = '-j' in sys.argv
+    if dump_json:
+        sys.argv.remove('-j')
+        args.remove('-j')

I'd prefer to access sys.argv in one place (in "if __name__ ...").


In case we move the block

     global dump_json
     dump_json = '-j' in sys.argv

         if dump_json:
             sys.argv.remove('-j')

from main() to the body of "if __name__ == '__main__'"

we get the following error -

"SyntaxError: name 'dump_json' is assigned to before global declaration"

you don't need "global" declaration outside of a function



OK, thanks. However, if we want to parse more keys in future, will we do all that parsing in the body of "if __name__ == '__main__'"?


Andrey




reply via email to

[Prev in Thread] Current Thread [Next in Thread]