root / pykota / trunk / checkdeps.py @ 2074

Revision 2061, 5.0 kB (checked in by jalet, 20 years ago)

Added a check for the presence of pythn-psyco

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