root / pykota / trunk / checkdeps.py @ 2139

Revision 2139, 5.4 kB (checked in by jerome, 19 years ago)

Added the Log keyword property

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision Log
Line 
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, 2005 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.6  2005/03/05 18:54:54  jalet
27# Improved the installation documentation.
28# Now checkdeps also checks for the presence of GhostScript, which
29# may be needed if PyKota's bannering facility is used or if some
30# printer driver produces non-DSC compliant PostScript.
31#
32# Revision 1.5  2005/02/14 23:37:58  jalet
33# Added a check for the presence of pythn-psyco
34#
35# Revision 1.4  2005/01/17 08:44:23  jalet
36# Modified copyright years
37#
38# Revision 1.3  2004/11/15 21:11:01  jalet
39# Modified some labels for Python modules
40#
41# Revision 1.2  2004/11/15 21:08:01  jalet
42# Now checks for the presence of ReportLab and PIL
43#
44# Revision 1.1  2004/11/10 22:17:12  jalet
45# Installation script is now non-interactive again, and doesn't install
46# the sample configuration files into /etc/pykota anymore.
47# Dependencies check is now done by running checkdeps.py
48# The database creation scripts will now be included in RPM packages.
49#
50#
51#
52
53import sys
54import os
55
56def checkModule(module) :
57    """Checks if a Python module is available or not."""
58    try :
59        exec "import %s" % module
60    except ImportError :   
61        return 0
62    else :   
63        return 1
64       
65def checkCommand(command) :
66    """Checks if a command is available or not."""
67    input = os.popen("type %s 2>/dev/null" % command)
68    result = input.read().strip()
69    input.close()
70    return result
71   
72def checkWithPrompt(prompt, module=None, command=None, helper=None) :
73    """Tells the user what will be checked, and asks him what to do if something is absent."""
74    sys.stdout.write("Checking for %s availability : " % prompt)
75    sys.stdout.flush()
76    if command is not None :
77        result = checkCommand(command)
78    elif module is not None :   
79        result = checkModule(module)
80    if result :   
81        sys.stdout.write("OK\n")
82    else :   
83        sys.stdout.write("NO.\n")
84        sys.stderr.write("ERROR : %s not available !\n" % prompt)
85        sys.stdout.write("%s\n" % helper)
86   
87if __name__ == "__main__" :   
88    print "Checking PyKota dependencies..."
89   
90    # checks if Python version is correct, we need >= 2.1
91    if not (sys.version > "2.1") :
92        sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n")
93        sys.exit(-1)
94       
95    # checks if some needed Python modules are there or not.
96    modulestocheck = [ ("Python-PygreSQL", "pg", "PygreSQL is mandatory if you want to use PostgreSQL as the quota storage backend.\nSee http://www.pygresql.org"),
97                       ("Python-egenix-mxDateTime", "mx.DateTime", "eGenix' mxDateTime is mandatory for PyKota to work.\nSee http://www.egenix.com"),
98                       ("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"),
99                       ("Python-OSD", "pyosd", "Python-OSD is recommended if you plan to use the X Window On Screen Display\nprint quota reminder named pykosd."),
100                       ("Python-SNMP", "pysnmp", "Python-SNMP is recommended if you plan to use hardware\naccounting with printers which support SNMP.\nSee http://pysnmp.sf.net"),
101                       ("Python-JAXML", "jaxml", "Python-JAXML is recommended if you plan to dump datas in the XML format.\nSee http://www.librelogiciel.com/software/"),
102                       ("Python-ReportLab", "reportlab.pdfgen.canvas", "Python-ReportLab is required if you plan to have PyKota generate banners.\nSee http://www.reportlab.org/"),
103                       ("Python-Imaging", "PIL.Image", "Python-Imaging is required if you plan to have PyKota generate banners.\nSee http://www.pythonware.com/downloads/"),
104                       ("Python-Psyco", "psyco", "Python-Psyco speedups parsing of print files, you should use it.\nSee http://psyco.sourceforge.net/"),
105                     ]
106    commandstocheck = [ ("GhostScript", "gs", "Depending on your configuration, GhostScript may be needed in different parts of PyKota."),
107                        ("SNMP Tools", "snmpget", "SNMP Tools are needed if you want to use SNMP enabled printers."), 
108                        ("Netatalk", "pap", "Netatalk is needed if you want to use AppleTalk enabled printers.")
109                      ]
110    for (name, module, helper) in modulestocheck :
111        checkWithPrompt(name, module=module, helper=helper)
112           
113    # checks if some software are there or not.
114    for (name, command, helper) in commandstocheck :
115        checkWithPrompt(name, command=command, helper=helper)
116           
Note: See TracBrowser for help on using the browser.