Exemple #1
0
def get_from_really_far_away(request, allcopies):
    from cache import TYPE_COMPUTER, TYPE_EXTERNAL_RING, is_cache_available_soon

    for copy in allcopies:
        if copy.where.type == TYPE_COMPUTER and is_cache_available_soon(copy.where):
            logging.info("Found a copy really far away")
            if RequestCopy.all().filter("file =", request.file).filter("dest_int =", TYPE_EXTERNAL_RING).get() == None:
                logging.info("No RequestCopy currently exists; creating...")
                rc = RequestCopy(
                    file=request.file, req=request, emailed_user=copy.where.last_touched, dest_int=TYPE_EXTERNAL_RING
                )
                rc.put()
                send_run_msg(rc.emailed_user)
            else:
                logging.info("RequestCopy already exists")
            return True
Exemple #2
0
def get_from_ext_cache(request, allcopies):
    logging.info("Searching (our) external cache...")
    from cache import TYPE_EXTERN_FD, is_cache_available_soon

    for copy in allcopies:
        if (
            copy.where.type == TYPE_EXTERN_FD
            and copy.where.permanent_location.team_responsible.key() == request.user.team.key()
            and is_cache_available_soon(copy.where)
        ):
            logging.info("Found copy in the external cache!")
            if RequestCopy.all().filter("file =", request.file).filter("dest =", request.user).get() == None:
                logging.info("No RequestCopy currently exists; creating...")
                rc = RequestCopy(file=request.file, req=request, dest=request.user, emailed_user=request.user)
                rc.put()
                send_run_msg(rc.emailed_user)
            else:
                logging.info("RequestCopy already exists")
            return True
    return False
Exemple #3
0
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
Exemple #4
0
def get_from_someone_on_team_not_tl(request, allcopies):
    from cache import TYPE_COMPUTER, CacheLocation, TYPE_LOCAL_FD, is_cache_available_soon

    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)
        ):
            if copy.where.last_touched.team_leader_flag:
                logging.info("Team leader has a copy; ignoring this copy for now")
                continue
            logging.info("Found copy from another teammember!")
            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
Exemple #5
0
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
Exemple #6
0
def available_soon_cc(contentcopy):
    from cache import is_cache_available_soon
    return is_cache_available_soon(contentcopy.where)