Skip to content

Commit 58e403b

Browse files
committed
sort.py: use script name in usage/main docstring
With this, the help section remains consistent regardless of how the script is called and even if the filename is changed. For example, if someone renames "sort.py" to "firejail-sort" and puts it somewhere in `$PATH`. 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 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). Note2: When running `pydoc ./contrib/sort.py`, argv[0] becomes "/usr/bin/pydoc".
1 parent 63b2857 commit 58e403b

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,10 +2,16 @@
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 commands in profiles.
713
8-
Usage: ./sort.py [/path/to/profile ...]
14+
Usage: {path.basename(argv[0])} [/path/to/profile ...]
915
1016
The following commands are supported:
1117
@@ -17,21 +23,17 @@
1723
Keep in mind that this will overwrite your profile(s).
1824
1925
Examples:
20-
$ ./sort.py MyAwesomeProfile.profile
21-
$ ./sort.py new_profile.profile second_new_profile.profile
22-
$ ./sort.py ~/.config/firejail/*.{profile,inc,local}
23-
$ sudo ./sort.py /etc/firejail/*.{profile,inc,local}
26+
$ {argv[0]} MyAwesomeProfile.profile
27+
$ {argv[0]} new_profile.profile second_new_profile.profile
28+
$ {argv[0]} ~/.config/firejail/*.{{profile,inc,local}}
29+
$ sudo {argv[0]} /etc/firejail/*.{{profile,inc,local}}
2430
2531
Exit Codes:
2632
0: Success: No profiles needed fixing.
2733
1: Error: One or more profiles could not be processed correctly.
2834
101: Info: One or more profiles were fixed.
2935
"""
3036

31-
# Requirements:
32-
# python >= 3.6
33-
from sys import argv, exit as sys_exit, stderr
34-
3537

3638
def sort_alphabetical(original_items):
3739
items = original_items.split(",")

0 commit comments

Comments
 (0)