[1905] | 1 | #! /usr/bin/env python |
---|
| 2 | # -*- coding: ISO-8859-15 -*- |
---|
| 3 | # |
---|
| 4 | # PyKota |
---|
| 5 | # |
---|
| 6 | # PyKota : Print Quotas for CUPS and LPRng |
---|
| 7 | # |
---|
[2028] | 8 | # (c) 2003, 2004, 2005 Jerome Alet <alet@librelogiciel.com> |
---|
[1905] | 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 |
---|
[2303] | 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
[1905] | 22 | # |
---|
| 23 | # $Id$ |
---|
| 24 | # |
---|
[2126] | 25 | # |
---|
[1905] | 26 | |
---|
| 27 | import sys |
---|
| 28 | import os |
---|
| 29 | |
---|
| 30 | def checkModule(module) : |
---|
| 31 | """Checks if a Python module is available or not.""" |
---|
| 32 | try : |
---|
| 33 | exec "import %s" % module |
---|
| 34 | except ImportError : |
---|
| 35 | return 0 |
---|
| 36 | else : |
---|
| 37 | return 1 |
---|
| 38 | |
---|
| 39 | def checkCommand(command) : |
---|
| 40 | """Checks if a command is available or not.""" |
---|
| 41 | input = os.popen("type %s 2>/dev/null" % command) |
---|
| 42 | result = input.read().strip() |
---|
| 43 | input.close() |
---|
| 44 | return result |
---|
| 45 | |
---|
| 46 | def checkWithPrompt(prompt, module=None, command=None, helper=None) : |
---|
| 47 | """Tells the user what will be checked, and asks him what to do if something is absent.""" |
---|
| 48 | sys.stdout.write("Checking for %s availability : " % prompt) |
---|
| 49 | sys.stdout.flush() |
---|
| 50 | if command is not None : |
---|
| 51 | result = checkCommand(command) |
---|
| 52 | elif module is not None : |
---|
| 53 | result = checkModule(module) |
---|
| 54 | if result : |
---|
| 55 | sys.stdout.write("OK\n") |
---|
| 56 | else : |
---|
| 57 | sys.stdout.write("NO.\n") |
---|
| 58 | sys.stderr.write("ERROR : %s not available !\n" % prompt) |
---|
| 59 | sys.stdout.write("%s\n" % helper) |
---|
| 60 | |
---|
| 61 | if __name__ == "__main__" : |
---|
| 62 | print "Checking PyKota dependencies..." |
---|
| 63 | |
---|
| 64 | # checks if Python version is correct, we need >= 2.1 |
---|
| 65 | if not (sys.version > "2.1") : |
---|
| 66 | sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n") |
---|
| 67 | sys.exit(-1) |
---|
| 68 | |
---|
| 69 | # checks if some needed Python modules are there or not. |
---|
[1920] | 70 | modulestocheck = [ ("Python-PygreSQL", "pg", "PygreSQL is mandatory if you want to use PostgreSQL as the quota storage backend.\nSee http://www.pygresql.org"), |
---|
| 71 | ("Python-egenix-mxDateTime", "mx.DateTime", "eGenix' mxDateTime is mandatory for PyKota to work.\nSee http://www.egenix.com"), |
---|
[1905] | 72 | ("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"), |
---|
[2322] | 73 | ("Python-OSD", "pyosd", "Python-OSD is recommended if you plan to use the X Window On Screen Display\nprint quota reminder named pykosd. See http://repose.cx/pyosd/"), |
---|
[1905] | 74 | ("Python-SNMP", "pysnmp", "Python-SNMP is recommended if you plan to use hardware\naccounting with printers which support SNMP.\nSee http://pysnmp.sf.net"), |
---|
| 75 | ("Python-JAXML", "jaxml", "Python-JAXML is recommended if you plan to dump datas in the XML format.\nSee http://www.librelogiciel.com/software/"), |
---|
[1919] | 76 | ("Python-ReportLab", "reportlab.pdfgen.canvas", "Python-ReportLab is required if you plan to have PyKota generate banners.\nSee http://www.reportlab.org/"), |
---|
| 77 | ("Python-Imaging", "PIL.Image", "Python-Imaging is required if you plan to have PyKota generate banners.\nSee http://www.pythonware.com/downloads/"), |
---|
[2061] | 78 | ("Python-Psyco", "psyco", "Python-Psyco speedups parsing of print files, you should use it.\nSee http://psyco.sourceforge.net/"), |
---|
[2345] | 79 | ("Python-pkpgcounter", "pkpgpdls", "Python-pkpgcounter is mandatory.\nGrab it from http://www.librelogiciel.com/software/pkpgcounter/action_Download"), |
---|
[1905] | 80 | ] |
---|
[2126] | 81 | commandstocheck = [ ("GhostScript", "gs", "Depending on your configuration, GhostScript may be needed in different parts of PyKota."), |
---|
| 82 | ("SNMP Tools", "snmpget", "SNMP Tools are needed if you want to use SNMP enabled printers."), |
---|
[1905] | 83 | ("Netatalk", "pap", "Netatalk is needed if you want to use AppleTalk enabled printers.") |
---|
| 84 | ] |
---|
| 85 | for (name, module, helper) in modulestocheck : |
---|
| 86 | checkWithPrompt(name, module=module, helper=helper) |
---|
| 87 | |
---|
| 88 | # checks if some software are there or not. |
---|
| 89 | for (name, command, helper) in commandstocheck : |
---|
| 90 | checkWithPrompt(name, command=command, helper=helper) |
---|
| 91 | |
---|