| 43 | ACTION_CONTINUE = 0 |
| 44 | ACTION_ABORT = 1 |
| 45 | |
| 46 | def 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 | |
| 55 | def 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 | |
| 62 | def 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 | |
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") |