473,809 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(notInstalle d) 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(rpm name):
''' 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.ap pend(rpmname)
else:
print output

def preReqCheckRpms ():
''' Check for the required RPMS '''
listOfRpms =
['firefox','sent hil','binutils' ,'gcc','cpp','g libc-devel','glibc-headers','glibc-kernheaders','c ompat-db','compat-gcc','compat-gcc-c++','compat-libstdc++','com pat-libstdc++-devel','gnome-libs','openmoti f21','setarch']

for eachRpm in listOfRpms:
checkForRpm(eac hRpm)
global notInstalled
if len(notInstalle d) 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.ap pend(rpmname) is not taking effect in
checkForRpm(rpm name)
* I dont know how to communicate the notInstalled list to
preReqCheckRpms .

--
Senthil

Jul 24 '06 #1
2 1273
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(notInstalle d) is greater than 0 then I display
them all asking it to be installed and exit the program.
My Script is below:
-------
def checkForRpm(rpm name):
''' 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.ap pend(rpmname)
else:
print output

def preReqCheckRpms ():
''' Check for the required RPMS '''
listOfRpms = ['firefox','sent hil',]
for eachRpm in listOfRpms:
checkForRpm(eac hRpm)
global notInstalled
if len(notInstalle d) 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.ap pend(rpmname) is not taking effect in
checkForRpm(rpm name)
* 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(rpm name):
# <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(req uiredRpm):
missingRpms.app end(requiredRpm )
# you could also do this by a list comprehension
missingRpms = [reqRpm for reqRpm in listOfRpms if not
checkForRpm(req Rpm)]
# 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(rpm name):
# <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(req uiredRpm):
missingRpms.app end(requiredRpm )
# you could also do this by a list comprehension
missingRpms = [reqRpm for reqRpm in listOfRpms if not
checkForRpm(req Rpm)]
# 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(rpm name):
''' 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','sent hil','binutils' ,'gcc','cpp','g libc-devel','glibc-headers','glibc-kernheaders','c ompat-db','compat-gcc','compat-gcc-c++','compat-libstdc++','com pat-libstdc++-devel','gnome-libs','openmoti f21','setarch']
missingRpms = []
for requiredRpm in listOfRpms:
if checkForRpm(req uiredRpm).find( 'is not installed') >
0:
missingRpms.app end(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
4358
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 HTML version is much more readable than the ReST version. See: http://www.python.org/peps/pep-0322.html
17
2580
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 with a link to old information that suggests use of "navigator": http://developer.irt.org/script/43.htm
7
2968
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 documentation this should automatically add to the Task List, but it doesn't?? I've checked under my Tools, Options, Environment, Task List and the TODO entry is there. But what I find odd is that at dialog I can NOT "Add" and comment tokens? I know...
13
1815
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 = "" for ch in text: if ch in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": word = word + ch
1
1576
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 communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "10.88.6.49". Communication function detecting the error: "recv". Protocol specific...
4
1599
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: - very simple, list all comments unthreaded and puts an 'add comment' form at the bottom. - preferably locally hosted (direct php code would be great)
0
1738
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 needs to be substituted is a simple file on disk. Here is a dump of the file and it's characters. I do understand that it is not in the range of ASCII but how can I make it so that it will work?
8
2186
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 understanding in it i have failed to do it myself. I have tried to use many functions but any of them did a job. I must have used them in the wrong way. This is the link of full script code: Comment Form Script Tutorial (It's free too!) Here is my code: ...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9199
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.