def checkLooseness(self, k, c, fix): orphan = False parent = getParent(c) if parent == None: print "[1st deg ORPHAN] %s\n" % prettyPrint(c) orphan = True elif hasattr(parent, 'getOwnerList') and parent.getOwnerList() == []: print "[2nd deg ORPHAN] %s %s\n" % (prettyPrint(c), parent) orphan = True if orphan and fix: DBMgr.getInstance().sync() print "Fixing %s..." % prettyPrint(c), if orphan: words = self.idx._words l = words[k] pos = l.index(c) print "del val %s\n" % l[pos] del l[pos] words[k] = l self.idx.setIndex(words) ids = self.idx._ids l = ids[k] print "del key %s\n" % l[pos] del l[pos] ids[k] = l DBMgr.getInstance().commit() print "Done!\n"
def findCamouflaged(fix=False,fromDate=None): table = { 0: [Conference], 1: [Contribution, AcceptedContribution], 2: [SubContribution] } dbi = DBMgr.getInstance() dbi.startRequest() camouflaged = [] doh = DeletedObjectHolder() for obj in doh.getList(): types = table[obj.getId().count(":")] if not obj._objClass in types: camouflaged.append(obj) print "-- CAMOUFLAGED %s (%s) should be in %s" % (prettyPrint(obj), obj._objClass, types) if fix: for c in camouflaged: dbi.sync() doh.remove(c) dbi.commit() print "-- FIXED %s " % prettyPrint(c) dbi.endRequest() print "\n Total of %s camouflaged conferences found" % len(camouflaged) return camouflaged
def checkLooseness(self, k, c, fix): orphan = False parent = getParent(c) if parent == None: print "[1st deg ORPHAN] %s\n" % prettyPrint(c) orphan = True elif hasattr(parent, "getOwnerList") and parent.getOwnerList() == []: print "[2nd deg ORPHAN] %s %s\n" % (prettyPrint(c), parent) orphan = True if orphan and fix: DBMgr.getInstance().sync() print "Fixing %s..." % prettyPrint(c), if orphan: words = self.idx._words l = words[k] pos = l.index(c) print "del val %s\n" % l[pos] del l[pos] words[k] = l self.idx.setIndex(words) ids = self.idx._ids l = ids[k] print "del key %s\n" % l[pos] del l[pos] ids[k] = l DBMgr.getInstance().commit() print "Done!\n"
def findCamouflaged(fix=False, fromDate=None): table = { 0: [Conference], 1: [Contribution, AcceptedContribution], 2: [SubContribution] } dbi = DBMgr.getInstance() dbi.startRequest() camouflaged = [] doh = DeletedObjectHolder() for obj in doh.getList(): types = table[obj.getId().count(":")] if not obj._objClass in types: camouflaged.append(obj) print "-- CAMOUFLAGED %s (%s) should be in %s" % ( prettyPrint(obj), obj._objClass, types) if fix: for c in camouflaged: dbi.sync() doh.remove(c) dbi.commit() print "-- FIXED %s " % prettyPrint(c) dbi.endRequest() print "\n Total of %s camouflaged conferences found" % len(camouflaged) return camouflaged
def checkProtection(self, k, c): if not c.getOwner(): print "[WARN] Since event '%s' is orphaned, protection cannot be checked" % prettyPrint( c) elif not self.isVisible(c): print "[ERR] Conference '%s' should not be here (protection)" % prettyPrint( c) self.err += 1
def checkOAIModificationTime(self, k, c): if k != c.getOAIModificationDate().strftime("%Y-%m-%d"): print "[ERR] Key '%s' does not match with mod. date %s (%s)!" % ( k, c.getOAIModificationDate(), prettyPrint(c), ) self.err += 1
def reindex(fix=False, fromDate=None): """ Recreate deleted obj indices, from the DOH """ dbi = DBMgr.getInstance() dbi.startRequest() pubConfIdx = IndexesHolder().getIndex( 'OAIDeletedConferenceModificationDate') prvConfIdx = IndexesHolder().getIndex( 'OAIDeletedPrivateConferenceModificationDate') pubContIdx = IndexesHolder().getIndex( 'OAIDeletedContributionModificationDate') prvContIdx = IndexesHolder().getIndex( 'OAIDeletedPrivateContributionModificationDate') doh = DeletedObjectHolder() pubConfIdx.initIndex() pubContIdx.initIndex() prvConfIdx.initIndex() prvContIdx.initIndex() fromDateParsed_tz = datetime.datetime( *time.strptime(fromDate, '%Y-%m-%d')[:6], **{'tzinfo': timezone('UTC')}) fromDateParsed_naive = datetime.datetime( *time.strptime(fromDate, '%Y-%m-%d')[:6]) for obj in doh.getList(): if fromDate: if obj.getOAIModificationDate().tzinfo: fromDateParsed = fromDateParsed_tz else: fromDateParsed = fromDateParsed_naive if obj.getOAIModificationDate() < fromDateParsed: continue if not hasattr(obj, 'protected'): print "NO DATA FOR %s (%s)" % (obj.getId(), obj.getOAIModificationDate()) continue print "indexing %s (%s)" % (prettyPrint(obj), obj.getOAIModificationDate()) if obj._objClass == Conference: if obj.protected: prvConfIdx.indexConference(obj) else: pubConfIdx.indexConference(obj) elif obj._objClass == Contribution or obj._objClass == AcceptedContribution or obj._objClass == SubContribution: if obj.protected: prvContIdx.indexContribution(obj) else: pubContIdx.indexContribution(obj) dbi.commit() dbi.endRequest()
def guessProtection(fix=False, fromDate=None): """ Recreate deleted obj indices, from the DOH, guessing the protection, using the parent category""" dbi = DBMgr.getInstance() dbi.startRequest() doh = DeletedObjectHolder() if fromDate: fromDateParsed_tz = datetime.datetime( *time.strptime(fromDate, '%Y-%m-%d')[:6], **{'tzinfo': timezone('UTC')}) fromDateParsed_naive = datetime.datetime( *time.strptime(fromDate, '%Y-%m-%d')[:6]) for obj in doh.getList(): if fromDate: if obj.getOAIModificationDate().tzinfo: fromDateParsed = fromDateParsed_tz else: fromDateParsed = fromDateParsed_naive if obj.getOAIModificationDate() < fromDateParsed: continue if not hasattr(obj, 'protected'): try: categ = CategoryManager().getById(obj.getCategoryPath()[-1]) obj.protected = categ.hasAnyProtection() print "-- protection for %s set as %s" % (prettyPrint(obj), obj.protected) except KeyError: print ">> CATEGORY %s for %s no longer exists - assuming TRUE" % ( obj.getCategoryPath()[-1], prettyPrint(obj)) obj.protected = True dbi.commit() else: print "** protection for %s was already at %s" % (prettyPrint(obj), obj.protected) dbi.endRequest()
def guessProtection(fix=False,fromDate=None): """ Recreate deleted obj indices, from the DOH, guessing the protection, using the parent category""" dbi = DBMgr.getInstance() dbi.startRequest() doh = DeletedObjectHolder() if fromDate: fromDateParsed_tz = datetime.datetime(*time.strptime(fromDate,'%Y-%m-%d')[:6],**{'tzinfo':timezone('UTC')}) fromDateParsed_naive = datetime.datetime(*time.strptime(fromDate,'%Y-%m-%d')[:6]) for obj in doh.getList(): if fromDate: if obj.getOAIModificationDate().tzinfo: fromDateParsed = fromDateParsed_tz else: fromDateParsed = fromDateParsed_naive if obj.getOAIModificationDate() < fromDateParsed: continue if not hasattr(obj, 'protected'): try: categ = CategoryManager().getById(obj.getCategoryPath()[-1]) obj.protected = categ.hasAnyProtection() print "-- protection for %s set as %s" % (prettyPrint(obj), obj.protected) except KeyError: print ">> CATEGORY %s for %s no longer exists - assuming TRUE" % (obj.getCategoryPath()[-1], prettyPrint(obj)) obj.protected = True dbi.commit() else: print "** protection for %s was already at %s" % (prettyPrint(obj), obj.protected) dbi.endRequest()
def reindex(fix=False,fromDate=None): """ Recreate deleted obj indices, from the DOH """ dbi = DBMgr.getInstance() dbi.startRequest() pubConfIdx = IndexesHolder().getIndex('OAIDeletedConferenceModificationDate') prvConfIdx = IndexesHolder().getIndex('OAIDeletedPrivateConferenceModificationDate') pubContIdx = IndexesHolder().getIndex('OAIDeletedContributionModificationDate') prvContIdx = IndexesHolder().getIndex('OAIDeletedPrivateContributionModificationDate') doh = DeletedObjectHolder() pubConfIdx.initIndex() pubContIdx.initIndex() prvConfIdx.initIndex() prvContIdx.initIndex() fromDateParsed_tz = datetime.datetime(*time.strptime(fromDate,'%Y-%m-%d')[:6],**{'tzinfo':timezone('UTC')}) fromDateParsed_naive = datetime.datetime(*time.strptime(fromDate,'%Y-%m-%d')[:6]) for obj in doh.getList(): if fromDate: if obj.getOAIModificationDate().tzinfo: fromDateParsed = fromDateParsed_tz else: fromDateParsed = fromDateParsed_naive if obj.getOAIModificationDate() < fromDateParsed: continue if not hasattr(obj,'protected'): print "NO DATA FOR %s (%s)" % (obj.getId(), obj.getOAIModificationDate()) continue print "indexing %s (%s)" % (prettyPrint(obj), obj.getOAIModificationDate()) if obj._objClass == Conference: if obj.protected: prvConfIdx.indexConference(obj) else: pubConfIdx.indexConference(obj) elif obj._objClass == Contribution or obj._objClass == AcceptedContribution or obj._objClass == SubContribution: if obj.protected: prvContIdx.indexContribution(obj) else: pubContIdx.indexContribution(obj) dbi.commit() dbi.endRequest()
def checkOAIModificationTime(self, k, c): if k != c.getOAIModificationDate().strftime("%Y-%m-%d"): print "[ERR] Key '%s' does not match with mod. date %s (%s)!" % ( k, c.getOAIModificationDate(), prettyPrint(c)) self.err += 1
def print_record(self, record, format): self._token = None if self._DataInt.isDeletedItem(self._DataInt.objToId(record)): print '- %s' % prettyPrint(record) else: print '+ %s' % prettyPrint(record)
def findZombies(fix=False,fromDate=None): dbi = DBMgr.getInstance() dbi.startRequest() pubConfIdx = IndexesHolder().getIndex('OAIDeletedConferenceModificationDate') prvConfIdx = IndexesHolder().getIndex('OAIDeletedPrivateConferenceModificationDate') pubContIdx = IndexesHolder().getIndex('OAIDeletedContributionModificationDate') prvContIdx = IndexesHolder().getIndex('OAIDeletedPrivateContributionModificationDate') zombies = [] doh = DeletedObjectHolder() for obj in doh.getList(): isZombie = False rec = None if obj._objClass == Conference: try: rec = ConferenceHolder().getById(obj.getId()) isZombie = True except: continue elif obj._objClass == Contribution or obj._objClass == AcceptedContribution: try: conference = ConferenceHolder().getById(obj.confId) except: continue rec = conference.getContributionById(obj.contribId) isZombie = (rec != None) elif obj._objClass == SubContribution: try: conference = ConferenceHolder().getById(obj.confId) except: continue contrib = conference.getContributionById(obj.contribId) if not contrib: continue rec = contrib.getSubContributionById(obj.subContribId) isZombie = (rec != None) if isZombie: print "-- ZOMBIE %s" % prettyPrint(rec) zombies.append(obj) if fix: for z in zombies: dbi.sync() pubConfIdx.unindexElement(z) prvConfIdx.unindexElement(z) pubContIdx.unindexElement(z) prvContIdx.unindexElement(z) id = z.getId() doh.remove(z) dbi.commit() print "-- FIXED %s " % id dbi.endRequest() print "\n Total of %s zombie records found" % len(zombies) return zombies
def checkProtection(self, k, c): if not c.getOwner(): print "[WARN] Since event '%s' is orphaned, protection cannot be checked" % prettyPrint(c) elif not self.isVisible(c): print "[ERR] Conference '%s' should not be here (protection)" % prettyPrint(c) self.err += 1
def findZombies(fix=False, fromDate=None): dbi = DBMgr.getInstance() dbi.startRequest() pubConfIdx = IndexesHolder().getIndex( 'OAIDeletedConferenceModificationDate') prvConfIdx = IndexesHolder().getIndex( 'OAIDeletedPrivateConferenceModificationDate') pubContIdx = IndexesHolder().getIndex( 'OAIDeletedContributionModificationDate') prvContIdx = IndexesHolder().getIndex( 'OAIDeletedPrivateContributionModificationDate') zombies = [] doh = DeletedObjectHolder() for obj in doh.getList(): isZombie = False rec = None if obj._objClass == Conference: try: rec = ConferenceHolder().getById(obj.getId()) isZombie = True except: continue elif obj._objClass == Contribution or obj._objClass == AcceptedContribution: try: conference = ConferenceHolder().getById(obj.confId) except: continue rec = conference.getContributionById(obj.contribId) isZombie = (rec != None) elif obj._objClass == SubContribution: try: conference = ConferenceHolder().getById(obj.confId) except: continue contrib = conference.getContributionById(obj.contribId) if not contrib: continue rec = contrib.getSubContributionById(obj.subContribId) isZombie = (rec != None) if isZombie: print "-- ZOMBIE %s" % prettyPrint(rec) zombies.append(obj) if fix: for z in zombies: dbi.sync() pubConfIdx.unindexElement(z) prvConfIdx.unindexElement(z) pubContIdx.unindexElement(z) prvContIdx.unindexElement(z) id = z.getId() doh.remove(z) dbi.commit() print "-- FIXED %s " % id dbi.endRequest() print "\n Total of %s zombie records found" % len(zombies) return zombies