teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0094-tools-use-print-function-in-Python-3-code.patch

ff6046
From 5adeea95a7310d97b98821322b51794a46199417 Mon Sep 17 00:00:00 2001
ff6046
From: Lucas Werkmeister <mail@lucaswerkmeister.de>
ff6046
Date: Sat, 25 Aug 2018 18:41:42 +0200
ff6046
Subject: [PATCH] tools: use print function in Python 3 code
ff6046
ff6046
This GDB script was converted to use Python 3 along with all other
ff6046
Python scripts in commit b95f5528cc, but still used the Python 2 print
ff6046
statement syntax instead of the Python 3 print function. Fix that.
ff6046
ff6046
We also add the Python 2 compatibility statement, just in case some GDB
ff6046
still uses Python 2 instead of Python 3.
ff6046
---
ff6046
 tools/gdb-sd_dump_hashmaps.py | 18 ++++++++++--------
ff6046
 1 file changed, 10 insertions(+), 8 deletions(-)
ff6046
ff6046
diff --git a/tools/gdb-sd_dump_hashmaps.py b/tools/gdb-sd_dump_hashmaps.py
ff6046
index e6ddd14ea7..ea15160107 100644
ff6046
--- a/tools/gdb-sd_dump_hashmaps.py
ff6046
+++ b/tools/gdb-sd_dump_hashmaps.py
ff6046
@@ -2,6 +2,8 @@
ff6046
 #  -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
ff6046
 # SPDX-License-Identifier: LGPL-2.1+
ff6046
 
ff6046
+from __future__ import print_function
ff6046
+
ff6046
 import gdb
ff6046
 
ff6046
 class sd_dump_hashmaps(gdb.Command):
ff6046
@@ -19,7 +21,7 @@ class sd_dump_hashmaps(gdb.Command):
ff6046
                 ulong_t = gdb.lookup_type("unsigned long")
ff6046
                 debug_offset = gdb.parse_and_eval("(unsigned long)&((HashmapBase*)0)->debug")
ff6046
 
ff6046
-                print "type, hash, indirect, entries, max_entries, buckets, creator"
ff6046
+                print("type, hash, indirect, entries, max_entries, buckets, creator")
ff6046
                 while d:
ff6046
                         h = gdb.parse_and_eval("(HashmapBase*)((char*)%d - %d)" % (int(d.cast(ulong_t)), debug_offset))
ff6046
 
ff6046
@@ -34,7 +36,7 @@ class sd_dump_hashmaps(gdb.Command):
ff6046
 
ff6046
                         t = ["plain", "ordered", "set"][int(h["type"])]
ff6046
 
ff6046
-                        print "{}, {}, {}, {}, {}, {}, {} ({}:{})".format(t, h["hash_ops"], bool(h["has_indirect"]), n_entries, d["max_entries"], n_buckets, d["func"], d["file"], d["line"])
ff6046
+                        print("{}, {}, {}, {}, {}, {}, {} ({}:{})".format(t, h["hash_ops"], bool(h["has_indirect"]), n_entries, d["max_entries"], n_buckets, d["func"], d["file"], d["line"]))
ff6046
 
ff6046
                         if arg != "" and n_entries > 0:
ff6046
                                 dib_raw_addr = storage_ptr + (all_entry_sizes[h["type"]] * n_buckets)
ff6046
@@ -46,10 +48,10 @@ class sd_dump_hashmaps(gdb.Command):
ff6046
 
ff6046
                                 for dib in sorted(iter(histogram)):
ff6046
                                         if dib != 255:
ff6046
-                                                print "{:>3} {:>8} {} of entries".format(dib, histogram[dib], 100.0*histogram[dib]/n_entries)
ff6046
+                                                print("{:>3} {:>8} {} of entries".format(dib, histogram[dib], 100.0*histogram[dib]/n_entries))
ff6046
                                         else:
ff6046
-                                                print "{:>3} {:>8} {} of slots".format(dib, histogram[dib], 100.0*histogram[dib]/n_buckets)
ff6046
-                                print "mean DIB of entries: {}".format(sum([dib*histogram[dib] for dib in iter(histogram) if dib != 255])*1.0/n_entries)
ff6046
+                                                print("{:>3} {:>8} {} of slots".format(dib, histogram[dib], 100.0*histogram[dib]/n_buckets))
ff6046
+                                print("mean DIB of entries: {}".format(sum([dib*histogram[dib] for dib in iter(histogram) if dib != 255])*1.0/n_entries))
ff6046
 
ff6046
                                 blocks = []
ff6046
                                 current_len = 1
ff6046
@@ -70,9 +72,9 @@ class sd_dump_hashmaps(gdb.Command):
ff6046
                                 if len(blocks) > 1 and blocks[0][0] == blocks[0][1] and blocks[-1][0] == n_buckets - 1:
ff6046
                                         blocks[0][1] += blocks[-1][1]
ff6046
                                         blocks = blocks[0:-1]
ff6046
-                                print "max block: {}".format(max(blocks, key=lambda a: a[1]))
ff6046
-                                print "sum block lens: {}".format(sum(b[1] for b in blocks))
ff6046
-                                print "mean block len: {}".format((1.0 * sum(b[1] for b in blocks) / len(blocks)))
ff6046
+                                print("max block: {}".format(max(blocks, key=lambda a: a[1])))
ff6046
+                                print("sum block lens: {}".format(sum(b[1] for b in blocks)))
ff6046
+                                print("mean block len: {}".format((1.0 * sum(b[1] for b in blocks) / len(blocks))))
ff6046
 
ff6046
                         d = d["debug_list_next"]
ff6046