X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=bootauth.py;h=19353f45d5c3064f211a3846732af099c11416f5;hb=121219ac45fd954d3c7219c0f249fb1cddbc5105;hp=dae075c8a0b6a17301e944639ceccdb461566fde;hpb=3f01a8df5899602098c79b61b46ff54b48b1ae75;p=nodemanager.git diff --git a/bootauth.py b/bootauth.py index dae075c..19353f4 100755 --- a/bootauth.py +++ b/bootauth.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # Obtaining a node session key. Usually, the Boot # Manager obtains it, then writes it to /etc/planetlab/session. @@ -21,12 +21,12 @@ def main(): # Help def usage(): - print "Usage: %s [OPTION]..." % sys.argv[0] - print "Options:" - print " -f, --config=FILE PLC configuration file (default: /etc/planetlab/plc_config)" - print " -n, --node-id=FILE Node ID (or file)" - print " -k, --key=FILE Node key (or file)" - print " --help This message" + print("Usage: %s [OPTION]..." % sys.argv[0]) + print("Options:") + print(" -f, --config=FILE PLC configuration file (default: /etc/planetlab/plc_config)") + print(" -n, --node-id=FILE Node ID (or file)") + print(" -k, --key=FILE Node key (or file)") + print(" --help This message") sys.exit(1) # Get options @@ -36,8 +36,8 @@ def main(): "node=", "nodeid=", "node-id", "node_id", "key=", "help"]) - except getopt.GetoptError, err: - print "Error: " + err.msg + except getopt.GetoptError as err: + print("Error: " + err.msg) usage() for (opt, optval) in opts: @@ -45,12 +45,14 @@ def main(): config = Config(optval) elif opt == "-n" or opt == "--node" or opt == "--nodeid" or opt == "--node-id" or opt == "--node_id": if os.path.exists(optval): - node_id = file(optval).read().strip() + with open(optval) as optfile: + node_id = optfile.read().strip() else: node_id = int(optval) elif opt == "-k" or opt == "--key": if os.path.exists(optval): - key = file(optval).read().strip() + with open(optval) as optfile: + key = optfile.read().strip() else: key = optval else: @@ -70,7 +72,7 @@ def main(): plc = PLCAPI(config.plc_api_uri, config.cacert, session) assert session == plc.GetSession() - print session + print(session) if __name__ == '__main__': main()