aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorLibravatar Fred Barclay <Fred-Barclay@users.noreply.github.com>2019-09-21 10:19:38 -0500
committerLibravatar GitHub <noreply@github.com>2019-09-21 10:19:38 -0500
commit2e14c1a1d0784acc7536158df3eb7ea58cb73ff7 (patch)
tree8ca1bf0c84379c03a5932b5fb21d794b1ef99140 /contrib
parentreadd .config/dconf to whitelist-common because … (diff)
downloadfirejail-2e14c1a1d0784acc7536158df3eb7ea58cb73ff7.tar.gz
firejail-2e14c1a1d0784acc7536158df3eb7ea58cb73ff7.tar.zst
firejail-2e14c1a1d0784acc7536158df3eb7ea58cb73ff7.zip
Adding sort.py to GitLab CI (#2973)
* Add contrib/sort.py to Gitlab CI Not adding to Debian Jessie or CentOS since python >=3.6 is not available See https://github.com/netblue30/firejail/pull/2870 * Updates Explicitly install python3 on Ubuntu (should be pre-installed but not working as-is) Remove running python3 code on CentOS * ci: comment out contrib/sort.py for Alpine Getting this error: $ python3 contrib/sort.py etc/*.{profile,inc} [ Error ] Can't find `etc/*.{profile,inc}' ERROR: Job failed: exit code 1 For now it's better to debug later and enable this test for the other jobs
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/sort.py11
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
24from sys import argv 24from sys import argv
25 25
26
26def sort_alphabetical(raw_items): 27def 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
31def sort_protocol(protocols): 33def 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
67def fix_profile(filename): 70def 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
97def main(args): 101def 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
116if __name__ == "__main__": 121if __name__ == "__main__":
117 exit(main(argv[1:])) 122 exit(main(argv[1:]))