a first very rough step towards python3
[nepi.git] / src / nepi / resources / linux / node.py
index 16b9b00..b440038 100644 (file)
@@ -297,7 +297,7 @@ class LinuxNode(ResourceManager):
         if not self.localhost and not self.get("username"):
             msg = "Can't resolve OS, insufficient data "
             self.error(msg)
-            raise RuntimeError, msg
+            raise RuntimeError(msg)
 
         out = self.get_os()
 
@@ -355,7 +355,7 @@ class LinuxNode(ResourceManager):
             trace = traceback.format_exc()
             msg = "Deploy failed. Unresponsive node {} -- traceback {}".format(self.get("hostname"), trace)
             self.error(msg)
-            raise RuntimeError, msg
+            raise RuntimeError(msg)
 
         self.find_home()
 
@@ -489,7 +489,7 @@ class LinuxNode(ResourceManager):
                     # adding the avoided pids filtered above (avoid_kill) to allow users keep process
                     # alive when using besides ssh connections  
                     kill_pids = set(pids_temp.items()) - set(pids.items())
-                    kill_pids = ' '.join(dict(kill_pids).keys())
+                    kill_pids = ' '.join(list(dict(kill_pids).keys()))
 
                     # removing pids from beside connections and its process
                     kill_pids = kill_pids.split(' ')
@@ -773,7 +773,7 @@ class LinuxNode(ResourceManager):
         # If dst files should not be overwritten, check that the files do not
         # exits already
         if isinstance(src, str):
-            src = map(str.strip, src.split(";"))
+            src = list(map(str.strip, src.split(";")))
     
         if overwrite == False:
             src = self.filter_existing_files(src, dst)
@@ -796,7 +796,7 @@ class LinuxNode(ResourceManager):
             
             msg = "{} out: {} err: {}".format(msg, out, err)
             if raise_on_error:
-                raise RuntimeError, msg
+                raise RuntimeError(msg)
 
         return ((out, err), proc)
 
@@ -812,7 +812,7 @@ class LinuxNode(ResourceManager):
             self.error(msg, out, err)
 
             if raise_on_error:
-                raise RuntimeError, msg
+                raise RuntimeError(msg)
 
         return ((out, err), proc)
 
@@ -825,7 +825,7 @@ class LinuxNode(ResourceManager):
         else:
             msg = "Error installing packages ( OS not known ) "
             self.error(msg, self.os)
-            raise RuntimeError, msg
+            raise RuntimeError(msg)
 
         return command
 
@@ -866,7 +866,7 @@ class LinuxNode(ResourceManager):
         else:
             msg = "Error removing packages ( OS not known ) "
             self.error(msg)
-            raise RuntimeError, msg
+            raise RuntimeError(msg)
 
         run_home = run_home or home
 
@@ -903,7 +903,7 @@ class LinuxNode(ResourceManager):
         if isinstance(paths, str):
             paths = [paths]
 
-        cmd = " ; ".join(map(lambda path: "rm -rf {}".format(path), paths))
+        cmd = " ; ".join(["rm -rf {}".format(path) for path in paths])
 
         return self.execute(cmd, with_lock = True)
     
@@ -950,7 +950,7 @@ class LinuxNode(ResourceManager):
             msg = " Failed to run command '{}' ".format(command)
             self.error(msg, out, err)
             if raise_on_error:
-                raise RuntimeError, msg
+                raise RuntimeError(msg)
 
         # Wait for pid file to be generated
         pid, ppid = self.wait_pid(
@@ -972,7 +972,7 @@ class LinuxNode(ResourceManager):
                 self.error(msg, eout, err)
 
                 if raise_on_error:
-                    raise RuntimeError, msg
+                    raise RuntimeError(msg)
 
         (out, oerr), proc = self.check_output(home, stdout)
         
@@ -1073,7 +1073,7 @@ class LinuxNode(ResourceManager):
         pid = ppid = None
         delay = 1.0
 
-        for i in xrange(2):
+        for i in range(2):
             pidtuple = self.getpid(home = home, pidfile = pidfile)
             
             if pidtuple:
@@ -1087,7 +1087,7 @@ class LinuxNode(ResourceManager):
             self.error(msg)
     
             if raise_on_error:
-                raise RuntimeError, msg
+                raise RuntimeError(msg)
 
         return pid, ppid
 
@@ -1166,7 +1166,7 @@ class LinuxNode(ResourceManager):
 
         if not self._home_dir:
             self.error(msg)
-            raise RuntimeError, msg
+            raise RuntimeError(msg)
 
     def filter_existing_files(self, src, dst):
         """ Removes files that already exist in the Linux host from src list
@@ -1176,19 +1176,19 @@ class LinuxNode(ResourceManager):
                 if len(src) > 1 else {dst: src[0]}
 
         command = []
-        for d in dests.keys():
+        for d in list(dests.keys()):
             command.append(" [ -f {dst} ] && echo '{dst}' ".format(dst=d) )
 
         command = ";".join(command)
 
         (out, err), proc = self.execute(command, retry = 1, with_lock = True)
         
-        for d in dests.keys():
+        for d in list(dests.keys()):
             if out.find(d) > -1:
                 del dests[d]
 
         if not dests:
             return []
 
-        return dests.values()
+        return list(dests.values())