still making both branches closer
[nepi.git] / src / nepi / resources / linux / node.py
index ee7e2e1..a411c64 100644 (file)
@@ -490,7 +490,8 @@ 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())
+                    # py2/py3 : keep it simple
+                    kill_pids = ' '.join(kill_pids)
 
                     # removing pids from beside connections and its process
                     kill_pids = kill_pids.split(' ')
@@ -766,15 +767,17 @@ class LinuxNode(ResourceManager):
         if text and not os.path.isfile(src):
             # src is text input that should be uploaded as file
             # create a temporal file with the content to upload
-            f = tempfile.NamedTemporaryFile(delete=False)
+            # in python3 we need to open in binary mode if str is bytes
+            mode = 'w' if isinstance(src, str) else 'wb'
+            f = tempfile.NamedTemporaryFile(mode=mode, delete=False)
             f.write(src)
             f.close()
             src = f.name
 
         # If dst files should not be overwritten, check that the files do not
-        # exits already
+        # exist already
         if isinstance(src, str):
-            src = map(str.strip, src.split(";"))
+            src = [s.strip() for s in src.split(";")]
     
         if overwrite == False:
             src = self.filter_existing_files(src, dst)
@@ -904,7 +907,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)
     
@@ -1074,7 +1077,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:
@@ -1177,14 +1180,14 @@ class LinuxNode(ResourceManager):
                 if len(src) > 1 else {dst: src[0]}
 
         command = []
-        for d in dests.keys():
+        for d in dests:
             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 dests:
             if out.find(d) > -1:
                 del dests[d]