always use print_function
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 23 Jun 2015 07:24:37 +0000 (09:24 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 23 Jun 2015 07:24:37 +0000 (09:24 +0200)
source/RunlevelAgent.py
source/steps/AuthenticateWithPLC.py
source/steps/ChainBootNode.py
source/steps/ConfirmInstallWithUser.py
source/steps/InstallBootstrapFS.py
source/steps/WriteNetworkConfig.py
source/utils.py

index 012dba1..9844648 100755 (executable)
@@ -7,6 +7,8 @@
 #   so that it is immediately visible at myplc (gui or api).
 # 
 
+from __future__ import print_function
+
 import xml, xmlrpclib
 import logging
 import time
@@ -32,7 +34,7 @@ def read_config_file(filename):
 
         parts = string.split(line, "=")
         if len(parts) != 2:
-            print "Invalid line in vars file: {}".format(line)
+            print("Invalid line in vars file: {}".format(line))
             validConfFile = False
             break
 
@@ -42,7 +44,7 @@ def read_config_file(filename):
 
     vars_file.close()
     if not validConfFile:
-        print "Unable to read configuration vars."
+        print("Unable to read configuration vars.")
 
     return vars
 
@@ -103,7 +105,7 @@ def save_pid():
         f.write("{}\n".format(pid))
         f.close()
     except:
-        print "Uuuhhh.... this should not occur."
+        print("Uuuhhh.... this should not occur.")
         sys.exit(1)
 
 def start_and_run():
@@ -122,7 +124,7 @@ def start_and_run():
             api.AuthCheck()
             break
         except:
-            print "Retry in 30 seconds: ", os.popen("uptime").read().strip()
+            print("Retry in 30 seconds: ", os.popen("uptime").read().strip())
             traceback.print_exc()
             time.sleep(30)
 
@@ -168,7 +170,7 @@ def start_and_run():
                 api.ReportRunlevel({'run_level' : 'failboot'})
                 
         except:
-            print "reporting error: ", os.popen("uptime").read().strip()
+            print("reporting error: ", os.popen("uptime").read().strip())
             traceback.print_exc()
 
         sys.stdout.flush()
index 2e71a1c..2282dd6 100644 (file)
@@ -87,5 +87,3 @@ def Run(vars, log):
         log.write("Canceling boot process and going into debug mode.\n")
 
     raise BootManagerException("Unable to authenticate node.")
-    
-
index 78337ab..f21a2ff 100644 (file)
@@ -94,7 +94,6 @@ def Run(vars, log):
 
         ROOT_MOUNTED = 1
         vars['ROOT_MOUNTED'] = 1
-        
 
     # write out the session value /etc/planetlab/session
     try:
index 7144e15..1a18387 100644 (file)
@@ -6,6 +6,8 @@
 # Copyright (c) 2004-2006 The Trustees of Princeton University
 # All rights reserved.
 
+from __future__ import print_function
+
 from Exceptions import *
 
 welcome_message= \
@@ -49,7 +51,7 @@ def Run(vars, log):
     try:
         confirmation = ""
         install = 0
-        print welcome_message
+        print(welcome_message)
         
         while confirmation not in ("yes","no"):
             confirmation = \
index 06f9807..0587057 100644 (file)
@@ -165,7 +165,7 @@ def Run(vars, log):
                 raise BootManagerException(
                     "FATAL: Unable to download main tarball {} from server."\
                     .format(source_file))
-            # for extensions, just print a warning
+            # for extensions, just issue a warning
             else:
                 log.write("WARNING: tarball for extension {} not found\n".format(name))
 
index 610bff8..e7d624a 100644 (file)
@@ -110,44 +110,39 @@ def Run(vars, log):
     # Node Manager needs at least PLC_API_HOST and PLC_BOOT_HOST
     log.write("Writing /etc/planetlab/plc_config\n")
     utils.makedirs("{}/etc/planetlab".format(SYSIMG_PATH))
-    plc_config = file("{}/etc/planetlab/plc_config".format(SYSIMG_PATH), "w")
-
-    api_url = vars['BOOT_API_SERVER']
-    (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(api_url)
-    parts = netloc.split(':')
-    host = parts[0]
-    if len(parts) > 1:
-        port = parts[1]
-    else:
-        port = '80'
-    try:
-        log.write("getting via https://{}/PlanetLabConf/get_plc_config.php ".format(host))
-        bootserver = httplib.HTTPSConnection(host, int(port))
-        bootserver.connect()
-        bootserver.request("GET","https://{}/PlanetLabConf/get_plc_config.php".format(host))
-        plc_config.write("{}".format(bootserver.getresponse().read()))
-        bootserver.close()
-        log.write("Done\n")
-    except:
-        log.write(" .. Failed.  Using old method. -- stack trace follows\n")
-        traceback.print_exc(file=log.OutputFile)
-        bs = BootServerRequest.BootServerRequest(vars)
-        if bs.BOOTSERVER_CERTS:
-            print >> plc_config, "PLC_BOOT_HOST='{}'".format(bs.BOOTSERVER_CERTS.keys()[0])
-        print >> plc_config, "PLC_API_HOST='{}'".format(host)
-        print >> plc_config, "PLC_API_PORT='{}'".format(port)
-        print >> plc_config, "PLC_API_PATH='{}'".format(path)
-
-    plc_config.close()
-
+    with open("{}/etc/planetlab/plc_config".format(SYSIMG_PATH), "w") as plc_config:
+    
+        api_url = vars['BOOT_API_SERVER']
+        (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(api_url)
+        parts = netloc.split(':')
+        host = parts[0]
+        if len(parts) > 1:
+            port = parts[1]
+        else:
+            port = '80'
+        try:
+            log.write("getting via https://{}/PlanetLabConf/get_plc_config.php ".format(host))
+            bootserver = httplib.HTTPSConnection(host, int(port))
+            bootserver.connect()
+            bootserver.request("GET","https://{}/PlanetLabConf/get_plc_config.php".format(host))
+            plc_config.write("{}".format(bootserver.getresponse().read()))
+            bootserver.close()
+            log.write("Done\n")
+        except:
+            log.write(" .. Failed.  Using old method. -- stack trace follows\n")
+            traceback.print_exc(file=log.OutputFile)
+            bs = BootServerRequest.BootServerRequest(vars)
+            if bs.BOOTSERVER_CERTS:
+                plc_config.write("PLC_BOOT_HOST='{}'\n".format(bs.BOOTSERVER_CERTS.keys()[0]))
+            plc_config.write("PLC_API_HOST='{}'\n".format(host))
+            plc_config.write("PLC_API_PORT='{}'\n".format(port))
+            plc_config.write("PLC_API_PATH='{}'\n".format(path))
 
     log.write("Writing /etc/hosts\n")
-    hosts_file = file("{}/etc/hosts".format(SYSIMG_PATH), "w")    
-    hosts_file.write("127.0.0.1       localhost\n")
-    if method == "static":
-        hosts_file.write("{} {}.{}\n".format(ip, hostname, domainname))
-    hosts_file.close()
-    hosts_file = None
+    with open("{}/etc/hosts".format(SYSIMG_PATH), "w") as hosts_file:
+        hosts_file.write("127.0.0.1       localhost\n")
+        if method == "static":
+            hosts_file.write("{} {}.{}\n".format(ip, hostname, domainname))
     
     data =  {'hostname': '{}.{}'.format(hostname, domainname),
              'networks': vars['INTERFACES']}
index 5ad3ec7..70f37fd 100644 (file)
@@ -7,6 +7,8 @@
 # All rights reserved.
 # expected /proc/partitions format
 
+from __future__ import print_function
+
 import os, sys, shutil
 import subprocess
 import shlex
@@ -75,7 +77,7 @@ def breakpoint (message, cmd = None):
             cmd = "/bin/sh"
             message = message + " -- Entering bash - type ^D to proceed"
 
-        print message
+        print(message)
         os.system(cmd)
 
 
@@ -142,13 +144,13 @@ def sysexec(cmd, log=None, fsck=False, shell=False):
             if log is not None:
                 log.write("sysexec (shell mode) >>> {}".format(cmd))
             if VERBOSE_MODE:
-                print "sysexec (shell mode) >>> {}".format(cmd)
+                print("sysexec (shell mode) >>> {}".format(cmd))
         else:
             prog = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
             if log is not None:
                 log.write("sysexec >>> {}\n".format(cmd))
             if VERBOSE_MODE:
-                print "sysexec >>> {}".format(cmd)
+                print("sysexec >>> {}".format(cmd))
     except OSError:
         raise BootManagerException(
               "Unable to create instance of subprocess.Popen "