Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   how to test for a dependency (http://www.velocityreviews.com/forums/t353209-how-to-test-for-a-dependency.html)

Darren Dale 01-09-2006 09:16 PM

how to test for a dependency
 
Hello,

I would like to test that latex is installed on a windows, mac or linux
machine. What is the best way to do this? This should work:

if os.system('latex -v'):
print 'please install latex'

but I dont actually want the latex version information to print to screen. I
tried redirecting sys.stdout to a file, but that doesnt help. Is there a
better way to do this in a cross-platform friendly way?

Thanks,
Darren

Dennis Benzinger 01-09-2006 09:30 PM

Re: how to test for a dependency
 
Darren Dale schrieb:
> Hello,
>
> I would like to test that latex is installed on a windows, mac or linux
> machine. What is the best way to do this? This should work:
>
> if os.system('latex -v'):
> print 'please install latex'
>
> but I dont actually want the latex version information to print to screen. I
> tried redirecting sys.stdout to a file, but that doesnt help. Is there a
> better way to do this in a cross-platform friendly way?
>
> Thanks,
> Darren



I didn't try it, but you could use the subprocess module
<http://python.org/doc/2.4.2/lib/module-subprocess.html>.
Create a Popen object with stdout = PIPE so that a pipe to the child
process is created and connected to the client's stdout.


Bye,
Dennis

Sybren Stuvel 01-09-2006 09:46 PM

Re: how to test for a dependency
 
Darren Dale enlightened us with:
> I would like to test that latex is installed on a windows, mac or linux
> machine. What is the best way to do this? This should work:
>
> if os.system('latex -v'):
> print 'please install latex'


The downside is that you can only use this to test by executing.
Perhaps it would be better to make a function that can search the PATH
environment variable in a cross-platform way. Also make sure you
include any platform-specific executable postfixes like Window's
".exe".

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa

Darren Dale 01-09-2006 09:53 PM

Re: how to test for a dependency
 
Dennis Benzinger wrote:

> Darren Dale schrieb:
>> Hello,
>>
>> I would like to test that latex is installed on a windows, mac or linux
>> machine. What is the best way to do this? This should work:
>>
>> if os.system('latex -v'):
>> print 'please install latex'
>>
>> but I dont actually want the latex version information to print to
>> screen. I tried redirecting sys.stdout to a file, but that doesnt help.
>> Is there a better way to do this in a cross-platform friendly way?
>>
>> Thanks,
>> Darren

>
>
> I didn't try it, but you could use the subprocess module
> <http://python.org/doc/2.4.2/lib/module-subprocess.html>.
> Create a Popen object with stdout = PIPE so that a pipe to the child
> process is created and connected to the client's stdout.



Thanks for the suggestion, that would probably work. Unfortunately, I need
to support Python 2.3 for some time to come.

I wonder, will this work across platforms?

if os.system('latex -v > temp.log'): print 'install latex'




Darren Dale 01-09-2006 09:56 PM

Re: how to test for a dependency
 
Sybren Stuvel wrote:

> Darren Dale enlightened us with:
>> I would like to test that latex is installed on a windows, mac or linux
>> machine. What is the best way to do this? This should work:
>>
>> if os.system('latex -v'):
>> print 'please install latex'

>
> The downside is that you can only use this to test by executing.
> Perhaps it would be better to make a function that can search the PATH
> environment variable in a cross-platform way. Also make sure you
> include any platform-specific executable postfixes like Window's
> ".exe".


I guess that would work. I was hoping there was a more elegant, batteries
included way to do it.

By the way, great Zappa quote.

Steven Bethard 01-10-2006 12:57 AM

Re: how to test for a dependency
 
Darren Dale wrote:
> I would like to test that latex is installed on a windows, mac or linux
> machine. What is the best way to do this? This should work:
>
> if os.system('latex -v'):
> print 'please install latex'
>
> but I dont actually want the latex version information to print to screen. I
> tried redirecting sys.stdout to a file, but that doesnt help. Is there a
> better way to do this in a cross-platform friendly way?


I've been using Trent's which package[1] for this kind of thing:

import which
try:
latex = which.which('latex')
except which.WhichError:
print 'please install latex'


STeVe

[1] http://starship.python.net/crew/tmick/#which


All times are GMT. The time now is 03:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.