I have this code that compares all version numbers of servers. (The version numbers are stored in an XML file) Before the code would compare the current version number with the previous. This caused some problems because in the cluster of servers, one has a different version number than the rest. If my code happened to connect to that server, it would think it was a change. So then I made it compare the three previous version numbers. The same issue was happening. So I got frustrated and made it load all the version numbers in a list and check the current one against the list. Will this cause a huge performance decrease (the list would be 50 elements at most)? Is there a better way?
#Loads all version numbers in list,
#starts at index 1 because the the first
#element in the XML file is has version number of 0
def loadAllVersions(self, hist):
historyLength = len(hist)
l =[]
for i in range(historyLength):
if i >= 1:
l.append(hist[len(hist)-i].get("version"))
return l
#Checks the current version number to each element
#in the list to see if it is the same. If there is a
#match then the it is not a newer version number,
#otherwise it is a new version number and the function
#returns True.
def checkAllVersions(self, currentVersion, allHist):
historyLength = len(allHist)
for i in range(historyLength):
if(allHist[i] == currentVersion):
return False
return True
def compareVersions(self,parent,componentTarget, write):
componentsTree = parent.findall("component")
currentVersion = self.componentVersions[self.components.index(componentTarget)]
for comp in componentsTree:
if(comp.get("id") == componentTarget):
hist = comp.findall("history")
allHist = self.loadAllVersions(hist)
isNewVersion = self.checkAllVersions(currentVersion, allHist)
if isNewVersion:
if write and currentVersion != None and self.getComponentURL(componentTarget) != None:
event = ET.SubElement(comp,"history")
event.set("time",str(int(time.time())))
event.set("version",currentVersion)
event.set("sourceUrl",self.getComponentURL(componentTarget))
event.set("pretty",self.componentsPretty[self.components.index(componentTarget)])
return True
return False