Skip to content

Commit d7c17ec

Browse files
committed
build: sort.py: rename line variables
Rename `line` to `original_line` to make it less likely to accidentally read from/write to it instead of the fixed line. Rename `fixed_line` to `line` to make the code shorter since it is now referenced much more often (up to 3 times in the same line of code) than the original line. See also commit aa17ca5 ("sort.py: rename protocols to original_protocols", 2022-10-17) / PR netblue30#5429.
1 parent b26a3a6 commit d7c17ec

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

contrib/sort.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,25 @@ def check_profile(filename, overwrite):
7171
lines = profile.read().split("\n")
7272
was_fixed = False
7373
fixed_profile = []
74-
for lineno, line in enumerate(lines, 1):
75-
fixed_line = line
76-
if fixed_line[:12] in ("private-bin ", "private-etc ", "private-lib "):
77-
fixed_line = f"{fixed_line[:12]}{sort_alphabetical(fixed_line[12:])}"
78-
elif fixed_line[:13] in ("seccomp.drop ", "seccomp.keep "):
79-
fixed_line = f"{fixed_line[:13]}{sort_alphabetical(fixed_line[13:])}"
80-
elif fixed_line[:10] in ("caps.drop ", "caps.keep "):
81-
fixed_line = f"{fixed_line[:10]}{sort_alphabetical(fixed_line[10:])}"
82-
elif fixed_line[:8] == "protocol":
83-
fixed_line = f"protocol {sort_protocol(fixed_line[9:])}"
84-
elif fixed_line[:8] == "seccomp ":
85-
fixed_line = f"{fixed_line[:8]}{sort_alphabetical(fixed_line[8:])}"
86-
if fixed_line != line:
74+
for lineno, original_line in enumerate(lines, 1):
75+
line = original_line
76+
if line[:12] in ("private-bin ", "private-etc ", "private-lib "):
77+
line = f"{line[:12]}{sort_alphabetical(line[12:])}"
78+
elif line[:13] in ("seccomp.drop ", "seccomp.keep "):
79+
line = f"{line[:13]}{sort_alphabetical(line[13:])}"
80+
elif line[:10] in ("caps.drop ", "caps.keep "):
81+
line = f"{line[:10]}{sort_alphabetical(line[10:])}"
82+
elif line[:8] == "protocol":
83+
line = f"protocol {sort_protocol(line[9:])}"
84+
elif line[:8] == "seccomp ":
85+
line = f"{line[:8]}{sort_alphabetical(line[8:])}"
86+
if line != original_line:
8787
was_fixed = True
8888
print(
89-
f"{filename}:{lineno}:-{line}\n"
90-
f"{filename}:{lineno}:+{fixed_line}"
89+
f"{filename}:{lineno}:-{original_line}\n"
90+
f"{filename}:{lineno}:+{line}"
9191
)
92-
fixed_profile.append(fixed_line)
92+
fixed_profile.append(line)
9393

9494
if was_fixed:
9595
if overwrite:

0 commit comments

Comments
 (0)