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_from_tl(request, allcopies): logging.info("Searching team leader...") from user_sn import all_team_leaders_for leaders = all_team_leaders_for(request.user.team) leader_copies = [] from cache import TYPE_COMPUTER, is_cache_available_soon, TYPE_LOCAL_FD for copy in allcopies: if ( copy.where.last_touched.team.key() == request.user.team.key() and copy.where.type == TYPE_COMPUTER and is_cache_available_soon(copy.where) and copy.where.last_touched.team_leader_flag ): logging.info("Found copy from team leader!") dest = request.user.team if ( RequestCopy.all() .filter("file =", request.file) .filter("dest =", dest) .filter("dest_int =", TYPE_LOCAL_FD) .get() == None ): logging.info("No RequestCopy currently exists; creating...") rc = RequestCopy( file=request.file, req=request, dest=dest, dest_int=TYPE_LOCAL_FD, emailed_user=copy.where.last_touched, ) rc.put() send_run_msg(rc.emailed_user) else: logging.info("RequestCopy already exists.") return True return False
def get_from_any_ext_cache(request, allcopies): logging.info("Searching all external caches...") from cache import TYPE_EXTERN_FD, is_cache_available_soon for copy in allcopies: if copy.where.type == TYPE_EXTERN_FD and is_cache_available_soon(copy.where): logging.info( "Found a copy on team %s's external cache %s" % (copy.where.permanent_location.team_responsible.name, copy.where.friendlyName) ) dest = request.user.team if ( RequestCopy.all() .filter("file =", request.file) .filter("dest =", dest) .filter("dest_int =", TYPE_EXTERN_FD) .get() == None ): logging.info("No RequestCopy currently exists; creating...") # we need to get ahold of a team leader from user_sn import all_team_leaders_for leaders = all_team_leaders_for(request.user.team) from random import choice flag_leader = choice(leaders) rc = RequestCopy( file=request.file, req=request, dest=dest, dest_int=TYPE_EXTERN_FD, emailed_user=flag_leader ) rc.put() send_run_msg(flag_leader) else: logging.info("RequestCopy already exists.") return True return False