Skip to content

Commit 01fde78

Browse files
committed
build: sort.py: strip whitespace in commands
Currently whitespace is left as is within an entry. In a `protocol` entry, if there is whitespace between the command and its argument or around an item, the item in question is dropped from the output. Changes: * `protocol`: Strip all whitespace in the argument * Other commands: Strip leading/trailing whitespace around each item, including any extra whitespace between a command and its argument Note: Whitespace characters inside paths are left as is, as some paths (such as `Foo Bar` may contain spaces. Before: $ printf 'private-bin a,b\nprivate-bin a,b\nprivate-bin b,a\nprivate-bin C,A B\nprotocol unix,net\nprotocol inet,unix\n' \ >foo.profile $ ./contrib/sort.py -n foo.profile sort.py: checking 1 profile(s)... foo.profile:5:-protocol unix,net foo.profile:5:+protocol foo.profile:6:-protocol inet,unix foo.profile:6:+protocol unix After: $ printf 'private-bin a,b\nprivate-bin a,b\nprivate-bin b,a\nprivate-bin C,A B\nprotocol unix,net\nprotocol inet,unix\n' \ >foo.profile $ ./contrib/sort.py -n foo.profile sort.py: checking 1 profile(s)... foo.profile:2:-private-bin a,b foo.profile:2:+private-bin a,b foo.profile:3:-private-bin b,a foo.profile:3:+private-bin a,b foo.profile:4:-private-bin C,A B foo.profile:4:+private-bin A B,C foo.profile:5:-protocol unix,net foo.profile:5:+protocol unix foo.profile:6:-protocol inet,unix foo.profile:6:+protocol unix,inet
1 parent 84c6bb5 commit 01fde78

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

contrib/sort.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
Note that this is only applicable to commands that support multiple arguments.
2222
2323
Trailing whitespace is removed in all lines (that is, not just in lines
24-
containing supported commands).
24+
containing supported commands) and other whitespace is stripped depending on
25+
the command.
2526
2627
Options:
2728
-h Print this message.
@@ -45,7 +46,8 @@
4546

4647
def sort_alphabetical(original_items):
4748
items = original_items.split(",")
48-
items = filter(None, set(items))
49+
items = set(map(str.strip, items))
50+
items = filter(None, items)
4951
items = sorted(items)
5052
return ",".join(items)
5153

@@ -57,6 +59,9 @@ def sort_protocol(original_protocols):
5759
unix,inet,inet6,netlink,packet,bluetooth
5860
"""
5961

62+
# remove all whitespace
63+
original_protocols = "".join(original_protocols.split())
64+
6065
# shortcut for common protocol lines
6166
if original_protocols in ("unix", "unix,inet,inet6"):
6267
return original_protocols

0 commit comments

Comments
 (0)