Skip to content

Commit 261be8d

Browse files
committed
sort.py: use script name in usage/main docstring
Note: This depends on `os.path` and `sys.argv`, so the imports have to appear before the docstring. In which case, the docstring has to be explicitly assigned to `__doc__` (as it ceases to be the first statement in the file). Example outputs of the script name (using `print(argv[0]); return`: $ ./contrib/sort.py ./contrib/sort.py $ python contrib/sort.sh contrib/sort.py $ (cd contrib && ./sort.py) ./sort.py
1 parent c8d3a1e commit 261be8d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

contrib/sort.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,35 @@
22
# This file is part of Firejail project
33
# Copyright (C) 2014-2022 Firejail Authors
44
# License GPL v2
5-
"""\
5+
6+
# Requirements:
7+
# python >= 3.6
8+
from os import path
9+
from sys import argv, exit as sys_exit, stderr
10+
11+
__doc__ = f"""\
612
Sort the arguments of the commands that support multiple arguments in profiles;
713
the following commands are supported:
814
915
private-bin, private-etc, private-lib, caps.drop, caps.keep, seccomp.drop,
1016
seccomp.drop, protocol
1117
12-
Usage: ./sort.py [/path/to/profile ...]
18+
Usage: {path.basename(argv[0])} [/path/to/profile ...]
1319
1420
Keep in mind that this will overwrite your profile(s).
1521
1622
Examples:
17-
$ ./sort.py MyAwesomeProfile.profile
18-
$ ./sort.py new_profile.profile second_new_profile.profile
19-
$ ./sort.py ~/.config/firejail/*.{profile,inc,local}
20-
$ sudo ./sort.py /etc/firejail/*.{profile,inc,local}
23+
$ {argv[0]} MyAwesomeProfile.profile
24+
$ {argv[0]} new_profile.profile second_new_profile.profile
25+
$ {argv[0]} ~/.config/firejail/*.{{profile,inc,local}}
26+
$ sudo {argv[0]} /etc/firejail/*.{{profile,inc,local}}
2127
2228
Exit Codes:
2329
0: Success: No profiles needed fixing.
2430
1: Error: One or more profiles could not be processed correctly.
2531
101: Info: One or more profile were fixed.
2632
"""
2733

28-
# Requirements:
29-
# python >= 3.6
30-
from sys import argv, exit as sys_exit, stderr
31-
3234

3335
def sort_alphabetical(original_items):
3436
items = original_items.split(",")

0 commit comments

Comments
 (0)