diff options
Diffstat (limited to 'contrib/sort.py')
-rwxr-xr-x | contrib/sort.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/contrib/sort.py b/contrib/sort.py index 54b2cbaa6..9e5062c3c 100755 --- a/contrib/sort.py +++ b/contrib/sort.py | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/env python3 | 1 | #!/usr/bin/env python3 |
2 | # This file is part of Firejail project | 2 | # This file is part of Firejail project |
3 | # Copyright (C) 2014-2020 Firejail Authors | 3 | # Copyright (C) 2014-2021 Firejail Authors |
4 | # License GPL v2 | 4 | # License GPL v2 |
5 | """ | 5 | """ |
6 | Sort the items of multi-item options in profiles, the following options are supported: | 6 | Sort the items of multi-item options in profiles, the following options are supported: |
@@ -80,7 +80,7 @@ def fix_profile(filename): | |||
80 | lines = profile.read().split("\n") | 80 | lines = profile.read().split("\n") |
81 | was_fixed = False | 81 | was_fixed = False |
82 | fixed_profile = [] | 82 | fixed_profile = [] |
83 | for line in lines: | 83 | for lineno, line in enumerate(lines): |
84 | if line[:12] in ("private-bin ", "private-etc ", "private-lib "): | 84 | if line[:12] in ("private-bin ", "private-etc ", "private-lib "): |
85 | fixed_line = f"{line[:12]}{sort_alphabetical(line[12:])}" | 85 | fixed_line = f"{line[:12]}{sort_alphabetical(line[12:])}" |
86 | elif line[:13] in ("seccomp.drop ", "seccomp.keep "): | 86 | elif line[:13] in ("seccomp.drop ", "seccomp.keep "): |
@@ -95,6 +95,10 @@ def fix_profile(filename): | |||
95 | fixed_line = line | 95 | fixed_line = line |
96 | if fixed_line != line: | 96 | if fixed_line != line: |
97 | was_fixed = True | 97 | was_fixed = True |
98 | print( | ||
99 | f"{filename}:{lineno + 1}:-{line}\n" | ||
100 | f"{filename}:{lineno + 1}:+{fixed_line}" | ||
101 | ) | ||
98 | fixed_profile.append(fixed_line) | 102 | fixed_profile.append(fixed_line) |
99 | if was_fixed: | 103 | if was_fixed: |
100 | profile.seek(0) | 104 | profile.seek(0) |
@@ -108,6 +112,7 @@ def fix_profile(filename): | |||
108 | 112 | ||
109 | def main(args): | 113 | def main(args): |
110 | exit_code = 0 | 114 | exit_code = 0 |
115 | print(f"sort.py: checking {len(args)} {'profiles' if len(args) != 1 else 'profile'}...") | ||
111 | for filename in args: | 116 | for filename in args: |
112 | try: | 117 | try: |
113 | if exit_code not in (1, 101): | 118 | if exit_code not in (1, 101): |
@@ -120,8 +125,8 @@ def main(args): | |||
120 | except PermissionError: | 125 | except PermissionError: |
121 | print(f"[ Error ] Can't read/write `{filename}'") | 126 | print(f"[ Error ] Can't read/write `{filename}'") |
122 | exit_code = 1 | 127 | exit_code = 1 |
123 | except: | 128 | except Exception as err: |
124 | print(f"[ Error ] An error occurred while processing `{filename}'") | 129 | print(f"[ Error ] An error occurred while processing `{filename}': {err}") |
125 | exit_code = 1 | 130 | exit_code = 1 |
126 | return exit_code | 131 | return exit_code |
127 | 132 | ||