473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Comment on this script. Possible error in communication with list arg between functions

Hi all,
Part of my script is to check for pre-requisite rpms to be
installed.
If its installed, I just display the rpm version as in rpm database,
otherwise I output a message saying:
' rpm is not installed' and collect the rpm name in a list
(notInstalled).
At the end if the len(notInstalled) is greater than 0 then I display
them all asking it to be installed and exit the program.
My Script is below:
-------
#!/usr/bin/env python
import os
import sys

notInstalled = []

def checkForRpm(rpmname):
''' Check for the presence of the RPM. '''
cin,cout,cerr = os.popen3('rpm -q ' + rpmname)
output = cout.read()
global notInstalled
if len(output) <= 0:
print rpmname + ' not installed.'
notInstalled.append(rpmname)
else:
print output

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']

for eachRpm in listOfRpms:
checkForRpm(eachRpm)
global notInstalled
if len(notInstalled) 0:
print 'The following RPMS are not installed:'
for eachRpm in notInstalled:
print eachRpm
print 'Please install them for the installation to
continue.'
sys.exit(-1)


def main():
preReqCheckRpms()

if __name__ == '__main__':
main()
----

* This is NOT Working.
* notInstalled.append(rpmname) is not taking effect in
checkForRpm(rpmname)
* I dont know how to communicate the notInstalled list to
preReqCheckRpms.

--
Senthil

Jul 24 '06 #1
2 1254
Phoe6 wrote:
Hi all,
Part of my script is to check for pre-requisite rpms to be
installed.
If its installed, I just display the rpm version as in rpm database,
otherwise I output a message saying:
' rpm is not installed' and collect the rpm name in a list
(notInstalled).
At the end if the len(notInstalled) is greater than 0 then I display
them all asking it to be installed and exit the program.
My Script is below:
-------
def checkForRpm(rpmname):
''' Check for the presence of the RPM. '''
cin,cout,cerr = os.popen3('rpm -q ' + rpmname)
output = cout.read()
global notInstalled
if len(output) <= 0:
print rpmname + ' not installed.'
notInstalled.append(rpmname)
else:
print output

def preReqCheckRpms():
''' Check for the required RPMS '''
listOfRpms = ['firefox','senthil',]
for eachRpm in listOfRpms:
checkForRpm(eachRpm)
global notInstalled
if len(notInstalled) 0:
print 'The following RPMS are not installed:'
for eachRpm in notInstalled:
print eachRpm
print 'Please install them for the installation to
continue.'
sys.exit(-1)
* This is NOT Working.
* notInstalled.append(rpmname) is not taking effect in
checkForRpm(rpmname)
* I dont know how to communicate the notInstalled list to
preReqCheckRpms.

--
Senthil
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

# now, list of lenght 0 is False.
if missingRpms:
# print error messages, exit.

--
Juho Schultz

Jul 24 '06 #2
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)

---

Jul 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
17
by: lawrence | last post by:
How is it possible that the question "How do I detect which browser the user has" is missing from this FAQ: http://www.faqts.com/knowledge_base/index.phtml/fid/125 and is only here on this...
7
by: Rob R. Ainscough | last post by:
I'm using Visual Studio .NET 2003 (Visual Basic) and I can't seem to get my Task List to update automatically when I enter comment token: ' TODO: This is some stuff to do According to...
13
by: Pedro Graca | last post by:
I'm sure this isn't very pythonic; comments and advice appreciated def curious(text): """ Return the words in input text scrambled except for the first and last letter. """ new_text = "" word...
1
by: shsandeep | last post by:
Hi, I get the following error when trying to connect to a database: (I have cataloged the node and database and they show up in list node directory and list db directory): SQL30081N A...
4
by: Guillaume Dargaud | last post by:
Hello All, I'm looking for a way to add a list of user comments at the bottom of a web page, in PHP. I've looked and played with several available tools but they don't fit my needs which are:...
0
by: Jorgen Bodde | last post by:
Hi Edwin, Filemask is obvious as it is assigned in the python code itself. It is "%file%". The idea is that the file clicked is substituted for the "%file%" by the replace action. The file that...
8
by: rotorio | last post by:
Hi, I am new to php and I am trying to edit one free comment script to fit my needs. The last thing left is to make a word wrapping in comment <div>. It musn't be hard but because I lack...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.