From 211d6df0f6383515aaf408ca09272169f31b5c46 Mon Sep 17 00:00:00 2001 From: Luc Papeleux <L.Papeleux@ULiege.be> Date: Tue, 14 Dec 2021 11:21:38 +0100 Subject: [PATCH] replace distutils.spawn.find_executable(...) (that does not work with .bat, .cmd,... files) by shutil.which(...) --- externalProgramPath.py | 6 ++++-- postProLoop.py | 13 +++++++++++-- prmClassesGui.py | 7 ++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/externalProgramPath.py b/externalProgramPath.py index bc0da25..6b169e8 100755 --- a/externalProgramPath.py +++ b/externalProgramPath.py @@ -4,7 +4,7 @@ # Define external program paths according to local configuration from prmClasses import * -import os, os.path, distutils.spawn +import os, os.path, shutil #, distutils.spawn class ExtProgs(PRMSet): def __init__(self, verb=False): @@ -71,7 +71,9 @@ class ExtProgs(PRMSet): print("\t 3. If %s not in the Script last version, add it program in the Script..."%key) return False - if distutils.spawn.find_executable(os.path.splitext(self.pars[key].val)[0]) : + + #if distutils.spawn.find_executable(os.path.splitext(self.pars[key].val)[0]) : # sous windows ne trouve que les .exe => ne marche pas avec .bat & .cmd + if shutil.which(self.pars[key].val): return True else: print("%s is not found in %s ..."%(key, self.pars[key].val)) diff --git a/postProLoop.py b/postProLoop.py index ac7ec14..d66fdfe 100755 --- a/postProLoop.py +++ b/postProLoop.py @@ -6,7 +6,7 @@ # Define externals program path according to local configuration # from prmClasses import * -import os, os.path, distutils.spawn, time, sys, re, glob +import os, os.path, shutil, time, sys, re, glob #, distutils.spawn import imp #import importlib import externalProgramPath @@ -143,7 +143,16 @@ class PostProLoop(PRMSet): self.pars['LATEXREQUEST'].enable(self.pars['LATEXRUN'].val==True) - def checkValidity(self, key): + def checkValidity(self, key): + #if distutils.spawn.find_executable(os.path.splitext(self.pars[key].val)[0]): + if shutil.which(self.pars[key].val): + return True + else: + print "%s is not found (%s)...."%self.pars[key].val + print "\t Check installation and accessibility..." + print "\t Use 'externalProgramPathGui' to define the full program path (recommanded)" + print "\t or add %s in your user path (not recommanded)"%key + return False ''' if distutils.spawn.find_executable(os.path.splitext(self.pars[key].val)[0]): return True diff --git a/prmClassesGui.py b/prmClassesGui.py index 3b20bd2..58b4d8d 100644 --- a/prmClassesGui.py +++ b/prmClassesGui.py @@ -24,7 +24,7 @@ except: #print "PyQt%d (Qt %s) loaded!" % (foundQt, QT_VERSION_STR) -import distutils.spawn +import shutil #, distutils.spawn from prmClasses import * #======================================================================================== @@ -221,8 +221,9 @@ class ExeFileLine(FileLine): if os.path.isfile(f): # White bg #print "isFile" bgCol = QColor(255, 255, 255) - elif distutils.spawn.find_executable(os.path.splitext(f)[0]): # *.cmd pas reconnu comme exe !!! - #print "find_executable in path" + #elif distutils.spawn.find_executable(os.path.splitext(f)[0]): # *.cmd/*.bat pas reconnu comme exe !!! + elif shutil.which(f): # green bg + print ("found executable in path") bgCol = QColor(0, 255, 0) else: #redBg #print "not found" -- GitLab