def can_purge(user,contentcopy): from cache import ContentCopy, TYPE_COMPUTER allCopies = ContentCopy.all().filter("content =",contentcopy.content).fetch(limit = 1000) #now fetch all the copies allCopies = filter(available_soon_cc,allCopies) #only the ones that are online if len(allCopies) > LEAVE_COPIES_ON_DARKNET+1: copies_on_team = 0 chk_team = team_of(contentcopy) for copy in allCopies: if copy.key()==contentcopy.key(): continue #not interested in the copy we want to purge if chk_team.key()==team_of(copy).key(): copies_on_team += 1 if copies_on_team >= LEAVE_COPIES_ON_TEAM: if not user.team_leader_flag: #wait for the team leader to purge the crap. team_leader_copies = filter(lambda x: x.where.type==TYPE_COMPUTER, copies_on_team) from user_sn import all_team_leaders_for leaders = all_team_leaders_for(user.team) leaders = map(lambda x: x.key(),leaders) team_leader_copies = filter(lambda x: x.where.last_touched.key() in leaders) if len(team_leader_copies) != 0: logging.info("Team leader has a copy. Not purging.") return MOVE_TO_SOFTCACHE else: return PURGE_AT_WILL #this is conservative logic. If there's an outstanding request on the sneakernet, leave the file in place from request import Request reqs = Request.all().filter("file =",contentcopy.content).get() if reqs==None: return MOVE_TO_SOFTCACHE return LEAVE_IN_PLACE
def get(self): req = Request.all().order("last_routed").get() try_to_route(req)