From: Tony Mack Date: Mon, 28 Jan 2008 16:59:37 +0000 (+0000) Subject: if executing a file, add the file's directory to the path to so that other files... X-Git-Tag: PLCAPI-4.2-1~3 X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=commitdiff_plain;h=a39c1f088910100df76b32a7f1d3a98528ca226b if executing a file, add the file's directory to the path to so that other files from the directory can be imported --- diff --git a/plcsh b/plcsh index e18c1d4..9997c15 100755 --- a/plcsh +++ b/plcsh @@ -59,15 +59,17 @@ except Exception, err: parser.print_help() sys.exit(1) -# If called by a script or api call is passed -if len(sys.argv) > 1: +# If called by a script +if len(sys.argv) > 1 and os.path.exists(sys.argv[1]): # Pop us off the argument stack sys.argv.pop(0) - if os.path.exists(sys.argv[0]) and os.path.isfile(sys.argv[0]): - execfile(sys.argv[0]) - else: - print eval(sys.argv[0]) - sys.exit(0) + script = sys.argv[0] + # Add of script to sys.path + path = os.path.dirname(os.path.abspath(script)) + sys.path.append(path) + from pprint import pprint + pprint(sys.path) + execfile(sys.argv[0]) # Otherwise, run an interactive shell environment else: