Skip to content

Commit f7d7196

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 after `protocol ` * 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 ea3451c commit f7d7196

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
Leading/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
-i Edit the profile file(s) in-place (this is the default).
@@ -44,7 +45,8 @@
4445

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

@@ -56,6 +58,9 @@ def sort_protocol(original_protocols):
5658
unix,inet,inet6,netlink,packet,bluetooth
5759
"""
5860

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

0 commit comments

Comments
 (0)