1 |
commit: c8f5de35cfa59ce7620ed646cce9c9715b0ed72e |
2 |
Author: Mike Frysinger <vapier <AT> chromium <DOT> org> |
3 |
AuthorDate: Wed Sep 28 05:46:01 2022 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Sep 28 07:42:17 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=c8f5de35 |
7 |
|
8 |
lddtree: switch to f-strings in most places |
9 |
|
10 |
These are a bit more readable than % formatting. |
11 |
|
12 |
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> |
13 |
|
14 |
lddtree.py | 35 ++++++++++++++++++----------------- |
15 |
1 file changed, 18 insertions(+), 17 deletions(-) |
16 |
|
17 |
diff --git a/lddtree.py b/lddtree.py |
18 |
index 349bace..ecb353d 100755 |
19 |
--- a/lddtree.py |
20 |
+++ b/lddtree.py |
21 |
@@ -250,7 +250,7 @@ def ParseLdSoConf(ldso_conf, root='/', debug=False, _first=True): |
22 |
|
23 |
dbg_pfx = '' if _first else ' ' |
24 |
try: |
25 |
- dbg(debug, '%sParseLdSoConf(%s)' % (dbg_pfx, ldso_conf)) |
26 |
+ dbg(debug, f"{dbg_pfx}ParseLdSoConf({ldso_conf})") |
27 |
with open(ldso_conf, encoding='utf-8') as f: |
28 |
for line in f.readlines(): |
29 |
line = line.split('#', 1)[0].strip() |
30 |
@@ -262,7 +262,7 @@ def ParseLdSoConf(ldso_conf, root='/', debug=False, _first=True): |
31 |
line = root + line.lstrip('/') |
32 |
else: |
33 |
line = os.path.dirname(ldso_conf) + '/' + line |
34 |
- dbg(debug, '%s glob: %s' % (dbg_pfx, line)) |
35 |
+ dbg(debug, dbg_pfx, "glob:", line) |
36 |
# ldconfig in glibc uses glob() which returns entries sorted according |
37 |
# to LC_COLLATE. Further, ldconfig does not reset that but respects |
38 |
# the active env settings (which might be a mistake). Python does not |
39 |
@@ -336,7 +336,7 @@ def CompatibleELFs(elf1, elf2): |
40 |
""" |
41 |
osabis = frozenset([e.header['e_ident']['EI_OSABI'] for e in (elf1, elf2)]) |
42 |
compat_sets = ( |
43 |
- frozenset('ELFOSABI_%s' % x for x in ('NONE', 'SYSV', 'GNU', 'LINUX',)), |
44 |
+ frozenset(f"ELFOSABI_{x}" for x in ("NONE", "SYSV", "GNU", "LINUX")), |
45 |
) |
46 |
return ((len(osabis) == 1 or any(osabis.issubset(x) for x in compat_sets)) and |
47 |
elf1.elfclass == elf2.elfclass and |
48 |
@@ -357,13 +357,13 @@ def FindLib(elf, lib, ldpaths, root='/', debug=False): |
49 |
Returns: |
50 |
Tuple of the full path to the desired library and the real path to it |
51 |
""" |
52 |
- dbg(debug, ' FindLib(%s)' % lib) |
53 |
+ dbg(debug, f" FindLib({lib})") |
54 |
|
55 |
for ldpath in ldpaths: |
56 |
path = os.path.join(ldpath, lib) |
57 |
target = readlink(path, root, prefixed=True) |
58 |
if path != target: |
59 |
- dbg(debug, ' checking: %s -> %s' % (path, target)) |
60 |
+ dbg(debug, " checking:", path, "->", target) |
61 |
else: |
62 |
dbg(debug, ' checking:', path) |
63 |
|
64 |
@@ -374,7 +374,7 @@ def FindLib(elf, lib, ldpaths, root='/', debug=False): |
65 |
if CompatibleELFs(elf, libelf): |
66 |
return (target, path) |
67 |
except exceptions.ELFError as e: |
68 |
- warn('%s: %s' % (target, e)) |
69 |
+ warn(f"{target}: {e}") |
70 |
|
71 |
return (None, None) |
72 |
|
73 |
@@ -429,7 +429,7 @@ def ParseELF(path, root='/', cwd=None, prefix='', |
74 |
'libs': _all_libs, |
75 |
} |
76 |
|
77 |
- dbg(debug, 'ParseELF(%s)' % path) |
78 |
+ dbg(debug, f"ParseELF({path})") |
79 |
|
80 |
with open(path, 'rb') as f: |
81 |
try: |
82 |
@@ -527,7 +527,7 @@ def ParseELF(path, root='/', cwd=None, prefix='', |
83 |
lret = ParseELF(realpath, root, cwd, prefix, ldpaths, display=fullpath, |
84 |
debug=debug, _first=False, _all_libs=_all_libs) |
85 |
except exceptions.ELFError as e: |
86 |
- warn('%s: %s' % (realpath, e)) |
87 |
+ warn(f"{realpath}: {e}") |
88 |
_all_libs[lib]['needed'] = lret['needed'] |
89 |
|
90 |
del elf |
91 |
@@ -549,13 +549,14 @@ def _ActionShow(options, elf): |
92 |
if options.list: |
93 |
print(fullpath or lib) |
94 |
else: |
95 |
- print('%s%s => %s' % (' ' * depth, lib, fullpath)) |
96 |
+ indent = " " * depth |
97 |
+ print(f"{indent}{lib}", "=>", fullpath) |
98 |
|
99 |
new_libs = [] |
100 |
for lib in elf['libs'][lib]['needed']: |
101 |
if lib in chain_libs: |
102 |
if not options.list: |
103 |
- print('%s%s => !!! circular loop !!!' % (' ' * depth, lib)) |
104 |
+ print(f"{indent}{lib} => !!! circular loop !!!") |
105 |
continue |
106 |
if options.all or not lib in shown_libs: |
107 |
shown_libs.add(lib) |
108 |
@@ -584,7 +585,7 @@ def _ActionShow(options, elf): |
109 |
if not interp is None: |
110 |
print(interp) |
111 |
else: |
112 |
- print('%s (interpreter => %s)' % (elf['path'], interp)) |
113 |
+ print(elf["path"], f"(interpreter => {interp})") |
114 |
for lib in new_libs: |
115 |
_show(lib, 1) |
116 |
|
117 |
@@ -627,7 +628,7 @@ def _ActionCopy(options, elf): |
118 |
raise |
119 |
|
120 |
if options.verbose: |
121 |
- print('%s -> %s' % (src, dst)) |
122 |
+ print(src, "->", dst) |
123 |
|
124 |
os.makedirs(os.path.dirname(dst), exist_ok=True) |
125 |
try: |
126 |
@@ -644,7 +645,7 @@ def _ActionCopy(options, elf): |
127 |
|
128 |
if wrapit: |
129 |
if options.verbose: |
130 |
- print('generate wrapper %s' % (dst,)) |
131 |
+ print("generate wrapper", dst) |
132 |
|
133 |
if options.libdir: |
134 |
interp = os.path.join(options.libdir, os.path.basename(elf['interp'])) |
135 |
@@ -662,7 +663,7 @@ def _ActionCopy(options, elf): |
136 |
libdata = elf['libs'][lib] |
137 |
path = libdata['realpath'] |
138 |
if path is None: |
139 |
- warn('could not locate library: %s' % lib) |
140 |
+ warn("could not locate library:", lib) |
141 |
continue |
142 |
if not options.libdir: |
143 |
uniq_libpaths.add(_StripRoot(os.path.dirname(path))) |
144 |
@@ -838,11 +839,11 @@ def main(argv): |
145 |
_ActionCopy(options, elf) |
146 |
continue |
147 |
ret = 1 |
148 |
- warn('%s: %s' % (p, e)) |
149 |
+ warn(f"{p}: {e}") |
150 |
continue |
151 |
except IOError as e: |
152 |
ret = 1 |
153 |
- warn('%s: %s' % (p, e)) |
154 |
+ warn(f"{p}: {e}") |
155 |
continue |
156 |
|
157 |
if options.dest is None: |
158 |
@@ -853,7 +854,7 @@ def main(argv): |
159 |
if not matched: |
160 |
if not options.skip_missing: |
161 |
ret = 1 |
162 |
- warn('%s: did not match any paths' % (path,)) |
163 |
+ warn(f"{path}: did not match any paths") |
164 |
|
165 |
return ret |