#!/usr/bin/python
import os
import sys

"""
input - a perl module name
output - don't know yet

script takes a stream of module names and does
some test on them, returns one result per module 
name.

"""

def check_whether_installed(module,opt):
    state = ""
    # crazy I know, but we ask perl if it knows the module
    check_module_installed = "perl -M" +  module.strip() + " -e'print ok;'"
    cmd = check_module_installed
    # fork a thread and execute command
    (sin,sout,serr) = os.popen3(cmd,"r")
    errors = serr.read()
    # if there were errors perl does not recognise the module, easy! 
    if len(errors) > 0:
        state =  "not installed"
    else:
        state = "installed"
    if opt == "quiet":
        if state=="not installed": print module.strip()
    else:
        print "checking " + module.strip() + ": " + state

try:
    opt = sys.argv[1]
except:
    opt = "quiet"
line = sys.stdin.readline()
while 1:
    check_whether_installed(line,opt)
    line = sys.stdin.readline()
    if not line: break
    

