utils.py raw
1 #!/usr/bin/env python3
2 # Copyright (c) 2021 The Limenka developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 '''
6 Common utility functions
7 '''
8 import shutil
9 import sys
10 import os
11
12
13 def determine_wellknown_cmd(envvar, progname) -> list[str]:
14 maybe_env = os.getenv(envvar)
15 maybe_which = shutil.which(progname)
16 if maybe_env:
17 return maybe_env.split(' ') # Well-known vars are often meant to be word-split
18 elif maybe_which:
19 return [ maybe_which ]
20 else:
21 sys.exit(f"{progname} not found")
22