def redownloadContentsFile(self, http): """ Downloads a new contents.xml file in case it has changed. Returns true if the file has indeed changed, false if it has not. """ assert self.hasContentsFile if self.appRunner and self.appRunner.verifyContents == self.appRunner.P3DVCNever: # Not allowed to. return False url = self.hostUrlPrefix + 'contents.xml' self.notify.info("Redownloading %s" % (url)) # Get the hash of the original file. assert self.hostDir hv1 = HashVal() if self.contentsSpec.hash: hv1.setFromHex(self.contentsSpec.hash) else: filename = Filename(self.hostDir, 'contents.xml') hv1.hashFile(filename) # Now download it again. self.hasContentsFile = False hv2 = HashVal() if not self.downloadContentsFile(http, redownload = True, hashVal = hv2): return False if hv2 == HashVal(): self.notify.info("%s didn't actually redownload." % (url)) return False elif hv1 != hv2: self.notify.info("%s has changed." % (url)) return True else: self.notify.info("%s has not changed." % (url)) return False
def readHash(self, pathname): """ Reads the hash only from the indicated pathname. """ hv = HashVal() hv.hashFile(pathname) self.hash = hv.asHex()