Call bash from template

27 views
Skip to first unread message

vitsin

unread,
Jun 10, 2012, 10:35:56 PM6/10/12
to satchm...@googlegroups.com
hi,
is it possible to call some how from Satchmo bash script?
I'm trying to implement a button in the shop with some particular custom functionality
and it requires run of the bash with passing bunch of args from template into the bash.

regards,
--vs

Ryan Headley

unread,
Jun 11, 2012, 8:54:43 AM6/11/12
to satchm...@googlegroups.com

Probably something you should never do...i would highly recimmend against it.  Plus why not just use python to do what you are trying to do?
But if i had a gun ti my head....i'd write a template tag and have code in the tag shell out to the system....#yuck#...no offense intended.

--
You received this message because you are subscribed to the Google Groups "Satchmo users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/satchmo-users/-/VL4j7ISY-a8J.
To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.

vitsin

unread,
Jun 11, 2012, 10:59:53 AM6/11/12
to satchm...@googlegroups.com
:-)
well,
what the difference between calling Python based API with some functionality instead of calling bash script with Popen if both will do the same functional work?
Try to Explain your point of view instead of using f... words., cause THAT is definitely unprofessional, cheers.

Look like original question was not clear enough.
--vs



On Monday, June 11, 2012 8:54:43 AM UTC-4, lifewithryan wrote:

Probably something you should never do...i would highly recimmend against it.  Plus why not just use python to do what you are trying to do?
But if i had a gun ti my head....i'd write a template tag and have code in the tag shell out to the system....#yuck#...no offense intended.

On Jun 10, 2012 9:35 PM, "vitsin" <vitaly....@gmail.com> wrote:
hi,
is it possible to call some how from Satchmo bash script?
I'm trying to implement a button in the shop with some particular custom functionality
and it requires run of the bash with passing bunch of args from template into the bash.

regards,
--vs

--
You received this message because you are subscribed to the Google Groups "Satchmo users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/satchmo-users/-/VL4j7ISY-a8J.
To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-users+unsubscribe@googlegroups.com.

Tomas Neme

unread,
Jun 11, 2012, 11:25:00 AM6/11/12
to satchm...@googlegroups.com

> what the difference between calling Python based API with some functionality
> instead of calling bash script with Popen if both will do the same
> functional work?
> Try to Explain your point of view instead of using f... words., cause THAT
> is definitely unprofessional, cheers.

easier to debug, cleaner code, more cross-platform... I wanted to do that too, once, but I also came to the conclusion it wasn't a good idea.

And.. while you're right, "ugly" is a perfectly good reason for not doing something, it's in the very first line of the Zen of Python:

lacrymology@Roller:boilerplate$ python -c 'import this'
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

******

with that out of the way, also, whatever it is you want to do, it sounds blocking and time-consuming, which is something you probably don't want in a template.

I recommend you explain what you need to do, and you'll get a recommendation on how to do it in a more pythonic way

--
"The whole of Japan is pure invention. There is no such country, there are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny 
(")_(") to help him gain world domination.

Ryan Headley

unread,
Jun 11, 2012, 2:42:39 PM6/11/12
to satchm...@googlegroups.com
Did I miss something?  Where was there an F word?  I did say #yuck# but nowhere did I drop the f-bomb.

My point is, shelling out to bash sounds like a complete hack.  Not to mention that if someone were capable enough to cause your code to segfault, they could be left with elevated privileges on the target system...if the code were in python and it segfaulted, so would their access...

--
You received this message because you are subscribed to the Google Groups "Satchmo users" group.
To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.

vitsin

unread,
Jun 11, 2012, 6:12:24 PM6/11/12
to satchm...@googlegroups.com
This is all coming from the fact that I'm pretty new to front-end development.
Thanks anyway.

OK,
so let's say I need my template to call some JAR and get back from it some /path/file.ext, mean real file that I wanna show in this template.
Than how with Django+Satchmo can I achieve this please?

regards,
--vs

Dave Brown

unread,
Jun 11, 2012, 6:16:36 PM6/11/12
to satchm...@googlegroups.com
@Ryan - definitely with ya on the f-bomb - did I miss something too?  

Vitsin - as Tomas said, try to explain what you are trying to do, not how you would like to do it.

Dave


--
You received this message because you are subscribed to the Google Groups "Satchmo users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/satchmo-users/-/nlJf0vQt_u0J.

To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.



--
Dave Brown
CEO/Founder
Rampframe.com - Action Sports Network

Tom Longson (nym)

unread,
Jun 11, 2012, 6:22:23 PM6/11/12
to satchm...@googlegroups.com
@Dave - had he done that, nobody would have replied ;-)

Protip: To getting help on mailing lists/irc- state the wrong way to do something, and everyone and their mother will "correct" you.

Tomas Neme

unread,
Jun 11, 2012, 6:55:17 PM6/11/12
to satchm...@googlegroups.com
> OK,
> so let's say I need my template to call some JAR and get back from it some
> /path/file.ext, mean real file that I wanna show in this template.
> Than how with Django+Satchmo can I achieve this please?

#yuck# indeed :/

not sure, but maybe this may help?
http://stackoverflow.com/questions/3652554/calling-java-from-python

vitsin

unread,
Jun 11, 2012, 8:46:27 PM6/11/12
to satchm...@googlegroups.com
I'm happy you boys having fun :-)

I'll try again, less generic, more specific.

Satchmo (and other e-Commerse open source solutions like JadaSite, Shopizer, etc) see the main concept of Product as bunch of predefined by admin Products and their properties.
What my shop needs is: Generic product while its being created by User (not admin) from certain peaces.

Let's say user defined such Generic product from template conf param-s (what ever they are) and now click on Preview button to see picture of what it could be at the end.
By clicking on Preview, I need on server side to start over some bash/p-language wrapper for bunch of JARs that we'll be exec() in certain sequence and return back
raster image file(or error msg).

What's the Django/Satchmo way to do such Preview functionality please?

regards,
--vs

Dave Brown

unread,
Jun 11, 2012, 10:55:42 PM6/11/12
to satchm...@googlegroups.com
Vitsin - 
It sounds like you want a user-defined customized product.  Not sure what all the java stuff is, but we can just ignore that part for now. 

Unfortunately I don't think this is really a question you can toss up on an email forum and expect to get an 'answer'.  
You're obviously going to need to write some custom views and models, etc.  Trying to define this over an email is pretty tough.

All i can say is - start digging into it and see where it takes you.

good luck
Dave


--
You received this message because you are subscribed to the Google Groups "Satchmo users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/satchmo-users/-/lxTXp_goRYQJ.

To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.

Tomas Neme

unread,
Jun 12, 2012, 11:22:21 AM6/12/12
to satchm...@googlegroups.com
> What my shop needs is: Generic product while its being created by User (not
> admin) from certain peaces.

you mean "pieces", and satchmo has a CustomProduct class which might
be what you need (in terms of creating and charging for the product).

As per the visualization, I don't know, but I'm sure there're analog
libraries to those JAR you're talking about

Since you've already have the functionality there, you can of course
(this would be the answer to your original question) use
subprocess.Popen to run your JAR, but I'd really look into an analog
python library before doing that, unless you have a very strong reason
not to. PIL is the library normally used to generate graphics (you
already have it, if you're running satchmo), but I don't know the API
so I'm not sure how you'd go about generating the graphics you need

also, don't use Popen, use these:
and PROBABLY (but I'm not certain of what you want to do, exactly) the
way of doing it is creating a custom templatetag for the processing.

Yet ANOTHER way of doing it is printing the image link with some
parameters. For example something like: <img
src="/dyanmic/images/product/cpu.png?casing=hellfire&color=red&monitor=smsyncms23"
/> and then have the generation of the image in the
/dynamic/images/product/ view.

It all depends on the API you have and how you want to implement it.

But yes, the basic answer you're going to get is "better if you try to
do this with a python library". You can try asking more people in the
django mailing list or #django in irc.freenode.org

Chris Dukes

unread,
Jun 12, 2012, 8:14:11 PM6/12/12
to satchm...@googlegroups.com
On Mon, Jun 11, 2012 at 05:46:27PM -0700, vitsin wrote:
> I'm happy you boys having fun :-)
>
> I'll try again, less generic, more specific.
>
> Satchmo (and other e-Commerse open source solutions like JadaSite,
> Shopizer, etc) see the main concept of Product as bunch of predefined by
> admin Products and their properties.
> What my shop needs is: Generic product while its being created by User (not
> admin) from certain peaces.
>
> Let's say user defined such Generic product from template conf param-s
> (what ever they are) and now click on Preview button to see picture of what
> it could be at the end.
> By clicking on Preview, I need on server side to start over some
> bash/p-language wrapper for bunch of JARs that we'll be exec() in certain
> sequence and return back
> raster image file(or error msg).
>
> What's the Django/Satchmo way to do such Preview functionality please?

This part isn't django specific.

When running java cruft outside of command line interactive or from
a build system such as a Makefile you aim to do the work with the
minimum number of long running servers running from an equal or
smaller number of persistant JVMs. You interface using the lightest
protocol for which you understand how to debug.

Ideally, have a long running JVM running a single server that speaks a simple
protocol such as HTTP that accepts a config on input, calls your own
custom java that uses the classes in those jars in an appropriate
sequence, then spits the image back from where it came.
(Or returns a location of where the image is, and drops the image out
as a file named by a hash of the config, so you can cache the work
for identical config files).

Starting a JVM is expensive.
If you leave the JVM running you can split the cost of starting the JVM
across multiple previews.

This part is django specific.
When you get the config, store it in a format that the java can use in
a text or blob field in an appropriate model, along with a short hash
or ID.
In your django template for the image you give a URL based off of the hash or
ID. An http get request against that URL would be sent to the java
to either retrieve a cached image for the config, or generate the
image and send it. Your long running java process would have atleast
read access to the same database to be able to retrieve the config from
it.
> --vs
>
>
> On Monday, June 11, 2012 6:55:17 PM UTC-4, Tomas Neme wrote:
> >
> > > OK,
> > > so let's say I need my template to call some JAR and get back from it
> > some
> > > /path/file.ext, mean real file that I wanna show in this template.
> > > Than how with Django+Satchmo can I achieve this please?
> >
> > #yuck# indeed :/
> >
> > not sure, but maybe this may help?
> > http://stackoverflow.com/questions/3652554/calling-java-from-python
> >
> > --
> > "The whole of Japan is pure invention. There is no such country, there are
> > no such people" --Oscar Wilde
> >
> > |_|0|_|
> > |_|_|0|
> > |0|0|0|
> >
> > (\__/)
> > (='.'=)This is Bunny. Copy and paste bunny
> > (")_(") to help him gain world domination.
> >
>
> --
> You received this message because you are subscribed to the Google Groups "Satchmo users" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/satchmo-users/-/lxTXp_goRYQJ.
> To post to this group, send email to satchm...@googlegroups.com.
> To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.
>

--
Chris Dukes.
This message is not confidential. Due to the nature of how email is
sent, it's only slightly more private than a postcard. Use GPG if you
want correspondence to be confidential and private.
Reply all
Reply to author
Forward
0 new messages