def post(self): av = self.request.get('av') data = AvData.get_or_insert(key_name="Data:" + av) query = AvTokenValue.gql("WHERE av = :1", av) if query.count(1) > 0: for record in query: if record.value != "leasher,00000000-0000-0000-0000-000000000000": setattr(data, record.token, record.value) data.put() for record in query: record.delete() name = Av.get_by_key_name("Av:" + av) if name is None: namequery = Av.gql("WHERE id = :1", av) count = namequery.count() if count == 0: #doesn't exist. save logging.error("key %s has no record in Av. While converting", av) elif count == 1: #already exists. just update the name avname = namequery.get() if avname: Av(key_name="Av:" + av, id=av, name=avname.name).put() avname.delete() else: #there's more than one record. delete them all and just save one #this should never happen logging.error("key %s had more than one record in Av.", av) avname = "" for record in namequery: avname = record.name record.delete() Av(key_name="Av:" + av, id=av, name=avname)
def post(self): av = self.request.get('av') data = AvData.get_or_insert(key_name="Data:"+av) query = AvTokenValue.gql("WHERE av = :1", av) if query.count(1) > 0: for record in query: if record.value != "leasher,00000000-0000-0000-0000-000000000000": setattr(data, record.token, record.value) data.put() for record in query: record.delete() name = Av.get_by_key_name("Av:"+av) if name is None: namequery = Av.gql("WHERE id = :1", av) count = namequery.count() if count == 0:#doesn't exist. save logging.error("key %s has no record in Av. While converting", av) elif count == 1:#already exists. just update the name avname = namequery.get() if avname: Av(key_name="Av:"+av, id = av, name = avname.name).put() avname.delete() else:#there's more than one record. delete them all and just save one #this should never happen logging.error("key %s had more than one record in Av.", av) avname = "" for record in namequery: avname = record.name record.delete() Av(key_name="Av:"+av, id = av, name = avname)
def update_av(id, name): """update's av's name if key found, else creates entity. only use request header data. POST and PUT data are not trustworthy.""" av = Av.get_by_key_name("Av:" + id) #optimize if av is None: #Av(key_name="Av:"+id,id = id, name = name).put() query = Av.gql("WHERE id = :1", id) count = query.count() if count == 0: #doesn't exist. save Av(key_name="Av:" + id, id=id, name=name).put() elif count == 1: #already exists. just update the name av = query.get() if (av.name != name): av.name = name av.put() else: #there's more than one record. delete them all and just save one #this should never happen logging.error("%s key %s had more than one record in Av.", name, id) for record in query: record.delete() av = Av(key_name="Av:" + id, id=id, name=name) av.put() elif (av.name != name): av.name = name av.put()
def post(self): lastav = self.request.get('lastav') logging.info('lastav:%s' % (lastav)) q = Av.gql('WHERE id > :1 Order by id', lastav) try: for result in q: taskqueue.add(url='/convert', params={'av': result.id}, queue_name='SlowConvert') lastav = result.id except (DeadlineExceededError, _ToDatastoreError, db.Timeout ): taskqueue.add(url='/convert/loader?lastav=%s' % (lastav), headers={'lastav': lastav}, queue_name='Loader', method='PUT') logging.info('lastav:%s' % (lastav))
def key2name(key): """given an av uuid, returns av name. Returns None if av not found""" av = Av.get_by_key_name("Av:"+key) if av is None: av = Av.gql("WHERE id = :1", key).get() if av: return av.name else: return None else: return av.name
def key2name(key): """given an av uuid, returns av name. Returns None if av not found""" av = Av.get_by_key_name("Av:" + key) if av is None: av = Av.gql("WHERE id = :1", key).get() if av: return av.name else: return None else: return av.name
def post(self): lastav = self.request.get('lastav') logging.info('lastav:%s' % (lastav)) q = Av.gql('WHERE id > :1 Order by id', lastav) try: for result in q: taskqueue.add(url='/convert', params={'av': result.id}, queue_name='SlowConvert') lastav = result.id except (DeadlineExceededError, _ToDatastoreError, db.Timeout): taskqueue.add(url='/convert/loader?lastav=%s' % (lastav), headers={'lastav': lastav}, queue_name='Loader', method='PUT') logging.info('lastav:%s' % (lastav))
def update_av(id, name): """update's av's name if key found, else creates entity. only use request header data. POST and PUT data are not trustworthy.""" av = Av.get_by_key_name("Av:"+id)#optimize if av is None: #Av(key_name="Av:"+id,id = id, name = name).put() query = Av.gql("WHERE id = :1", id) count = query.count() if count == 0:#doesn't exist. save Av(key_name="Av:"+id,id = id, name = name).put() elif count == 1:#already exists. just update the name av = query.get() if (av.name != name): av.name = name av.put() else:#there's more than one record. delete them all and just save one #this should never happen logging.error("%s key %s had more than one record in Av.", name, id) for record in query: record.delete() av = Av(key_name="Av:"+id, id = id, name = name) av.put() elif (av.name != name): av.name = name av.put()