if args.has_key('gui') and args.has_key('session_gui'):
if not args['gui'] or not args['session_gui']:
toimport = args['pyscript']
- i = 0
- while i < len( toimport ) :
- if toimport[ i ] == 'killall':
+
+ for srcname in toimport :
+ if srcname == 'killall':
clt.showNS()
killAllPorts()
sys.exit(0)
else:
- scrname = toimport[ i ]
- if len(scrname) > 2 and (len(scrname) - string.rfind(scrname, ".py") == 3):
- print 'executing',scrname
- sys.path.insert( 0, os.path.dirname(scrname))
- execfile(scrname,globals())
- del sys.path[0]
+ if os.path.isabs(srcname):
+ if os.path.exists(srcname):
+ execScript(srcname)
+ elif os.path.exists(srcname+".py"):
+ execScript(srcname+".py")
+ else:
+ print "Can't execute file %s" % srcname
+ pass
else:
- print 'importing',scrname
- doimport = 'import ' + scrname
- exec doimport
- i = i + 1
-
+ found = False
+ for path in [os.getcwd()] + sys.path:
+ if os.path.exists(os.path.join(path,srcname)):
+ execScript(os.path.join(path,srcname))
+ found = True
+ break
+ elif os.path.exists(os.path.join(path,srcname+".py")):
+ execScript(os.path.join(path,srcname+".py"))
+ found = True
+ break
+ pass
+ if not found:
+ print "Can't execute file %s" % srcname
+ pass
+ pass
+ pass
+ pass
+ pass
return clt
+
+def execScript(script_path):
+ print 'executing', script_path
+ sys.path.insert(0, os.path.dirname(script_path))
+ execfile(script_path,globals())
+ del sys.path[0]
# -----------------------------------------------------------------------------