1 | #! /usr/bin/env python |
---|
2 | # -*- coding: ISO-8859-15 -*- |
---|
3 | # |
---|
4 | # PyKota |
---|
5 | # |
---|
6 | # PyKota : Print Quotas for CUPS and LPRng |
---|
7 | # |
---|
8 | # (c) 2003-2004 Jerome Alet <alet@librelogiciel.com> |
---|
9 | # This program is free software; you can redistribute it and/or modify |
---|
10 | # it under the terms of the GNU General Public License as published by |
---|
11 | # the Free Software Foundation; either version 2 of the License, or |
---|
12 | # (at your option) any later version. |
---|
13 | # |
---|
14 | # This program is distributed in the hope that it will be useful, |
---|
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | # GNU General Public License for more details. |
---|
18 | # |
---|
19 | # You should have received a copy of the GNU General Public License |
---|
20 | # along with this program; if not, write to the Free Software |
---|
21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | # |
---|
23 | # $Id$ |
---|
24 | # |
---|
25 | # $Log$ |
---|
26 | # Revision 1.1 2004/11/10 22:17:12 jalet |
---|
27 | # Installation script is now non-interactive again, and doesn't install |
---|
28 | # the sample configuration files into /etc/pykota anymore. |
---|
29 | # Dependencies check is now done by running checkdeps.py |
---|
30 | # The database creation scripts will now be included in RPM packages. |
---|
31 | # |
---|
32 | # |
---|
33 | # |
---|
34 | |
---|
35 | import sys |
---|
36 | import os |
---|
37 | |
---|
38 | def checkModule(module) : |
---|
39 | """Checks if a Python module is available or not.""" |
---|
40 | try : |
---|
41 | exec "import %s" % module |
---|
42 | except ImportError : |
---|
43 | return 0 |
---|
44 | else : |
---|
45 | return 1 |
---|
46 | |
---|
47 | def checkCommand(command) : |
---|
48 | """Checks if a command is available or not.""" |
---|
49 | input = os.popen("type %s 2>/dev/null" % command) |
---|
50 | result = input.read().strip() |
---|
51 | input.close() |
---|
52 | return result |
---|
53 | |
---|
54 | def checkWithPrompt(prompt, module=None, command=None, helper=None) : |
---|
55 | """Tells the user what will be checked, and asks him what to do if something is absent.""" |
---|
56 | sys.stdout.write("Checking for %s availability : " % prompt) |
---|
57 | sys.stdout.flush() |
---|
58 | if command is not None : |
---|
59 | result = checkCommand(command) |
---|
60 | elif module is not None : |
---|
61 | result = checkModule(module) |
---|
62 | if result : |
---|
63 | sys.stdout.write("OK\n") |
---|
64 | else : |
---|
65 | sys.stdout.write("NO.\n") |
---|
66 | sys.stderr.write("ERROR : %s not available !\n" % prompt) |
---|
67 | sys.stdout.write("%s\n" % helper) |
---|
68 | |
---|
69 | if __name__ == "__main__" : |
---|
70 | print "Checking PyKota dependencies..." |
---|
71 | |
---|
72 | # checks if Python version is correct, we need >= 2.1 |
---|
73 | if not (sys.version > "2.1") : |
---|
74 | sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n") |
---|
75 | sys.exit(-1) |
---|
76 | |
---|
77 | # checks if some needed Python modules are there or not. |
---|
78 | modulestocheck = [ ("PygreSQL", "pg", "PygreSQL is mandatory if you want to use PostgreSQL as the quota storage backend.\nSee http://www.pygresql.org"), |
---|
79 | ("mxDateTime", "mx.DateTime", "eGenix' mxDateTime is mandatory for PyKota to work.\nSee http://www.egenix.com"), |
---|
80 | ("Python-LDAP", "ldap", "Python-LDAP is mandatory if you plan to use an LDAP\ndirectory as the quota storage backend.\nSee http://python-ldap.sf.net"), |
---|
81 | ("Python-OSD", "pyosd", "Python-OSD is recommended if you plan to use the X Window On Screen Display\nprint quota reminder named pykosd."), |
---|
82 | ("Python-SNMP", "pysnmp", "Python-SNMP is recommended if you plan to use hardware\naccounting with printers which support SNMP.\nSee http://pysnmp.sf.net"), |
---|
83 | ("Python-JAXML", "jaxml", "Python-JAXML is recommended if you plan to dump datas in the XML format.\nSee http://www.librelogiciel.com/software/"), |
---|
84 | ] |
---|
85 | commandstocheck = [ ("SNMP Tools", "snmpget", "SNMP Tools are needed if you want to use SNMP enabled printers."), |
---|
86 | ("Netatalk", "pap", "Netatalk is needed if you want to use AppleTalk enabled printers.") |
---|
87 | ] |
---|
88 | for (name, module, helper) in modulestocheck : |
---|
89 | checkWithPrompt(name, module=module, helper=helper) |
---|
90 | |
---|
91 | # checks if some software are there or not. |
---|
92 | for (name, command, helper) in commandstocheck : |
---|
93 | checkWithPrompt(name, command=command, helper=helper) |
---|
94 | |
---|