Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Django gist to send a text file and launch a program on a different server
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 + ' guillet@helios.public.stolaf.edu: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 guillet@helios.public.stolaf.edu "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