Juho Schultz wrote: > I think return values should be used for communication between > functions. Maybe something like this could work for you (not tested). > > def checkForRpm(rpmname): > # <cut start of function> > # Strings with 0 lenght are False > if output: > print output > else: > print rpmname + ' is not installed' > return output > > def checkPreReqs(): > missingRpms = [] > for requiredRpm in listOfRpms: > if not checkForRpm(requiredRpm): > missingRpms.append(requiredRpm) > # you could also do this by a list comprehension > missingRpms = [reqRpm for reqRpm in listOfRpms if not > checkForRpm(reqRpm)] > # or you could use the builtin function filter() - see > filter.__doc__ for that
Thanks Juho. I got the logic to workout the problem and I was able to solve it. There was bit alteration of my code was required. Its working now. Thanks. --- def checkForRpm(rpmname): ''' Check for the presence of the RPM. ''' cin,cout,cerr = os.popen3('rpm -q ' + rpmname) rpmStatus = cout.read() print rpmStatus, return rpmStatus def preReqCheckRpms(): ''' Check for the required RPMS ''' listOfRpms = ['firefox','senthil','binutils','gcc','cpp','glibc-devel','glibc-headers','glibc-kernheaders','compat-db','compat-gcc','compat-gcc-c++','compat-libstdc++','compat-libstdc++-devel','gnome-libs','openmotif21','setarch'] missingRpms = [] for requiredRpm in listOfRpms: if checkForRpm(requiredRpm).find('is not installed') > 0: missingRpms.append(requiredRpm) if missingRpms: print 'The following RPMS are not installed:' for eachMissingRpm in missingRpms: print eachMissingRpm print 'Please install them for the installation to continue.' sys.exit(-1) --- -- http://mail.python.org/mailman/listinfo/python-list