A pair of python3 scripts for importing. I wrote these to facilitate writing wrappers external commands, when replacing some shell scripts. There might be better ways to do it (including checking for libraries in lieu of commands) but in absence of that possibility (looking at you, docker-compose
!), these have made things much easier...!
The arguments.py
script allows loading a parser with some defaults, as well as passing your own argparse
definitions to it. It then returns a usable dicitonary in which to look up items.
The runner.sh
script provides a convenience set of functions for runnning external commands, as well as a dry run mode predicated on use of --dry-run
from the arguments.sh
script. It also accepts a simple dict mapping extra environment variables into the existing environment
import runner
import arguments
import sys
my_options = {
"--server": {"help": "the server to ping"}
}
parser = arguments.Parser(my_options)
args = parser.parse(sys.argv[1:])
myenv = {"PATH":"/home/user/.local/bin"} # Note - this will overwrite the default path, not append
runner.run(["ping", arguments["server"], "-c", "4"], addenv=myenv)
There. That was easy, right?
(C) Tai Kedzierski Provided under LGPLv3 https://www.gnu.org/licenses/lgpl-3.0.txt