Skip to content

Commit

Permalink
sort.py: use script name in usage/main docstring
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kmk3 committed Oct 19, 2022
1 parent 4ca1c1a commit 7e172a5
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions contrib/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@
# This file is part of Firejail project
# Copyright (C) 2014-2022 Firejail Authors
# License GPL v2
"""\

# Requirements:
# python >= 3.6
from os import path
from sys import argv, exit as sys_exit, stderr

__doc__ = f"""\
Sort the arguments of the commands that support multiple arguments in profiles;
the following commands are supported:
private-bin, private-etc, private-lib, caps.drop, caps.keep, seccomp.drop,
seccomp.drop, protocol
Usage: ./sort.py [/path/to/profile ...]
Usage: {path.basename(argv[0])} [/path/to/profile ...]
Keep in mind that this will overwrite your profile(s).
Examples:
$ ./sort.py MyAwesomeProfile.profile
$ ./sort.py new_profile.profile second_new_profile.profile
$ ./sort.py ~/.config/firejail/*.{profile,inc,local}
$ sudo ./sort.py /etc/firejail/*.{profile,inc,local}
$ {argv[0]} MyAwesomeProfile.profile
$ {argv[0]} new_profile.profile second_new_profile.profile
$ {argv[0]} ~/.config/firejail/*.{{profile,inc,local}}
$ sudo {argv[0]} /etc/firejail/*.{{profile,inc,local}}
Exit Codes:
0: Success: No profiles needed fixing.
1: Error: One or more profiles could not be processed correctly.
101: Info: One or more profiles were fixed.
"""

# Requirements:
# python >= 3.6
from sys import argv, exit as sys_exit, stderr


def sort_alphabetical(original_items):
items = original_items.split(",")
Expand Down

0 comments on commit 7e172a5

Please sign in to comment.