#!/usr/bin/env python # $Id: kusu-deps-check 1575 2007-07-02 06:46:20Z najib $ # # Copyright 2007 Platform Computing Inc. # # Licensed under GPL version 2; See LICENSE for details. import sys import os import gettext from optparse import OptionParser import subprocess # exceptions class DepsNotFound(Exception): pass # constants TOOLS_DEPS = ['cpio', 'mount', 'umount', 'file', 'strings', 'zcat', 'mkisofs', 'tar', 'gzip', 'rpmbuild', 'cmake', 'make', 'rpm', 'python', 'gcc'] NONPY_LIBS_DEPS = ['libsqlite','libnewt','libparted'] PY_LIBS_DEPS = {'pyparted':'parted'} SITE_URL = 'http://www.osgdc.org/project/kusu/wiki/DevelopersCorner' def checkPyLibDeps(lib): """ Check if the specified python library is installed and accessible. Returns False if fail. """ c = 'python -c "import %s"' % lib libP = subprocess.Popen(c,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) libP.communicate() if libP.returncode <> 0: return False return True def checkNonPyLibDeps(lib, searchpath='/usr/lib'): """ Check if the specified library is installed and accessible. A searchpath can be specified for alternative locations. Returns False if fail. """ c = 'find %s -name "%s*"' % (searchpath,lib) libP = subprocess.Popen(c,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) out,err = libP.communicate() if not out: return False return True def checkToolDeps(tool): """ Check if the tool is indeed available. Returns False if fail. """ cmd = 'which %s > /dev/null 2>&1' % tool whichP = subprocess.Popen(cmd,shell=True) whichP.communicate() if whichP.returncode <> 0: return False return True class KusuDepsCheckApp(object): """ Application class""" def __init__(self): super(KusuDepsCheckApp, self).__init__() def run(self): """Main launcher""" print "Checking dependencies for Project Kusu" print "--------------------------------------" missingTools = [] # check the list of tools print "Checking tools' dependencies:" for tool in TOOLS_DEPS: msg = "checking %s..." % tool print msg, if checkToolDeps(tool): print "yes" else: missingTools.append(tool) print 'no' # check the list of non-python libs print print "Checking non-python libraries' dependencies:" for lib in NONPY_LIBS_DEPS: msg = "checking %s..." % lib print msg, if checkNonPyLibDeps(lib): print "yes" else: missingTools.append(lib) print 'no' # check the list of tools print print "Checking python dependencies:" for lib in PY_LIBS_DEPS: msg = "checking %s..." % lib print msg, if checkPyLibDeps(PY_LIBS_DEPS[lib]): print "yes" else: missingTools.append(lib) if missingTools: print print 'The following tool(s) are not available:' print ', '.join(missingTools) print 'For more information, please browse to', SITE_URL print sys.exit(2) sys.exit(0) if __name__ == '__main__': app = KusuDepsCheckApp() app.run()