From 171059cf454ff689cdcba4a8ce8f9b5a16f51d1d Mon Sep 17 00:00:00 2001 From: j Date: Thu, 29 Aug 2024 20:22:37 +0200 Subject: [PATCH] avoid distutils, no longer in python 3.12 --- ox/file.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ox/file.py b/ox/file.py index cb8cc35..a983662 100644 --- a/ox/file.py +++ b/ox/file.py @@ -2,7 +2,6 @@ # vi:si:et:sw=4:sts=4:ts=4 # GPL 2008 from __future__ import division, print_function -from distutils.spawn import find_executable from glob import glob import hashlib import os @@ -39,6 +38,21 @@ EXTENSIONS = { ], } +def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + +def which(program): + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ.get("PATH", "").split(os.pathsep): + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + return None + def cmd(program): local = os.path.expanduser('~/.ox/bin/%s' % program) if os.path.exists(local): @@ -160,12 +174,11 @@ def avinfo(filename, cached=True): if cached: return cache(filename, 'info') if os.path.getsize(filename): - if find_executable('ffprobe'): + if which('ffprobe'): return ffprobe(filename) raise EnvironmentError('could to find ffprobe. please install ffmpeg') return {'path': filename, 'size': 0} - def ffprobe(filename): p = subprocess.Popen([ cmd('ffprobe'),