Skip to content

Commit

Permalink
Rework sort_protocol (sort.py) (#4226)
Browse files Browse the repository at this point in the history
Support "+", "-" and "=" prefixes (introduced in cddc483 + 5ffd928)
  • Loading branch information
rusty-snake committed Apr 30, 2021
1 parent 6f766d4 commit eb69d30
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions contrib/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down

0 comments on commit eb69d30

Please sign in to comment.