Last active
December 15, 2015 02:49
-
-
Save benguillet/5190447 to your computer and use it in GitHub Desktop.
A Django gist to send a text file and launch a program on a different server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if request.method == 'POST': | |
if form.is_valid(): | |
# write file in ~/hipercic/apps/dcor/jobs/ | |
with open('apps/dcor/jobs/job_' + datetime.today().strftime("%Y%m%d_%H%M%S") + '_params.txt', 'w') as params_file: | |
for key, val in form.cleaned_data.iteritems(): | |
params_file.write(str(val) + ' \n') | |
scp = 'scp /home/guillet/hipercic/' + params_file.name + ' [email protected]:dcor/jobs/' | |
context['scp'] = scp | |
return_code_scp = subprocess.call(scp, shell=True) | |
context['return_code_scp'] = return_code_scp | |
head, tail = os.path.split(params_file.name) | |
print tail | |
cpp = 'ssh [email protected] "cd dcor; ./test jobs/' + tail + '"' | |
context['cpp'] = cpp | |
return_code_cpp = subprocess.call(cpp, shell=True) | |
context['return_code_cpp'] = return_code_cpp | |
return render(request, 'base_pending.html', context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment