From 10ddf71cfe290a9de4ac06fc55b8d335b94c2d52 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 9 Mar 2016 15:40:09 +0100 Subject: [PATCH] node.upload knows how to optionnally create executable files 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 | 2 +- nepi/resources/linux/node.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/nepi/resources/linux/application.py b/nepi/resources/linux/application.py index 447b5ad1..4b60f463 100644 --- a/nepi/resources/linux/application.py +++ b/nepi/resources/linux/application.py @@ -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: diff --git a/nepi/resources/linux/node.py b/nepi/resources/linux/node.py index 32b590e2..30438579 100644 --- a/nepi/resources/linux/node.py +++ b/nepi/resources/linux/node.py @@ -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 -- 2.43.0