root / pykota / trunk / checkdeps.py @ 2028

Revision 2028, 4.7 kB (checked in by jalet, 19 years ago)

Modified copyright years

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