[1905] | 1 | #! /usr/bin/env python |
---|
[3411] | 2 | # -*- coding: utf-8 -*- |
---|
[1905] | 3 | # |
---|
| 4 | # PyKota |
---|
| 5 | # |
---|
[3259] | 6 | # PyKota : Print Quotas for CUPS |
---|
[1905] | 7 | # |
---|
[3481] | 8 | # (c) 2003-2009 Jerome Alet <alet@librelogiciel.com> |
---|
[3259] | 9 | # This program is free software: you can redistribute it and/or modify |
---|
[1905] | 10 | # it under the terms of the GNU General Public License as published by |
---|
[3259] | 11 | # the Free Software Foundation, either version 3 of the License, or |
---|
[1905] | 12 | # (at your option) any later version. |
---|
[3413] | 13 | # |
---|
[1905] | 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. |
---|
[3413] | 18 | # |
---|
[1905] | 19 | # You should have received a copy of the GNU General Public License |
---|
[3259] | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
[1905] | 21 | # |
---|
| 22 | # $Id$ |
---|
| 23 | # |
---|
[2126] | 24 | # |
---|
[1905] | 25 | |
---|
| 26 | import sys |
---|
| 27 | import os |
---|
| 28 | |
---|
| 29 | def checkModule(module) : |
---|
| 30 | """Checks if a Python module is available or not.""" |
---|
| 31 | try : |
---|
| 32 | exec "import %s" % module |
---|
[3413] | 33 | except ImportError : |
---|
[1905] | 34 | return 0 |
---|
[3413] | 35 | else : |
---|
[1905] | 36 | return 1 |
---|
[3413] | 37 | |
---|
[1905] | 38 | def checkCommand(command) : |
---|
| 39 | """Checks if a command is available or not.""" |
---|
| 40 | input = os.popen("type %s 2>/dev/null" % command) |
---|
| 41 | result = input.read().strip() |
---|
| 42 | input.close() |
---|
| 43 | return result |
---|
[3413] | 44 | |
---|
[1905] | 45 | def checkWithPrompt(prompt, module=None, command=None, helper=None) : |
---|
| 46 | """Tells the user what will be checked, and asks him what to do if something is absent.""" |
---|
| 47 | sys.stdout.write("Checking for %s availability : " % prompt) |
---|
| 48 | sys.stdout.flush() |
---|
| 49 | if command is not None : |
---|
| 50 | result = checkCommand(command) |
---|
[3413] | 51 | elif module is not None : |
---|
[1905] | 52 | result = checkModule(module) |
---|
[3413] | 53 | if result : |
---|
[1905] | 54 | sys.stdout.write("OK\n") |
---|
[3413] | 55 | else : |
---|
[1905] | 56 | sys.stdout.write("NO.\n") |
---|
| 57 | sys.stderr.write("ERROR : %s not available !\n" % prompt) |
---|
| 58 | sys.stdout.write("%s\n" % helper) |
---|
[3413] | 59 | |
---|
| 60 | if __name__ == "__main__" : |
---|
[3430] | 61 | sys.stdout.write("Checking PyKota dependencies...\n") |
---|
[3413] | 62 | |
---|
[3471] | 63 | # checks if Python version is correct, we need >= 2.4 |
---|
| 64 | if not (sys.version > "2.4") : |
---|
| 65 | sys.stderr.write("PyKota needs at least Python v2.4 !\nYour version seems to be older than that, please update.\nAborted !\n") |
---|
[1905] | 66 | sys.exit(-1) |
---|
[3413] | 67 | |
---|
[1905] | 68 | # checks if some needed Python modules are there or not. |
---|
[3471] | 69 | modulestocheck = [ ("Python-PygreSQL", "pg", "PygreSQL is mandatory if you want to use PostgreSQL as the quota database backend.\nSee http://www.pygresql.org or use 'apt-get install python-pygresql'"), |
---|
| 70 | ("Python-SQLite", "pysqlite2", "Python-SQLite is mandatory if you want to use SQLite as the quota database backend.\nSee http://www.pysqlite.org or use 'apt-get install python-pysqlite2'"), |
---|
| 71 | ("MySQL-Python", "MySQLdb", "MySQL-Python is mandatory if you want to use MySQL as the quota database backend.\nSee http://sourceforge.net/projects/mysql-python or use 'apt-get install python-mysqldb'"), |
---|
| 72 | ("Python-egenix-mxDateTime", "mx.DateTime", "eGenix' mxDateTime is mandatory for PyKota to work.\nSee http://www.egenix.com or use 'apt-get install python-egenix-mxdatetime'"), |
---|
| 73 | ("Python-LDAP", "ldap", "Python-LDAP is mandatory if you plan to use an LDAP\ndirectory as the quota database backend.\nSee http://python-ldap.sf.net or use 'apt-get install python-ldap'"), |
---|
| 74 | ("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/ or use 'apt-get install python-osd'"), |
---|
| 75 | ("Python-SNMP", "pysnmp", "Python-SNMP is recommended if you plan to use hardware\naccounting with printers which support SNMP.\nSee http://pysnmp.sf.net or use 'apt-get install python-pysnmp4'"), |
---|
| 76 | ("Python-JAXML", "jaxml", "Python-JAXML is recommended if you plan to dump datas in the XML format.\nSee http://www.librelogiciel.com/software/ or use 'apt-get install python-jaxml'"), |
---|
| 77 | ("Python-ReportLab", "reportlab.pdfgen.canvas", "Python-ReportLab is required if you plan to have PyKota generate banners, invoices or receipts.\nSee http://www.reportlab.org/ or use 'apt-get install python-reportlab'"), |
---|
| 78 | ("Python-Imaging", "PIL.Image", "Python-Imaging is required if you plan to have PyKota generate banners, invoices or receipts.\nSee http://www.pythonware.com/downloads/ or use 'apt-get install python-imaging'"), |
---|
| 79 | ("Python-pkpgcounter", "pkpgpdls", "Python-pkpgcounter is mandatory.\nGrab it from http://www.pykota.com/software/pkpgcounter/ or use 'apt-get install pkpgcounter'"), |
---|
| 80 | ("Python-PAM", "PAM", "Python-PAM is recommended if you plan to use pknotify+PyKotIcon.\nGrab it from http://www.pangalactic.org/PyPAM/ or use 'apt-get install python-pam'"), |
---|
[2892] | 81 | ("Python-pkipplib", "pkipplib", "Python-pkipplib is now mandatory.\nGrab it from http://www.pykota.com/software/pkipplib/"), |
---|
[1905] | 82 | ] |
---|
[3471] | 83 | commandstocheck = [ ("GhostScript", "gs", "GhostScript may be needed in different parts of PyKota. Install it from your favorite distribution, or use 'apt-get install ghostscript'."), |
---|
| 84 | ("Netatalk", "pap", "Netatalk is needed if you want to use hardware accounting with AppleTalk enabled printers. Install it from your favorite distribution or use 'apt-get install netatalk'") |
---|
[1905] | 85 | ] |
---|
| 86 | for (name, module, helper) in modulestocheck : |
---|
| 87 | checkWithPrompt(name, module=module, helper=helper) |
---|
[3413] | 88 | |
---|
[1905] | 89 | # checks if some software are there or not. |
---|
| 90 | for (name, command, helper) in commandstocheck : |
---|
| 91 | checkWithPrompt(name, command=command, helper=helper) |
---|