add 'which' function to utils and use for 'iwgetid'
This commit is contained in:
parent
feabc7ad98
commit
8c12daa407
2 changed files with 20 additions and 1 deletions
|
@ -60,4 +60,21 @@ def durationfmt(duration, shorten=False, suffix=False):
|
|||
|
||||
return "{}{}".format(res, suf if suffix else "")
|
||||
|
||||
def which(program):
|
||||
import os
|
||||
def is_exe(fpath):
|
||||
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
||||
|
||||
fpath, fname = os.path.split(program)
|
||||
if fpath:
|
||||
if is_exe(program):
|
||||
return program
|
||||
else:
|
||||
for path in os.environ["PATH"].split(os.pathsep) + ["/sbin", "/usr/sbin/", "/usr/local/sbin"]:
|
||||
exe_file = os.path.join(path, program)
|
||||
if is_exe(exe_file):
|
||||
return exe_file
|
||||
|
||||
return None
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue