예제 #1
0
    def resolve_attribute_recursively(self, obj, value, base_id):
        unresolved = []
        if type(value)==StringType:
            if value=='': return unresolved
            this_id = atlas.get_base_id(base_id)
            other_id = atlas.get_base_id(value)
            if self.objects.has_key(other_id):
                #pointer resolved, but all depencies still might not be resolved for this to be ok...
                key = atlas.get_last_part(base_id)
                if type(obj)==ListType: key = int(key)
                if self.verbose:
                    print "!!", str(obj)[:100], value, base_id, key, atlas.resolve_pointer(self.objects, value)
                self.depencies.copy(this_id, other_id)
                obj[key] = atlas.resolve_pointer(self.objects, value)
                self.check_bidirectiontal(obj, key)
                self.links.add(value, base_id)
                return unresolved
            else:
                #pointer not resolved, record needed info for later resolving:
                if self.verbose:
                    print "??", str(obj)[:70], base_id, this_id, value, other_id
                unresolved.append(other_id)
                
                #1) add value into "what pointers other_id object can resolve" -dictionary
                self.pending.add(other_id, base_id)
                if self.verbose:
                    print self.pending
                
                #2) what pointers need to be resolved for this object
                self.depencies.add(this_id, base_id)
                if self.verbose:
                    print self.depencies

                return unresolved
        elif type(value)==ListType:
            if self.verbose:
                print "list:", base_id
            for i in range(len(value)):
                value2 = value[i]
                res = self.resolve_attribute_recursively(value, value2, "%s.%s" % (base_id, i))
                if res: unresolved = unresolved + res
            return unresolved
        elif type(value)==DictType or \
             (type(value)==InstanceType and hasattr(value, "items") and not hasattr(value, "id")):
            if self.verbose:
                print "dict:", base_id
            for key, value2 in value.items():
                res = self.resolve_attribute_recursively(value, value2, "%s.%s" % (base_id, key))
                if res: unresolved = unresolved + res
            return unresolved
        #ignore unknown types (like Vector3D)
        if self.verbose:
            print "this type (%s) not handled yet (%s)..." % (type(value), value)
            if type(value)==InstanceType:
                print "class:", value.__class__, value.__class__.__bases__
        #raise ValueError, "this type (%s) not handled yet (%s)..." % (type(value), value)
        return unresolved
예제 #2
0
 def ask(self, id_lst):
     for id in id_lst:
         id = atlas.get_base_id(id)
         #print "?"*60, id, len(id_lst)
         if id and not self.pending.has_key(id) and not self.objects.has_key(id):
             print "?", id
             op = atlas.Operation("get", atlas.Object(id=id))
             self.send_operation(op)
             self.pending[id] = id
예제 #3
0
 def ask(self, id_lst):
     for id in id_lst:
         id = atlas.get_base_id(id)
         #print "?"*60, id, len(id_lst)
         if id and id not in self.pending and id not in self.objects:
             print("?", id)
             op = atlas.Operation("get", atlas.Object(id=id))
             self.send_operation(op)
             self.pending[id] = id
예제 #4
0
 def ask(self, id_lst):
     for id in id_lst:
         id = atlas.get_base_id(id)
         #print "?"*60, id, len(id_lst)
         if id and not self.pending.has_key(
                 id) and not self.objects.has_key(id):
             print "?", id
             op = atlas.Operation("get", atlas.Object(id=id))
             self.send_operation(op)
             self.pending[id] = id
예제 #5
0
 def set_op(self, op):
     ent = op.arg
     #CHEAT: should create missing objects, not assume that we are up to date
     obj = atlas.resolve_pointer(self.objects, ent.id)
     self.objects._send_flag = 0
     try:
         for key, value in ent.items(convert2plain_flag=0):
             if key == "id": continue
             if type(obj) == ListType:
                 obj[key] = value
             else:
                 setattr(obj, key, value)
     finally:
         self.objects._send_flag = 1
     if self.verbose:
         print "updated entity:", ent
     self.call_trigger("set", self.objects[atlas.get_base_id(ent.id)])
예제 #6
0
 def set_op(self, op):
     ent = op.arg
     #CHEAT: should create missing objects, not assume that we are up to date
     obj = atlas.resolve_pointer(self.objects, ent.id)
     self.objects._send_flag = 0
     try:
         for key,value in ent.items(convert2plain_flag=0):
             if key=="id": continue
             if type(obj)==ListType:
                 obj[key] = value
             else:
                 setattr(obj, key, value)
     finally:
         self.objects._send_flag = 1
     if self.verbose:
         print "updated entity:", ent
     self.call_trigger("set", self.objects[atlas.get_base_id(ent.id)])