def fetchCache(self, url, versionNum = None): # Populate a pageTree with data from my awesome cache. # If needsChildren = true, will pull whole pageTree. # API for cache to pull data tba. directory = self.parseDirectory(url) fName = directory[1] directory = directory[0] preFileString = "" currVersionNum = self.findRevisionNum(directory, fName) if versionNum: if versionNum < 0: versionNum = currVersionNum + versionNum preFileString = versionNum + "_" if versionNum < 0 or versionNum > currVersionNum: preFileString = "" pageTree = PageTree(url) contentType = "Text" try: with open(os.path.join(directory, preFileString + "pageTreeData.txt")) as f: pageTree.setPageTreeData(f.read()) contentType = pageTree.getEncodeType(0) pageTree.setSourceMode(0, "cache") except IOError: Scheduler.newPagesAdded += 1 return False try: with open(os.path.join(directory, preFileString + fName)) as f: content = f.read() pageTree.setContent(0, content, contentType) except IOError: return False return pageTree
def testStrangeDirectory(self): pageTree = PageTree() pageTree.createPageNode("http://www.dummyurl.com/strangeDirectory.html/strangeDirectory.html", 0) self.storeCache(pageTree) self.storeCache(pageTree) againPageTree = self.fetchCache(pageTree.getUrl(0)) self.clearPage(pageTree.getUrl(0)) if not againPageTree.equals(pageTree): return False if not againPageTree.getRevisionNum(0) == 1: return False return True
def sampleTree(self): pageTree = PageTree("http://www.dummyurl.com/sample/aPage.html") pageTree.setEncodeType(0, "Jibberish") pageTree.setContent(0, "Here is some content. Blah blah blah.", pageTree.getEncodeType(0)) pageTree.setPullTS(0, "57") pageTree.setHash(0, "Doobop") return pageTree
def testMalformedUrl(self): url = "some.really.bad./wrongurl//" pageTree = PageTree() pageTree.createPageNode(url, 0) self.storeCache(pageTree)
def testSpecificNameTree(self, treeRootDir): pageTree = PageTree() pageTree.createPageNode(treeRootDir, 0) self.storeCache(pageTree)