class SimpleCoreServer(SocketServer):
    def setup(self):
        try:
            self.objects = read_and_analyse(file_name)
            self.worlds = []
            for obj in list(self.objects.values()):
                if obj.has_parent("world") and obj.id != "world":
                    self.worlds.append(obj)
                    print(obj)
            print(len(self.objects), "objects loaded in", len(self.worlds),
                  "worlds")
        except IOError:
            print("no %s, starting empty" % file_name)
            print(
                'do "python2 gen_simple_core.py" to generate example meadow file'
            )
            print(
                "or get it from http://purple.worldforge.org/~aloril/atlas/simple_core.atlas"
            )
            self.objects = {}
        self.save_no = 0
        self.save()
        self.log = File(log_file_name, "w")

    def reply_all(self, op, new_op):
        for client in self.clients:
            client.reply_operation(op, new_op)

    def save(self):
        return
        name = save_file_name % self.save_no
        write_file(list(self.objects.values()), name)
        print("Wrote", name)
        self.save_no = self.save_no + 1

    def next_id(self):
        i = 0
        while str(i) in self.objects:
            i = i + 1
        return "a" + str(i)

    def check_bidirectional(self, obj, op="create"):
        if not obj: return
        #print "check_bidirectional:", op, obj.id, op
        for attr, other_attr in [("loc", "contains")]:
            if hasattr(obj, attr):
                value = getattr(obj, attr)
                other_obj = self.objects.get(value)
                if other_obj and hasattr(other_obj, other_attr):
                    other_value = getattr(other_obj, other_attr)
                    #print "check_bidirectional:", other_obj.id, other_value
                    if op == "create":
                        other_value.append(obj.id)
                    else:
                        other_value.remove(obj.id)

    def log_op(self, op):
        self.log.write_object(op)
        self.log.fp.flush()
Exemplo n.º 2
0
class SimpleCoreServer(SocketServer):
    def setup(self):
        try:
            self.objects = read_and_analyse(file_name)
            self.worlds = []
            for obj in self.objects.values():
                if obj.has_parent("world") and obj.id != "world":
                    self.worlds.append(obj)
                    print obj
            print len(self.objects), "objects loaded in", len(self.worlds), "worlds"
        except IOError:
            print "no %s, starting empty" % file_name
            print 'do "python2 gen_simple_core.py" to generate example meadow file'
            print "or get it from http://purple.worldforge.org/~aloril/atlas/simple_core.atlas"
            self.objects = {}
        self.save_no = 0
        self.save()
        self.log = File(log_file_name, "w")

    def reply_all(self, op, new_op):
        for client in self.clients:
            client.reply_operation(op, new_op)

    def save(self):
        return
        name = save_file_name % self.save_no
        write_file(self.objects.values(), name)
        print "Wrote", name
        self.save_no = self.save_no + 1

    def next_id(self):
        i = 0
        while self.objects.has_key(str(i)):
            i = i + 1
        return "a" + str(i)

    def check_bidirectional(self, obj, op="create"):
        if not obj:
            return
        # print "check_bidirectional:", op, obj.id, op
        for attr, other_attr in [("loc", "contains")]:
            if hasattr(obj, attr):
                value = getattr(obj, attr)
                other_obj = self.objects.get(value)
                if other_obj and hasattr(other_obj, other_attr):
                    other_value = getattr(other_obj, other_attr)
                    # print "check_bidirectional:", other_obj.id, other_value
                    if op == "create":
                        other_value.append(obj.id)
                    else:
                        other_value.remove(obj.id)

    def log_op(self, op):
        self.log.write_object(op)
        self.log.fp.flush()
Exemplo n.º 3
0
 def setup(self):
     try:
         self.objects = read_and_analyse(file_name)
         self.worlds = []
         for obj in self.objects.values():
             if obj.has_parent("world") and obj.id!="world":
                 self.worlds.append(obj)
                 print obj
         print len(self.objects), "objects loaded in", len(self.worlds), "worlds"
     except IOError:
         print "no %s, starting empty" % file_name
         print 'do "python2 gen_simple_core.py" to generate example meadow file'
         print "or get it from http://purple.worldforge.org/~aloril/atlas/simple_core.atlas"
         self.objects = {}
     self.save_no = 0
     self.save()
     self.log = File(log_file_name, "w")
Exemplo n.º 4
0
 def setup(self):
     try:
         self.objects = read_and_analyse(file_name)
         self.worlds = []
         for obj in self.objects.values():
             if obj.has_parent("world") and obj.id != "world":
                 self.worlds.append(obj)
                 print obj
         print len(self.objects), "objects loaded in", len(self.worlds), "worlds"
     except IOError:
         print "no %s, starting empty" % file_name
         print 'do "python2 gen_simple_core.py" to generate example meadow file'
         print "or get it from http://purple.worldforge.org/~aloril/atlas/simple_core.atlas"
         self.objects = {}
     self.save_no = 0
     self.save()
     self.log = File(log_file_name, "w")