X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plcsh;h=ef434ace08190d10d44d00cfcc57922d051859a3;hb=bd46d3f265c3655e432815df9ab7aa6796a3a76b;hp=7bc3abe214c9a46a962c64360ce87d59cd037e36;hpb=3b44c0228c26dc43d985185afc225caa5f48c1fb;p=plcapi.git diff --git a/plcsh b/plcsh index 7bc3abe..ef434ac 100755 --- a/plcsh +++ b/plcsh @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # Interactive shell for testing PLCAPI # @@ -47,7 +47,7 @@ if options.user is not None and options.password is None: try: options.password = getpass() except (EOFError, KeyboardInterrupt): - print + print() sys.exit(0) # Initialize a single global instance (scripts may re-initialize @@ -63,16 +63,16 @@ try: auth = shell.auth api = shell.api config = shell.config -except Exception, err: - print "Error:", err - print +except Exception as err: + print("Error:", err) + print() parser.print_help() sys.exit(1) # If called by a script if args: if not os.path.exists(args[0]): - print 'File %s not found'%args[0] + print('File %s not found'%args[0]) parser.print_help() sys.exit(1) else: @@ -85,32 +85,32 @@ if args: # Add of script to sys.path path = os.path.dirname(os.path.abspath(script)) sys.path.append(path) - execfile(script) + exec(compile(open(script).read(), script, 'exec')) # Otherwise, run an interactive shell environment else: if shell.server is None: - print "PlanetLab Central Direct API Access" + print("PlanetLab Central Direct API Access") prompt = "" elif shell.auth['AuthMethod'] == "anonymous": prompt = "[anonymous]" - print "Connected anonymously" + print("Connected anonymously") elif shell.auth['AuthMethod'] == "session": # XXX No way to tell node and user sessions apart from the # client point of view. prompt = "[%s]" % gethostname() - print "%s connected using session authentication" % gethostname() + print("%s connected using session authentication" % gethostname()) else: prompt = "[%s]" % shell.auth['Username'] - print "%s connected using %s authentication" % \ - (shell.auth['Username'], shell.auth['AuthMethod']) + print("%s connected using %s authentication" % \ + (shell.auth['Username'], shell.auth['AuthMethod'])) # Readline and tab completion support import atexit import readline import rlcompleter - print 'Type "system.listMethods()" or "help(method)" for more information.' + print('Type "system.listMethods()" or "help(method)" for more information.') # Load command history history_path = os.path.join(os.environ["HOME"], ".plcapi_history") try: @@ -133,11 +133,11 @@ else: sep = ">>> " else: sep = "... " - line = raw_input(prompt + sep) + line = input(prompt + sep) # Ctrl-C except KeyboardInterrupt: command = "" - print + print() break # Build up multi-line command @@ -161,13 +161,13 @@ else: # Try evaluating as an expression and printing the result result = eval(command) if result is not None: - print result + print(result) except SyntaxError: # Fall back to executing as a statement - exec command - except Exception, err: + exec(command) + except Exception as err: print_exc() except EOFError: - print + print() pass