Changeset 870 for pykota/trunk/setup.py

Show
Ignore:
Timestamp:
03/29/03 10:47:00 (21 years ago)
Author:
jalet
Message:

More powerful installation script.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/setup.py

    r869 r870  
    1717# 
    1818# $Log$ 
     19# Revision 1.4  2003/03/29 09:47:00  jalet 
     20# More powerful installation script. 
     21# 
    1922# Revision 1.3  2003/03/26 17:48:36  jalet 
    2023# First shot at trying to detect the availability of the needed software 
     
    3841from pykota.version import __version__, __doc__ 
    3942 
     43ACTION_CONTINUE = 0 
     44ACTION_ABORT = 1 
     45 
     46def checkModule(module) : 
     47    """Checks if a Python module is available or not.""" 
     48    try : 
     49        exec "import %s" % module 
     50    except ImportError :     
     51        return 0 
     52    else :     
     53        return 1 
     54         
     55def checkCommand(command) : 
     56    """Checks if a command is available or not.""" 
     57    input = os.popen("type %s 2>/dev/null" % command) 
     58    result = input.read().strip() 
     59    input.close() 
     60    return result 
     61     
     62def checkWithPrompt(prompt, module=None, command=None) : 
     63    """Tells the user what will be checked, and asks him what to do if something is absent.""" 
     64    sys.stdout.write("Checking for %s availability : " % prompt) 
     65    sys.stdout.flush() 
     66    if command is not None : 
     67        result = checkCommand(command) 
     68    elif module is not None :     
     69        result = checkModule(module) 
     70    if result :     
     71        sys.stdout.write("OK\n") 
     72        return ACTION_CONTINUE 
     73    else :     
     74        sys.stdout.write("NO.\n") 
     75        sys.stderr.write("ERROR : %s not available !\n" % prompt) 
     76        answer = raw_input("%s is missing. Do you want to continue anyway (y/N) ? " % prompt) 
     77        if answer[0:1].upper() == 'Y' : 
     78            return ACTION_CONTINUE 
     79        else : 
     80            return ACTION_ABORT 
     81     
    4082if "install" in sys.argv : 
    41     sys.stderr.write("PygreSQL availability : ") 
    42     try : 
    43         import pg 
    44     except ImportError :     
    45         sys.stderr.write("No ! Installation aborted.\n") 
     83    if not (sys.version > "2.1") : 
     84        sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n") 
    4685        sys.exit(-1) 
    47     else :     
    48         del pg 
    49         sys.stderr.write("OK.\n") 
    50         sys.stderr.write("snmpget availability : ") 
    51         result = os.popen("type snmpget") 
    52         snmpget = result.read().strip() 
    53         result.close() 
    54         if not snmpget : 
    55             sys.stderr.write("No ! Installation aborted.\n") 
     86         
     87    modulestocheck = [("PygreSQL", "pg"), ("mxDateTime", "mx.DateTime")] 
     88    commandstocheck = [("SNMP Tools", "snmpget")] 
     89    for (name, module) in modulestocheck : 
     90        action = checkWithPrompt(name, module=module) 
     91        if action == ACTION_ABORT : 
     92            sys.stderr.write("Aborted !\n") 
    5693            sys.exit(-1) 
    57         else :     
    58             sys.stderr.write("OK.\n") 
     94             
     95    for (name, command) in commandstocheck : 
     96        action = checkWithPrompt(name, command=command) 
     97        if action == ACTION_ABORT : 
     98            sys.stderr.write("Aborted !\n") 
     99            sys.exit(-1) 
    59100             
    60101data_files = []