Friday, March 25, 2016

Re: Simple subprocess help

On 26/03/2016 1:05 AM, Joshua Valdez wrote:
> Okay, so I have figured out that the subprocess is the module that I
> want to use in this context and I have tried implementing some simple
> code based on the documentation but I am getting an
>
> |ExceptionType:OSErrorExceptionValue:[Errno2]Nosuch file or directory
> ExceptionLocation:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py
> in _execute_child,line 1335.|
>
> A brief overview of what I'm trying to do:
>
> This is the code I have in views. Its intent is to take text input from
> the model form, POST that to the DB and then pass that input into my
> script which produces an XML file which is stored in another column in
> the DB. I'm very new to django so I'm sorry if this is an simple fix,
> but I couldn't find any documentation relating django to subprocess that
> was helpful.
>

What is the problem for which subprocess the solution?

> |def queries_create(request):ifnot
> request.user.is_authenticated():returnrender(request,'login_error.html')form
> =QueryForm(request.POST or None)ifform.is_valid():instance
> =form.save(commit=False)instance.save()p=subprocess.Popen([request.POST['post'],'./path/to/run_pipeline.sh'])p.save()context
> ={"title":"Create","form":form,}returnrender(request,"query_form.html",context)|

If run_pipeline.sh is converts form input to XML it is happening outside
of Django.

Ignorant of what you are really doing, I would be looking to write a
Python equivalent of run_pipeline so that the model instance can do the
conversion as part of its save() process - completely invisible from the
form.

It feels overly complex to trigger an external event then incorporate
the result in a different column - presumably a different field in the
same model.

Mike

>
> Model code snippet:
>
> |classQuery(models.Model):problem/intervention =models.TextField()updated
> =models.DateTimeField(auto_now=True,auto_now_add=False)timestamp
> =models.DateTimeField(auto_now=False,auto_now_add=True)|
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3695d62e-6633-4dae-8afe-792b917cc0b4%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3695d62e-6633-4dae-8afe-792b917cc0b4%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/56F5F8A1.50400%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment