29 lines
815 B
Python
29 lines
815 B
Python
|
import tarfile, os
|
||
|
|
||
|
def extract_tar(file_path, dest_dir = "."):
|
||
|
print('Extracting "{:s}" to "{:s}"'.format(file_path, dest_dir))
|
||
|
with tarfile.open(file_path) as tar:
|
||
|
tar.extractall(dest_dir)
|
||
|
tar.close()
|
||
|
|
||
|
def which(program, additional_paths = None):
|
||
|
|
||
|
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:
|
||
|
paths = os.environ["PATH"].split(os.pathsep);
|
||
|
if additional_paths != None:
|
||
|
paths.append(additional_paths)
|
||
|
for path in paths:
|
||
|
path = path.strip('"')
|
||
|
exe_file = os.path.join(path, program)
|
||
|
if is_exe(exe_file):
|
||
|
return exe_file
|
||
|
|
||
|
return None
|