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