Skip to content

Commit

Permalink
Merge pull request #3985 from rusty-snake/sort.py-updates
Browse files Browse the repository at this point in the history
Sort.py updates
  • Loading branch information
rusty-snake committed Feb 17, 2021
2 parents 905f94e + f1121cf commit bdabc87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches: [ master ]
paths:
- 'etc/**'
- 'contrib/sort.py'
pull_request:
branches: [ master ]
paths:
- 'etc/**'
- 'contrib/sort.py'

jobs:
profile-sort:
Expand Down
11 changes: 8 additions & 3 deletions contrib/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def fix_profile(filename):
lines = profile.read().split("\n")
was_fixed = False
fixed_profile = []
for line in lines:
for lineno, line in enumerate(lines):
if line[:12] in ("private-bin ", "private-etc ", "private-lib "):
fixed_line = f"{line[:12]}{sort_alphabetical(line[12:])}"
elif line[:13] in ("seccomp.drop ", "seccomp.keep "):
Expand All @@ -95,6 +95,10 @@ def fix_profile(filename):
fixed_line = line
if fixed_line != line:
was_fixed = True
print(
f"{filename}:{lineno + 1}:-{line}\n"
f"{filename}:{lineno + 1}:+{fixed_line}"
)
fixed_profile.append(fixed_line)
if was_fixed:
profile.seek(0)
Expand All @@ -108,6 +112,7 @@ def fix_profile(filename):

def main(args):
exit_code = 0
print(f"sort.py: checking {len(args)} {'profiles' if len(args) != 1 else 'profile'}...")
for filename in args:
try:
if exit_code not in (1, 101):
Expand All @@ -120,8 +125,8 @@ def main(args):
except PermissionError:
print(f"[ Error ] Can't read/write `{filename}'")
exit_code = 1
except:
print(f"[ Error ] An error occurred while processing `{filename}'")
except Exception as err:
print(f"[ Error ] An error occurred while processing `{filename}': {err}")
exit_code = 1
return exit_code

Expand Down

0 comments on commit bdabc87

Please sign in to comment.