From 91cafc251139f237237d31ee765480d0b7f898e6 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 13 Sep 2023 23:32:19 +0000 Subject: [PATCH] faster startup on windows by asking for ffmpeg.exe explicitly rather than just "ffmpeg" which makes windows try to open each of ffmpeg.BAT,CMD,COM,EXE,JS,JSE,MSC,VBE,VBS,WSF,WSH one by one (ffmpeg.js? hello??) --- copyparty/mtag.py | 5 ++++- copyparty/util.py | 16 ++++++++++++++++ scripts/pyinstaller/build.sh | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/copyparty/mtag.py b/copyparty/mtag.py index 4a025b86..82ff63b6 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -8,7 +8,7 @@ import shutil import subprocess as sp import sys -from .__init__ import EXE, PY2, WINDOWS, E, unicode +from .__init__ import ANYWIN, EXE, PY2, WINDOWS, E, unicode from .bos import bos from .util import ( FFMPEG_URL, @@ -29,6 +29,9 @@ if True: # pylint: disable=using-constant-test def have_ff(scmd: str) -> bool: + if ANYWIN: + scmd += ".exe" + if PY2: print("# checking {}".format(scmd)) acmd = (scmd + " -version").encode("ascii").split(b" ") diff --git a/copyparty/util.py b/copyparty/util.py index 40a090c8..ba7fdddc 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -298,11 +298,19 @@ REKOBO_KEY = { REKOBO_LKEY = {k.lower(): v for k, v in REKOBO_KEY.items()} +_exestr = "python3 python ffmpeg ffprobe cfssl cfssljson cfssl-certinfo" +CMD_EXEB = set(_exestr.encode("utf-8").split()) +CMD_EXES = set(_exestr.split()) + + pybin = sys.executable or "" if EXE: pybin = "" for zsg in "python3 python".split(): try: + if ANYWIN: + zsg += ".exe" + zsg = shutil.which(zsg) if zsg: pybin = zsg @@ -2450,6 +2458,14 @@ def runcmd( bout: bytes berr: bytes + if ANYWIN: + if isinstance(argv[0], (bytes, bytearray)): + if argv[0] in CMD_EXEB: + argv[0] += b".exe" + else: + if argv[0] in CMD_EXES: + argv[0] += ".exe" + p = sp.Popen(argv, stdout=cout, stderr=cerr, **ka) if not timeout or PY2: bout, berr = p.communicate(sin) diff --git a/scripts/pyinstaller/build.sh b/scripts/pyinstaller/build.sh index 5691346b..7976fb93 100644 --- a/scripts/pyinstaller/build.sh +++ b/scripts/pyinstaller/build.sh @@ -9,7 +9,7 @@ tee build2.sh | cmp build.sh && rm build2.sh || { [[ $r =~ [yY] ]] && mv build{2,}.sh && exec ./build.sh } -[ -e up2k.sh ] && ./up2k.sh +[ -e up2k.sh ] && [ ! "$1" ] && ./up2k.sh uname -s | grep WOW64 && m=64 || m=32 uname -s | grep NT-10 && w10=1 || w7=1 @@ -73,6 +73,7 @@ excl=( multiprocessing pdb pickle + PIL.EpsImagePlugin pyftpdlib.prefork urllib.request urllib.response