Пример #1
0
 def get(self):
   from user_sn import confirm
   u = confirm(self)
   from cache import get_cache_by_name, can_operate_on, ContentCopy
   from Content import content_by_id
   
   c = get_cache_by_name(self.request.get("cache"))
   if not can_operate_on(c,u):
       raise Exception("You can't sync this cache.")
   content = content_by_id(self.request.get("content"))
   logging.info(c.key())
   logging.info(content.key())
   copy = ContentCopy.all().filter("where =",c).filter("content =",content).get()
   logging.info(copy)
   if copy is None:
       self.repsonse.out.write("NO_SUCH_THING")
       return
   result = can_purge(u,copy)
   if result==PURGE_AT_WILL:
       self.response.out.write("PURGE_AT_WILL")
       logging.info("PURGE_AT_WILL")
   elif result==MOVE_TO_SOFTCACHE:
       self.response.out.write("MOVE_TO_SOFTCACHE")
       logging.info("MOVE_TO_SOFTCACHE")
   else:
       self.response.out.write("LEAVE_IN_PLACE")
       logging.info("LEAVE_IN_PLACE")
Пример #2
0
 def post(self):
     from user_sn import confirm
     u = confirm(self)
     from Content import content_by_id
     c = content_by_id(self.request.get("id"))
     if c.SharedBy.key() != u.key():
         raise Exception("You did not share this content")
     if c.file_secret is not None:
         raise Exception("Already completed updating this content")
     c.file_secret =self.request.get("key")
     c.file_size = long(self.request.get("size"))
     c.put()
     self.response.out.write("OK")
Пример #3
0
    def post(self):
        from user_sn import confirm
        from cache import (
            can_operate_on,
            get_copy,
            ContentCopy,
            get_cache_by_name,
            TYPE_COMPUTER,
            TYPE_EXTERN_FD,
            TYPE_LOCAL_FD,
            TYPE_EXTERNAL_RING,
        )
        from Content import content_by_id

        u = confirm(self)
        cname = self.request.get("cache")
        c = get_cache_by_name(cname)
        if not can_operate_on(c, u):
            raise Exception("You're not permitted to sync this cache.")
        deletes = self.request.get("deletes")
        for item in deletes.split("\n"):
            if item == "":
                continue
            logging.info("deleting %s" % item)
            get_copy(cname, item).delete()
        adds = self.request.get("adds")
        for item in adds.split("\n"):
            if item == "":
                continue
            logging.info("adding %s" % item)
            # see if there's an RC associated with this
            from request import RequestCopy

            content = content_by_id(item)
            rcs = RequestCopy.all().filter("file =", content)
            if c.type == TYPE_COMPUTER:
                rcs = rcs.filter("dest =", u).fetch(limit=1000)
            elif c.type == TYPE_LOCAL_FD:
                rcs = (
                    rcs.filter("dest =", c.permanent_location.team_responsible)
                    .filter("dest_int =", TYPE_LOCAL_FD)
                    .fetch(limit=1000)
                )
            elif c.type == TYPE_EXTERN_FD:
                # the common case (closing the RC associated with a swap) is handled in runComplete.
                rcs = (
                    RequestCopy.all()
                    .filter("file =", content)
                    .filter("dest_int =", TYPE_EXTERNAL_RING)
                    .fetch(limit=1000)
                )
            for rc in rcs:
                logging.info("Closing %s" % rc.key())
                rc.delete()
            co = ContentCopy(where=c, content=content)
            if co.content is None:
                logging.warning("Not adding %s" % item)
            else:
                co.put()
        c.space_left = int(self.request.get("size"))
        c.last_touched = u
        c.put()
Пример #4
0
def get_copy(cacheid,fileid):
    from Content import content_by_id
    c = get_cache_by_name(cacheid)
    content = content_by_id(fileid)
    return ContentCopy.all().filter("content =",content).filter("where =",c).get()