I know this is horrible coding. Just trying to find out why do i keep getting this error message...
QUESTION: When not supplying the file with the script; why does it return the error below instead of the except block? else the script works if I supply the xml file when running it.
Traceback (most recent call last): File "C:\bin\read.py", line 5, in script, filename = argv ValueError: need more than 1 value to unpack
import sys
from xml.dom import minidom
from sys import argv
script, filename = argv
xmldoc = minidom.parse(filename)
total = len(sys.argv)
spacenumber = 1
space = "\t" * spacenumber
betweenspace = "\t" * 2
# ROOT ELEMENT <clusterConfig></clusterConfig>
rootElement = xmldoc.getElementsByTagName('clusterConfig')[0]
# CHILD ELEMENT 1 <instanceConfiguration></instanceConfiguration>
#childElement1s = rootElement.getElementsByTagName('instanceConfiguration')[0]
instanceRaters = rootElement.getElementsByTagName('instanceConfiguration')[0]
instanceUpdaters = rootElement.getElementsByTagName('instanceConfiguration')[1]
instanceGuiders = rootElement.getElementsByTagName('instanceConfiguration')[2]
instanceBulkLoaders = rootElement.getElementsByTagName('instanceConfiguration')[3]
instanceTaxers = rootElement.getElementsByTagName('instanceConfiguration')[4]
instanceDispatchers = rootElement.getElementsByTagName('instanceConfiguration')[5]
# CHILD ELEMENT 2 <configParameter />
#childElement2s = childElement1s.getElementsByTagName('configParameter')
raterAttributes = instanceRaters.getElementsByTagName('configParameter')
updaterAttributes = instanceUpdaters.getElementsByTagName('configParameter')
guiderAttributes = instanceGuiders.getElementsByTagName('configParameter')
bulkLoaderAttributes = instanceBulkLoaders.getElementsByTagName('configParameter')
taxerAttributes = instanceTaxers.getElementsByTagName('configParameter')
dispatcherAttributes = instanceDispatchers.getElementsByTagName('configParameter')
def runthis():
# Print rater configuration
print "RATER CONFIGURATION:\n"
for raterAttribute in raterAttributes:
print ("%s%s%s%s" %(space,raterAttribute.getAttribute('name'), betweenspace, raterAttribute.getAttribute('value')))
# Print updater configuration
print "\n\nUPDATER CONFIGURATION:\n"
for updaterAttribute in updaterAttributes:
print ("%s%s%s%s" %(space,updaterAttribute.getAttribute('name'), betweenspace, updaterAttribute.getAttribute('value')))
# Print guider configuration
print "\n\nGUIDER CONFIGURATION:\n"
for guiderAttribute in guiderAttributes:
print ("%s%s%s%s" %(space,guiderAttribute.getAttribute('name'), betweenspace, guiderAttribute.getAttribute('value')))
# Print bulkLoader configuration
print "\n\nBULKLOADER CONFIGURATION:\n"
for bulkLoaderAttribute in bulkLoaderAttributes:
print ("%s%s%s%s" %(space,bulkLoaderAttribute.getAttribute('name'), betweenspace, bulkLoaderAttribute.getAttribute('value')))
# Print taxer configuration
print "\n\nTAXER CONFIGURATION:\n"
for taxerAttribute in taxerAttributes:
print ("%s%s%s%s" %(space,taxerAttribute.getAttribute('name'), betweenspace, taxerAttribute.getAttribute('value')))
# Print dispatcher configuration
print "\n\nDISPATCHER CONFIGURATION:\n"
for dispatcherAttribute in dispatcherAttributes:
print ("%s%s%s%s" %(space,dispatcherAttribute.getAttribute('name'), betweenspace, dispatcherAttribute.getAttribute('value')))
try:
runthis()
except ValueError:
print "ERROR!!!! YOU FORGOT TO INCLUDE THE PARAMETERS.XML FILE!"