From eb69d30137306cd179ae2f3495689c5861addb4b Mon Sep 17 00:00:00 2001 From: rusty-snake <41237666+rusty-snake@users.noreply.github.com> Date: Fri, 30 Apr 2021 11:09:59 +0000 Subject: Rework sort_protocol (sort.py) (#4226) Support "+", "-" and "=" prefixes (introduced in cddc4832 + 5ffd9287) --- contrib/sort.py | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) (limited to 'contrib') diff --git a/contrib/sort.py b/contrib/sort.py index 9e5062c3c..c7325facb 100755 --- a/contrib/sort.py +++ b/contrib/sort.py @@ -35,43 +35,16 @@ def sort_alphabetical(raw_items): def sort_protocol(protocols): """sort the given protocole into this scheme: unix,inet,inet6,netlink,packet,bluetooth""" + # shortcut for common protocol lines if protocols in ("unix", "unix,inet,inet6"): return protocols + fixed_protocols = "" - present_protocols = { - "unix": False, - "inet": False, - "inet6": False, - "netlink": False, - "packet": False, - "bluetooth": False, - } - for protocol in protocols.split(","): - if protocol == "unix": - present_protocols["unix"] = True - elif protocol == "inet": - present_protocols["inet"] = True - elif protocol == "inet6": - present_protocols["inet6"] = True - elif protocol == "netlink": - present_protocols["netlink"] = True - elif protocol == "packet": - present_protocols["packet"] = True - elif protocol == "bluetooth": - present_protocols["bluetooth"] = True - if present_protocols["unix"]: - fixed_protocols += "unix," - if present_protocols["inet"]: - fixed_protocols += "inet," - if present_protocols["inet6"]: - fixed_protocols += "inet6," - if present_protocols["netlink"]: - fixed_protocols += "netlink," - if present_protocols["packet"]: - fixed_protocols += "packet," - if present_protocols["bluetooth"]: - fixed_protocols += "bluetooth," + for protocol in ("unix", "inet", "inet6", "netlink", "packet", "bluetooth"): + for prefix in ("", "-", "+", "="): + if f",{prefix}{protocol}," in f",{protocols},": + fixed_protocols += f"{prefix}{protocol}," return fixed_protocols[:-1] -- cgit v1.2.3-54-g00ecf