1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
from .hal_pythonplugin import *
try:
import importlib
support_aux_apps = True
except:
support_aux_apps = False
print("\n")
print("Gladevcp: Cannot import importlib")
print(" Auxiliary Gladevcp apps not available\n")
#----------------------------------------------------------------------
# Support auxiliary gladevcp apps
import os,sys,glob,subprocess
def excluded_filename(fname):
exclude_list = ["install","setup"]
for e in exclude_list:
if e in fname: return True
return False
if support_aux_apps:
#----------------------------------------------------------------------
modnames = []
#----------------------------------------------------------------------
# Auxiliary gladevcp apps specified by environmental variable
gladevcp_user_extras = os.getenv('GLADEVCP_EXTRAS')
if gladevcp_user_extras is not None:
print("gladevcp: GLADEVCP_EXTRAS:",gladevcp_user_extras)
for extradir in gladevcp_user_extras.split(":"):
for fname in glob.glob(extradir + "/*.py"):
if excluded_filename(fname):
print("gladevcp: excluded filename:",fname)
continue
modname = os.path.basename(fname).split(".")[0]
if modname in modnames:
print("gladevcp: rejecting duplicate:",fname)
continue
modnames.append(modname)
sys.path.insert(0,extradir) # prepend
importlib.import_module(modname)
print("gladevcp: importing:",fname)
#----------------------------------------------------------------------
# Auxiliary gladevcp apps may be installed in a known location
# location defined by the substitution item LINUXCNC_AUX_GLADEVCP.
# The location is available from the script linuxcnc_var
# (this script should always be in PATH for both RIP builds and
# deb installs of LinuxCNC)
s = subprocess.Popen(['linuxcnc_var','LINUXCNC_AUX_GLADEVCP']
,stdout=subprocess.PIPE
,stderr=subprocess.PIPE
)
p,e = s.communicate()
gladevcp_aux_apps_dir = p.strip().decode() # remove trailing \n
for auxdir in glob.glob(gladevcp_aux_apps_dir + "/*"):
print("gladevcp: auxiliary dir:",auxdir)
for fname in glob.glob(auxdir + "/*.py"):
if excluded_filename(fname):
print("gladevcp: excluded filename:",fname)
continue
modname = os.path.basename(fname).split(".")[0]
if modname in modnames:
print("gladevcp: rejecting duplicate:",fname)
continue
modnames.append(modname)
sys.path.insert(0,auxdir) # prepend
importlib.import_module(modname)
print("gladevcp: importing:",fname)
#----------------------------------------------------------------------
|