node.upload knows how to optionnally create executable files
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 9 Mar 2016 14:40:09 +0000 (15:40 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 9 Mar 2016 14:55:42 +0000 (15:55 +0100)
application.upload_code takes advantage of that
--
this way we can upload a shell script usable as ${APP_HOME}/code

nepi/resources/linux/application.py
nepi/resources/linux/node.py

index 447b5ad..4b60f46 100644 (file)
@@ -469,7 +469,7 @@ class LinuxApplication(ResourceManager):
             self.info("Uploading code")
 
             dst = os.path.join(self.app_home, "code")
-            self.node.upload(code, dst, overwrite = False, text = True)
+            self.node.upload(code, dst, overwrite = False, text = True, executable = True)
 
     def upload_stdin(self, stdin = None):
         if not stdin:
index 32b590e..3043857 100644 (file)
@@ -25,6 +25,7 @@ from nepi.util.sshfuncs import ProcStatus
 
 import collections
 import os
+import stat
 import random
 import re
 import tempfile
@@ -742,7 +743,7 @@ class LinuxNode(ResourceManager):
         return (out, err), proc
 
     def upload(self, src, dst, text = False, overwrite = True,
-               raise_on_error = True):
+               raise_on_error = True, executable = False):
         """ Copy content to destination
 
         src  string with the content to copy. Can be:
@@ -754,8 +755,9 @@ class LinuxNode(ResourceManager):
         dst  string with destination path on the remote host (remote is 
             always self.host)
 
-        text src is text input, it must be stored into a temp file before 
-        uploading
+        when src is text input, it gets stored into a temp file before 
+        uploading; in this case, and if executable is True, said temp file
+        is made executable, and thus uploaded file will be too
         """
         # If source is a string input 
         f = None
@@ -767,6 +769,12 @@ class LinuxNode(ResourceManager):
             f = tempfile.NamedTemporaryFile(mode=mode, delete=False)
             f.write(src)
             f.close()
+            if executable:
+                # do something like chmod u+x
+                mode = os.stat(f.name).st_mode
+                mode |= stat.S_IXUSR
+                os.chmod(f.name, mode)
+                
             src = f.name
 
         # If dst files should not be overwritten, check that the files do not