Skip to contentSkip to conversation

scripts: Fix undefinited name 'file' error for python3

PATCH In review Han Han 2 participants 5 messages Nov 13, 2019 – Dec 4, 2019

lore
Share & tools
lore

Han Han

author
#0 lore raw

PATCH 1/1 scripts: Fix undefinited name 'file' error for python3

In python3, 'file' is no longer a keyword for file type object. So it will can error when run the scripts by python3:

$ python3 ./scripts/vmstate-static-checker.py -s 4.0.json -d 4.1.json
Traceback (most recent call last):
  File "./scripts/vmstate-static-checker.py", line 431, in <module>
    sys.exit(main())
  File "./scripts/vmstate-static-checker.py", line 378, in main
    parser.add_argument('-s', '--src', type=file, required=True,
NameError: name 'file' is not defined

Replace file type to argparse.FileType('r').

---
 scripts/vmstate-static-checker.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/vmstate-static-checker.py +2 -2
index d3467288..14f199a0 100755
@@ -375,9 +375,9 @@ def main():
     help_text = "Parse JSON-formatted vmstate dumps from QEMU in files SRC and DEST.  Checks whether migration from SRC to DEST QEMU versions would break based on the VMSTATE information contained within the JSON outputs.  The JSON output is created from a QEMU invocation with the -dump-vmstate parameter and a filename argument to it.  Other parameters to QEMU do not matter, except the -M (machine type) parameter."
 
     parser = argparse.ArgumentParser(description=help_text)
-    parser.add_argument('-s', '--src', type=file, required=True,
+    parser.add_argument('-s', '--src', type=argparse.FileType('r'), required=True,
                         help='json dump from src qemu')
-    parser.add_argument('-d', '--dest', type=file, required=True,
+    parser.add_argument('-d', '--dest', type=argparse.FileType('r'), required=True,
                         help='json dump from dest qemu')
     parser.add_argument('--reverse', required=False, default=False,
                         action='store_true',
Signature · 1 line
2.23.0
author
#1 lore raw

ping

Quoted 46 lines · Han Han

In python3, 'file' is no longer a keyword for file type object. So it will can error when run the scripts by python3:

$ python3 ./scripts/vmstate-static-checker.py -s 4.0.json -d 4.1.json
Traceback (most recent call last):
  File "./scripts/vmstate-static-checker.py", line 431, in <module>
    sys.exit(main())
  File "./scripts/vmstate-static-checker.py", line 378, in main
    parser.add_argument('-s', '--src', type=file, required=True,
NameError: name 'file' is not defined

Replace file type to argparse.FileType('r').

---
 scripts/vmstate-static-checker.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/vmstate-static-checker.py +0 -0
index d3467288..14f199a0 100755
@@ -375,9 +375,9 @@ def main():
     help_text = "Parse JSON-formatted vmstate dumps from QEMU in files

SRC and DEST. Checks whether migration from SRC to DEST QEMU versions would break based on the VMSTATE information contained within the JSON outputs. The JSON output is created from a QEMU invocation with the -dump-vmstate parameter and a filename argument to it. Other parameters to QEMU do not matter, except the -M (machine type) parameter."

parser = argparse.ArgumentParser(description=help_text)

scripts/vmstate-static-checker.py +1 -1
-    parser.add_argument('-s', '--src', type=file, required=True,
+    parser.add_argument('-s', '--src', type=argparse.FileType('r'),

required=True,
help='json dump from src qemu')

scripts/vmstate-static-checker.py +1 -1
-    parser.add_argument('-d', '--dest', type=file, required=True,
+    parser.add_argument('-d', '--dest', type=argparse.FileType('r'),

required=True,
help='json dump from dest qemu')
parser.add_argument('--reverse', required=False, default=False,
action='store_true',
--
2.23.0

Signature · 8 lines
Best regards,
-----------------------------------
Han Han
Quality Engineer
Redhat.

Email: [email protected]
Phone: +861065339333
author
#2 lore raw

Anyone help to review it?

Quoted 61 lines · Han Han

ping

Quoted 38 lines · Han Han

In python3, 'file' is no longer a keyword for file type object. So it will can error when run the scripts by python3:

$ python3 ./scripts/vmstate-static-checker.py -s 4.0.json -d 4.1.json
Traceback (most recent call last):
  File "./scripts/vmstate-static-checker.py", line 431, in <module>
    sys.exit(main())
  File "./scripts/vmstate-static-checker.py", line 378, in main
    parser.add_argument('-s', '--src', type=file, required=True,
NameError: name 'file' is not defined

Replace file type to argparse.FileType('r').

---
 scripts/vmstate-static-checker.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/vmstate-static-checker.py +0 -0
index d3467288..14f199a0 100755
@@ -375,9 +375,9 @@ def main():
     help_text = "Parse JSON-formatted vmstate dumps from QEMU in files

SRC and DEST. Checks whether migration from SRC to DEST QEMU versions would break based on the VMSTATE information contained within the JSON outputs. The JSON output is created from a QEMU invocation with the -dump-vmstate parameter and a filename argument to it. Other parameters to QEMU do not matter, except the -M (machine type) parameter."

parser = argparse.ArgumentParser(description=help_text)

scripts/vmstate-static-checker.py +1 -1
-    parser.add_argument('-s', '--src', type=file, required=True,
+    parser.add_argument('-s', '--src', type=argparse.FileType('r'),

required=True,
help='json dump from src qemu')

scripts/vmstate-static-checker.py +1 -1
-    parser.add_argument('-d', '--dest', type=file, required=True,
+    parser.add_argument('-d', '--dest', type=argparse.FileType('r'),
Quoted 8 lines

required=True,
help='json dump from dest qemu')
parser.add_argument('--reverse', required=False, default=False,
action='store_true',
--
2.23.0

--
Best regards,
-----------------------------------
Han Han
Quality Engineer
Redhat.

Email: [email protected]
Phone: +861065339333

Signature · 8 lines
Best regards,
-----------------------------------
Han Han
Quality Engineer
Redhat.

Email: [email protected]
Phone: +861065339333
#3 lore raw
Quoted 1 line · Han Han

Anyone help to review it?

Hi!

When sending patches to the qemu-devel mailing list, please always make sure to put the corresponding maintainers on CC:, otherwise your mails might get lost in the high traffic of the mailing list. For this case, it would have been good to CC: the "Migration" and "Python script" maintainers, see the corresponding sections of the MAINTAINERS file in the top most directory of the QEMU sources.

Anyway, it seems someone else ran into the same issue already, too, and
it got already fixed here:

https://git.qemu.org/?p=qemu.git;a=commitdiff;h=e8d0ac5801edda91412e5

Thomas

Quoted 67 lines

On Tue, Nov 26, 2019 at 1:54 PM Han Han <[email protected] <mailto:[email protected]>> wrote:

ping

On Wed, Nov 13, 2019 at 9:17 PM Han Han <[email protected] <mailto:[email protected]>> wrote:

In python3, 'file' is no longer a keyword for file type object. So it
will can error when run the scripts by python3:

$ python3 ./scripts/vmstate-static-checker.py -s 4.0.json -d 4.1.json
Traceback (most recent call last):
  File "./scripts/vmstate-static-checker.py", line 431, in <module> sys.exit(main())
  File "./scripts/vmstate-static-checker.py", line 378, in main parser.add_argument('-s', '--src', type=file, required=True,
NameError: name 'file' is not defined

Replace file type to argparse.FileType('r').

Signed-off-by Han Han <[email protected] <mailto:[email protected]>>

---
 scripts/vmstate-static-checker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/vmstate-static-checker.py b/scripts/vmstate-static-checker.py
index d3467288..14f199a0 100755
--- a/scripts/vmstate-static-checker.py
+++ b/scripts/vmstate-static-checker.py
@@ -375,9 +375,9 @@ def main():
     help_text = "Parse JSON-formatted vmstate dumps from QEMU in files SRC and DEST.  Checks whether migration from SRC to DEST QEMU versions would break based on the VMSTATE information contained within the JSON outputs.  The JSON output is created from a QEMU invocation with the -dump-vmstate parameter and a filename argument to it.  Other parameters to QEMU do not matter, except the -M (machine type) parameter."

     parser = argparse.ArgumentParser(description=help_text) -    parser.add_argument('-s', '--src', type=file, required=True, +    parser.add_argument('-s', '--src', type=argparse.FileType('r'), required=True,
                         help='json dump from src qemu') -    parser.add_argument('-d', '--dest', type=file, required=True, +    parser.add_argument('-d', '--dest', type=argparse.FileType('r'), required=True,
                         help='json dump from dest qemu') parser.add_argument('--reverse', required=False, default=False, action='store_true',
--
2.23.0

Signature · 8 lines
Best regards,
-----------------------------------
Han Han
Quality Engineer
Redhat.

Email: [email protected] <mailto:[email protected]>
Phone: +861065339333
author
#4 lore raw
Quoted 12 lines · Thomas Huth
Quoted 1 line · Han Han

Anyone help to review it?

Hi!

When sending patches to the qemu-devel mailing list, please always make sure to put the corresponding maintainers on CC:, otherwise your mails might get lost in the high traffic of the mailing list. For this case, it would have been good to CC: the "Migration" and "Python script" maintainers, see the corresponding sections of the MAINTAINERS file in the top most directory of the QEMU sources.

OK. Thanks for your advice

Quoted 82 lines

Anyway, it seems someone else ran into the same issue already, too, and
it got already fixed here:

https://git.qemu.org/?p=qemu.git;a=commitdiff;h=e8d0ac5801edda91412e5

Thomas

Quoted 8 lines

On Tue, Nov 26, 2019 at 1:54 PM Han Han <[email protected] <mailto:[email protected]>> wrote:

ping

On Wed, Nov 13, 2019 at 9:17 PM Han Han <[email protected] <mailto:[email protected]>> wrote:

Quoted 8 lines

In python3, 'file' is no longer a keyword for file type object. So it
will can error when run the scripts by python3:

$ python3 ./scripts/vmstate-static-checker.py -s 4.0.json -d 4.1.json
Traceback (most recent call last):
File "./scripts/vmstate-static-checker.py", line 431, in

<module>

Quoted 27 lines

sys.exit(main())
File "./scripts/vmstate-static-checker.py", line 378, in main
parser.add_argument('-s', '--src', type=file, required=True,
NameError: name 'file' is not defined

Replace file type to argparse.FileType('r').

Quoted 1 line

---
scripts/vmstate-static-checker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/vmstate-static-checker.py b/scripts/vmstate-static-checker.py
index d3467288..14f199a0 100755
--- a/scripts/vmstate-static-checker.py
+++ b/scripts/vmstate-static-checker.py
@@ -375,9 +375,9 @@ def main():
help_text = "Parse JSON-formatted vmstate dumps from QEMU
in files SRC and DEST. Checks whether migration from SRC to DEST QEMU versions would break based on the VMSTATE information contained within the JSON outputs. The JSON output is created from a QEMU invocation with the -dump-vmstate parameter and a filename argument to it. Other parameters to QEMU do not matter, except the -M (machine type) parameter."

Quoted 6 lines

parser = argparse.ArgumentParser(description=help_text)
- parser.add_argument('-s', '--src', type=file, required=True,
+ parser.add_argument('-s', '--src',
type=argparse.FileType('r'), required=True,
help='json dump from src qemu')
- parser.add_argument('-d', '--dest', type=file,

required=True,

Quoted 4 lines

+ parser.add_argument('-d', '--dest',
type=argparse.FileType('r'), required=True,
help='json dump from dest qemu')
parser.add_argument('--reverse', required=False,

default=False,

Quoted 15 lines
                                 action='store_true',
        --
        2.23.0

--
Best regards,
-----------------------------------
Han Han
Quality Engineer
Redhat.

Email: [email protected] <mailto:[email protected]>
Phone: +861065339333

Signature · 8 lines
Best regards,
-----------------------------------
Han Han
Quality Engineer
Redhat.

Email: [email protected]
Phone: +861065339333