Example #1
0
def fix_nodes(request):
    from hazel.nuts.pages.models import Node
    from hazel.models.restoremap import RestoreMap
    from google.appengine.ext import db

    _map = {}

    for m in RestoreMap.all():
        source = str(m.key().name())[7:]
        sink = m.sink
        if source != sink:
            _map[source] = m.sink

    def tryfix(x):
        if x in _map:
            return _map[x]
        return x

    for n in Node.all():
        for prop in ('siblings','children', 'ancestors'):
            setattr(n,prop,map(tryfix, getattr(n,prop)))
        n.put()
    db.delete(RestoreMap.all())

    return Response("Fixed!")
Example #2
0
def eb_rec(request):
    if request.method != 'POST':
        return Response('POST required')
    f = request.files.get('file')
    key_map = {}
    def decode(x,y):
        if y is None:
            return y
        if isinstance(x, db.UserProperty):
            return users.User(email=y)
        if isinstance(x, db.ReferenceProperty):
            key = RestoreMap.sink_for_key(y)
            if key:
                return db.Key(key)
            return db.Key(y)
        return y
    while True:
        try:
            (l,) = unpack('I', f.read(4))
            t = loads(decompress(f.read(l)))
            mod = __import__(t[0], fromlist=[t[0]])
            kind = getattr(mod,t[1])
            key = db.Key(t[2])
            kwds = dict([(k,decode(getattr(kind, k), v)) for k,v in t[3]])
            if key.name():
                kwds['key_name'] = key.name()
            obj = kind(**kwds)
            obj.put()
            RestoreMap.create_or_update(str(key), sink=str(obj.key()))
        except error, e:
            break
Example #3
0
 def decode(x,y):
     if y is None:
         return y
     if isinstance(x, db.UserProperty):
         return users.User(email=y)
     if isinstance(x, db.ReferenceProperty):
         key = RestoreMap.sink_for_key(y)
         if key:
             return db.Key(key)
         return db.Key(y)
     return y