root / pykota / trunk / checkdeps.py @ 1937

Revision 1920, 4.6 kB (checked in by jalet, 20 years ago)

Modified some labels for Python modules

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