X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plcsh;h=15a42a5c84762120b6f3459703f9fa00d9d47476;hb=1b1b5a911bb005644baabb87ecba60602228a070;hp=ef434ace08190d10d44d00cfcc57922d051859a3;hpb=bd46d3f265c3655e432815df9ab7aa6796a3a76b;p=plcapi.git diff --git a/plcsh b/plcsh index ef434ac..15a42a5 100755 --- a/plcsh +++ b/plcsh @@ -32,7 +32,8 @@ parser.add_option("-s", "--session", help = "API session key") parser.add_option("-u", "--user", help = "API user name") parser.add_option("-p", "--password", help = "API password") parser.add_option("-r", "--role", help = "API role") -parser.add_option("-x", "--xmlrpc", action = "store_true", default = False, help = "Use XML-RPC interface") +parser.add_option("-x", "--xmlrpc", action = "store_true", + default = False, help = "Use XML-RPC interface") # pass this to the invoked shell if any parser.add_option("--help", action = "store_true", dest="help", default=False, help = "show this help message and exit") @@ -40,7 +41,7 @@ parser.add_option("--help", action = "store_true", dest="help", default=False, if not args and options.help: parser.print_help() - sys.exit(1) + sys.exit(1) # If user is specified but password is not if options.user is not None and options.password is None: @@ -69,7 +70,7 @@ except Exception as err: parser.print_help() sys.exit(1) -# If called by a script +# If called by a script if args: if not os.path.exists(args[0]): print('File %s not found'%args[0]) @@ -82,10 +83,11 @@ if args: # use args as sys.argv for the next shell, so our own options get removed for the next script sys.argv = args script = sys.argv[0] - # Add of script to sys.path + # Add of script to sys.path path = os.path.dirname(os.path.abspath(script)) sys.path.append(path) - exec(compile(open(script).read(), script, 'exec')) + with open(script) as feed: + exec(feed.read()) # Otherwise, run an interactive shell environment else: @@ -114,7 +116,9 @@ else: # Load command history history_path = os.path.join(os.environ["HOME"], ".plcapi_history") try: - file(history_path, 'a').close() + # check directory: pretend to open + with open(history_path, 'a') as check: + pass readline.read_history_file(history_path) atexit.register(readline.write_history_file, history_path) except IOError: