Skip to contentSkip to conversation

scripts/signrom: remove Python 2 support, add shebang

PATCH In review Paolo Bonzini 2 participants 5 messages Feb 4, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/signrom: remove Python 2 support, add shebang

Based-on: <[email protected]>

Cc Philippe Mathieu-Daudé <[email protected]>
---
 scripts/signrom.py | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
scripts/signrom.py +4 -8
index 313ee28a17..9be5dab1cf 100644
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
 from __future__ import print_function
 #
 # Option ROM signing utility
@@ -44,14 +46,8 @@ fout.write(data)
 
 checksum = 0
 for b in data:
-    # catch Python 2 vs. 3 differences
-    if isinstance(b, int):
-        checksum += b
-    else:
-        checksum += ord(b)
-checksum = (256 - checksum) % 256
-
-# Python 3 no longer allows chr(checksum)
+    checksum = (checksum - b) & 255
+
 fout.write(struct.pack('B', checksum))
 
 fin.close()
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Paolo Bonzini

Based-on: <[email protected]>

Cc Philippe Mathieu-Daudé <[email protected]>
---
  scripts/signrom.py | 12 ++++--------
  1 file changed, 4 insertions(+), 8 deletions(-)
scripts/signrom.py +2 -3
index 313ee28a17..9be5dab1cf 100644
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
  from __future__ import print_function
  #
  # Option ROM signing utility
@@ -44,14 +46,8 @@ fout.write(data)
 
  checksum = 0
  for b in data:
-    # catch Python 2 vs. 3 differences
-    if isinstance(b, int):
-        checksum += b

scripts/signrom.py fout.write(data) · line 53

Quoted 10 lines
scripts/signrom.py +2 -5
-    else:
-        checksum += ord(b)
-checksum = (256 - checksum) % 256
-
-# Python 3 no longer allows chr(checksum)
+    checksum = (checksum - b) & 255
+
  fout.write(struct.pack('B', checksum))
 
  fin.close()

Also, applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next

#2 lore raw
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 30 lines · Paolo Bonzini

Based-on: <[email protected]>

Cc Philippe Mathieu-Daudé <[email protected]>

---
  scripts/signrom.py | 12 ++++--------

  1 file changed, 4 insertions(+), 8 deletions(-)
scripts/signrom.py +2 -0
index 313ee28a17..9be5dab1cf 100644
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+

  from __future__ import print_function
  #
  # Option ROM signing utility

scripts/signrom.py +0 -0
@@ -44,14 +46,8 @@ fout.write(data)

    checksum = 0
  for b in data:
-    # catch Python 2 vs. 3 differences
-    if isinstance(b, int):
-        checksum += b
-    else:
-        checksum += ord(b)

scripts/signrom.py +2 -3
-checksum = (256 - checksum) % 256
-
-# Python 3 no longer allows chr(checksum)
+    checksum = (checksum - b) & 255
+
Quoted 3 lines

  fout.write(struct.pack('B', checksum))
    fin.close()

Quoted 2 lines

Also, applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next

Oh, good. So I've unqueued your series on which this is based.

Paolo

#3 lore raw
Quoted 38 lines · Paolo Bonzini
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Paolo Bonzini

Based-on: <[email protected]>

Cc Philippe Mathieu-Daudé <[email protected]>
---
   scripts/signrom.py | 12 ++++--------
   1 file changed, 4 insertions(+), 8 deletions(-)
scripts/signrom.py +2 -3
index 313ee28a17..9be5dab1cf 100644
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
   from __future__ import print_function
   #
   # Option ROM signing utility
@@ -44,14 +46,8 @@ fout.write(data)
     checksum = 0
   for b in data:
-    # catch Python 2 vs. 3 differences
-    if isinstance(b, int):
-        checksum += b

scripts/signrom.py fout.write(data) · line 52

Quoted 10 lines
scripts/signrom.py +2 -5
-    else:
-        checksum += ord(b)
-checksum = (256 - checksum) % 256
-
-# Python 3 no longer allows chr(checksum)
+    checksum = (checksum - b) & 255
+
   fout.write(struct.pack('B', checksum))
     fin.close()
 
Quoted 4 lines
Quoted 2 lines

Also, applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next

Oh, good. So I've unqueued your series on which this is based.

Aargh I received your "series queued" mail _after_ this patch.

As you prefer, but I have various python patches pending already. If I keep "Explicit usage of Python 3" do you mind Acking it?

Thanks!

Phil.

author Acked-by
#4 lore raw
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Also, applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next

Quoted 6 lines
Quoted 1 line

Oh, good.  So I've unqueued your series on which this is based.

Aargh I received your "series queued" mail _after_ this patch.

As you prefer, but I have various python patches pending already. If I keep "Explicit usage of Python 3" do you mind Acking it?

Sure, the least patches I queue the better.

Paolo