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")
def get(self): from cache import can_operate_on, ContentCopy, get_cache_by_name, Cache, TYPE_COMPUTER from user_sn import confirm u = confirm(self) cname = self.request.get("cache") logging.info("Syncing a cache named %s" % cname) c = get_cache_by_name(cname) if c == None: logging.info("No cached named %s, making a new one" % cname) c = Cache(friendlyName=cname, type=TYPE_COMPUTER, last_touched=u, space_left=-1, person_responsible=u) c.put() if not can_operate_on(c, u): raise Exception("You're not permitted to sync this cache.") # fetch everything that's "supposed" to be on the key copies = ContentCopy.all().filter("where =", c).fetch(limit=1000) self.response.out.write("OK\n") for copy in copies: self.response.out.write(copy.content.file_id + "\n")
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()