def testGetDateAndDepth(self): for i in range(len(self.dyyoids)): date, depth = ooid.dateAndDepthFromOoid(self.dyyoids[i]) assert self.depths[i] == depth assert self.baseDate == date assert (None, None) == ooid.dateAndDepthFromOoid(self.badooid0) assert (None, None) == ooid.dateAndDepthFromOoid(self.badooid1)
def testGetDateAndDepth(self): for i in range(len(self.dyyoids)): date,depth = oo.dateAndDepthFromOoid(self.dyyoids[i]) assert self.depths[i] == depth, 'Expect depth=%d, got %d (%s)'%(self.depth[i],depth,self.dyyoids[i]) assert self.baseDate == date, 'Expect %s, got %s' %(self.baseDate, date) assert (None,None) == oo.dateAndDepthFromOoid(self.badooid0) assert (None,None) == oo.dateAndDepthFromOoid(self.badooid1)
def testUuidToOid(self): for i in range(len(self.rawuuids)): u = self.rawuuids[i] o0 = oo.uuidToOoid(u) expected = (self.nowstamp,oo.defaultDepth) got = oo.dateAndDepthFromOoid(o0) assert expected == got, 'Expected %s, got %s'%(expected,got) o1 = oo.uuidToOoid(u,timestamp=self.baseDate) expected = (self.baseDate,oo.defaultDepth) got = oo.dateAndDepthFromOoid(o1) assert expected == got, 'Expected %s, got %s'%(expected,got) o2 = oo.uuidToOoid(u,depth=self.depths[i]) expected = (self.nowstamp,self.depths[i]) got = oo.dateAndDepthFromOoid(o2) assert expected == got, 'Expected %s, got %s'%(expected,got) o3 = oo.uuidToOoid(u,depth=self.depths[i],timestamp=self.xmas05) expected = (self.xmas05,self.depths[i]) got = oo.dateAndDepthFromOoid(o3) assert expected == got, 'Expected %s, got %s'%(expected,got)
def namePath(self, ooid, timestamp=None): """ Return the path to the directory for this ooid and the directory parts of the path Ignores encoded ooid depth, uses depth from __init__ (default 2) """ ooidDay,depth = socorro_ooid.dateAndDepthFromOoid(ooid) if not depth: depth = 4 dirs = [self.root,self.dailyPart(ooid,timestamp),self.indexName] dirs.extend(self.relativeNameParts(ooid)) #self.logger.debug("%s - %s -> %s",threading.currentThread().getName(),ooid,dirs) return os.sep.join(dirs),dirs
def remove (self,uuid): """ Removes all instances of the uuid from the file system including the json file, the dump file, and the two links if they still exist. If it finds no trace of the uuid: No links, no data files, it raises a NoSuchUuidFound exception. """ namePath = self.__nameAbsPath(uuid) seenCount = 0 datestamp,depth = socorro_ooid.dateAndDepthFromOoid(uuid) if not depth: depth = 4 # prior, when hardcoded depth=4, uuid[-8:] was yyyymmdd, year was always (20xx) datePath = self.dateBranch try: datePath = os.path.join(namePath,os.readlink(os.path.join(namePath,uuid))) except OSError: self.logger.debug("%s - %s Missing or bad link in %s" % (threading.currentThread().getName(), uuid, namePath)) try: os.unlink(os.path.join(namePath,uuid)) seenCount += 1 except OSError: self.logger.debug("%s - %s Cannot unlink link at %s" % (threading.currentThread().getName(), uuid, namePath)) try: os.unlink(os.path.join(datePath,uuid)) seenCount += 1 except OSError: # probably the root-has-trailing-slash bug. We need the name-to-date link to remove the date-to-name link. # Since the first is wrong, lets just remove the date-to-name link directly webheadHostName = os.path.split(datePath)[1] if datestamp: datePath = self.__makeDateDir(datestamp,webheadHostName) try: os.unlink(os.path.join(datePath,uuid)) seenCount += 1 except: self.logger.debug("%s - %s Cannot unlink link at %s" % (threading.currentThread().getName(), uuid, datePath)) self.__cleanDirectory(datePath, self.dateName) try: os.unlink(os.path.join(namePath,uuid+self.jsonSuffix)) seenCount += 1 except: self.logger.debug("%s - %s Missing json file" % (threading.currentThread().getName(), uuid)) try: os.unlink(os.path.join(namePath,uuid+self.dumpSuffix)) seenCount += 1 except: self.logger.debug("%s - %s Missing dump file" % (threading.currentThread().getName(), uuid)) if self.cleanIndexDirectories: try: self.__cleanDirectory(namePath,namePath.split(os.sep)[-depth:1-depth][0]) #clean only as far back as the first name level except OSError: pass if not seenCount: self.logger.warning("%s - %s was totally unknown" % (threading.currentThread().getName(), uuid)) raise NoSuchUuidFound, "no trace of %s was found" % uuid