Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to test for a dependency

Reply
Thread Tools

how to test for a dependency

 
 
Darren Dale
Guest
Posts: n/a
 
      01-09-2006
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
 
Reply With Quote
 
 
 
 
Dennis Benzinger
Guest
Posts: n/a
 
      01-09-2006
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
 
Reply With Quote
 
 
 
 
Sybren Stuvel
Guest
Posts: n/a
 
      01-09-2006
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
 
Reply With Quote
 
Darren Dale
Guest
Posts: n/a
 
      01-09-2006
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'



 
Reply With Quote
 
Darren Dale
Guest
Posts: n/a
 
      01-09-2006
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.
 
Reply With Quote
 
Steven Bethard
Guest
Posts: n/a
 
      01-10-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
cmake + google test: weirdo dependency Giovanni Azua C++ 1 10-08-2011 01:43 PM
TEST TEST Test...Blah Blah Blah Generalbatguano@pacbell.net Computer Support 6 09-13-2006 01:53 AM
TEST TEST TEST Gazwad Computer Support 2 09-05-2003 07:32 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments