diff options
author | smitsohu <smitsohu@gmail.com> | 2019-09-22 13:26:53 +0200 |
---|---|---|
committer | smitsohu <smitsohu@gmail.com> | 2019-09-22 13:26:53 +0200 |
commit | 04057a4652e889e23b66d95da770e7e7abf75ba5 (patch) | |
tree | 077d19a3bae185e66ee495abff143680ab978246 /contrib/sort.py | |
parent | minor optimization (diff) | |
parent | Inkscape: allow xcf export (diff) | |
download | firejail-04057a4652e889e23b66d95da770e7e7abf75ba5.tar.gz firejail-04057a4652e889e23b66d95da770e7e7abf75ba5.tar.zst firejail-04057a4652e889e23b66d95da770e7e7abf75ba5.zip |
Merge branch 'master' of https://github.com/netblue30/firejail
Diffstat (limited to 'contrib/sort.py')
-rwxr-xr-x | contrib/sort.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/contrib/sort.py b/contrib/sort.py index 97315fba8..f77e2a1fc 100755 --- a/contrib/sort.py +++ b/contrib/sort.py | |||
@@ -23,11 +23,13 @@ Exit-Codes: | |||
23 | # python >= 3.6 | 23 | # python >= 3.6 |
24 | from sys import argv | 24 | from sys import argv |
25 | 25 | ||
26 | |||
26 | def sort_alphabetical(raw_items): | 27 | def sort_alphabetical(raw_items): |
27 | items = raw_items.split(",") | 28 | items = raw_items.split(",") |
28 | items.sort(key=lambda s: s.casefold()) | 29 | items.sort(key=lambda s: s.casefold()) |
29 | return ",".join(items) | 30 | return ",".join(items) |
30 | 31 | ||
32 | |||
31 | def sort_protocol(protocols): | 33 | def sort_protocol(protocols): |
32 | """sort the given protocole into this scheme: unix,inet,inet6,netlink,packet""" | 34 | """sort the given protocole into this scheme: unix,inet,inet6,netlink,packet""" |
33 | # shortcut for common protocol lines | 35 | # shortcut for common protocol lines |
@@ -64,6 +66,7 @@ def sort_protocol(protocols): | |||
64 | fixed_protocols += "packet," | 66 | fixed_protocols += "packet," |
65 | return fixed_protocols[:-1] | 67 | return fixed_protocols[:-1] |
66 | 68 | ||
69 | |||
67 | def fix_profile(filename): | 70 | def fix_profile(filename): |
68 | with open(filename, "r+") as profile: | 71 | with open(filename, "r+") as profile: |
69 | lines = profile.read().split("\n") | 72 | lines = profile.read().split("\n") |
@@ -94,6 +97,7 @@ def fix_profile(filename): | |||
94 | return 101 | 97 | return 101 |
95 | return 0 | 98 | return 0 |
96 | 99 | ||
100 | |||
97 | def main(args): | 101 | def main(args): |
98 | exit_code = 0 | 102 | exit_code = 0 |
99 | for filename in args: | 103 | for filename in args: |
@@ -103,15 +107,16 @@ def main(args): | |||
103 | else: | 107 | else: |
104 | fix_profile(filename) | 108 | fix_profile(filename) |
105 | except FileNotFoundError: | 109 | except FileNotFoundError: |
106 | print(f"[ Error ] Can't find {filename}") | 110 | print(f"[ Error ] Can't find `{filename}'") |
107 | exit_code = 1 | 111 | exit_code = 1 |
108 | except PermissionError: | 112 | except PermissionError: |
109 | print(f"[ Error ] Can't read/write {filename}") | 113 | print(f"[ Error ] Can't read/write `{filename}'") |
110 | exit_code = 1 | 114 | exit_code = 1 |
111 | except: | 115 | except: |
112 | print(f"[ Error ] An error occurred while processing {filename}") | 116 | print(f"[ Error ] An error occurred while processing `{filename}'") |
113 | exit_code = 1 | 117 | exit_code = 1 |
114 | return exit_code | 118 | return exit_code |
115 | 119 | ||
120 | |||
116 | if __name__ == "__main__": | 121 | if __name__ == "__main__": |
117 | exit(main(argv[1:])) | 122 | exit(main(argv[1:])) |