def post(self): from cache import CacheLocation, TYPE_LOCAL_FD, TYPE_EXTERN_FD from user_sn import confirm from team import get_team_for_team_leader u = confirm(self) team = get_team_for_team_leader(u) if self.request.get("cache-key")=="MAKENEW": cl = CacheLocation() else: cl = CacheLocation.get(self.request.get("cache-key")) cl.team_responsible = team cl.description = self.request.get("description") replace_image = self.request.get("image") if replace_image != "": cl.image = replace_image if self.request.get("cache-type")=="INTERN": cl.type=TYPE_LOCAL_FD elif self.request.get("cache-type")=="EXTERN": cl.type = TYPE_EXTERN_FD else: raise Exception("I don't know the type.") cl.put() self.response.out.write("OK")
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): #get the whole team's caches from cache import CacheLocation, Cache, TYPE_LOCAL_FD, TYPE_EXTERN_FD from team import get_team_for_team_leader from user_sn import confirm from cache import TYPE_LOCAL_FD u = confirm(self) team = get_team_for_team_leader(u) locations = CacheLocation.all().filter("team_responsible =",team).filter("type =",TYPE_LOCAL_FD).fetch(limit=1000) locations += CacheLocation.all().filter("team_responsible =",team).filter("type =",TYPE_EXTERN_FD).fetch(limit=1000) for location in locations: if location.type == TYPE_LOCAL_FD: r = "INTERN" elif location.type == TYPE_EXTERN_FD: r = "EXTERN" logging.info("Writing info for location %s" % location) self.response.out.write(r+";"+location.description+";") self.response.out.write("/cache/img?cache=%s" % location.key() + ";") self.response.out.write(location.key()) self.response.out.write(";") caches = Cache.all().filter("permanent_location =",location) for cache in caches: self.response.out.write(print_cache_info(cache)) self.response.out.write(",") self.response.out.write("\n")
def post(self): from user_sn import confirm from team import get_team_for_team_leader u = confirm(self) team = get_team_for_team_leader(u) from team import invite_person invite_person(u,self.request.get("email"))
def post(self): from user_sn import confirm u = confirm(self) from Content import Content, TYPE_BOOK, set_file_id c = Content(SharedBy = u, Name = self.request.get("title"),Type=TYPE_BOOK,Link=self.request.get("amzn")) set_file_id(c) c.put() self.response.out.write("/share/upload?key=%s" % c.file_id)
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")
def post(self): from user_sn import confirm from team import get_team_for_team_leader from cache import TYPE_EXTERN_FD, TYPE_LOCAL_FD u = confirm(self) team = get_team_for_team_leader(u) from cache import Cache, CacheLocation type = self.request.get("type") if type=="INTERN": ctype = TYPE_LOCAL_FD elif type=="EXTERN": ctype = TYPE_EXTERN_FD where = CacheLocation.get(self.request.get("location")) c = Cache(friendlyName = self.request.get("name"),type=ctype,last_touched=u,space_left=long(self.request.get("freespace")),permanent_location=where,checked_out=True) c.put() self.response.out.write("OK")
def post(self): user = confirm(self) content = Content.get(self.request.get("content")) #calculate points from math import ceil cost = cost_of_content(content) logging.info("cost %d" % cost) from magic import get_magic magic_mod = get_magic() if user.points >= cost or magic_mod.freeleech: r = Request(user=user,file=content) r.put() if not magic_mod.freeleech: user.points -= int(cost) user.put() self.response.out.write("OK") else: self.response.out.write("NEEDMOREPOINTS %d" % (cost - user.points))
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 get(self): from user_sn import confirm from team import get_team_for_team_leader u = confirm(self) team = get_team_for_team_leader(u) self.response.out.write(str(team.invites))
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()