Beispiel #1
0
    def load_chunk(self, chunk):
        first, second, filename = names_for_chunk(chunk.x, chunk.z)
        fp = self.folder.child(first).child(second)
        if not fp.exists():
            fp.makedirs()

        fp = fp.child(filename)
        if not fp.exists():
            raise SerializerReadException("%r doesn't exist!" % chunk)

        tag = self._read_tag(fp)
        if not tag:
            raise SerializerReadException("%r (in %s) is corrupt!" % (chunk, fp.path))

        try:
            self._load_chunk_from_tag(chunk, tag)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" % (chunk, e))
Beispiel #2
0
    def load_chunk(self, chunk):
        first, second, filename = names_for_chunk(chunk.x, chunk.z)
        fp = self.folder.child(first).child(second)
        if not fp.exists():
            fp.makedirs()

        fp = fp.child(filename)
        if not fp.exists():
            raise SerializerReadException("%r doesn't exist!" % chunk)

        tag = self._read_tag(fp)
        if not tag:
            raise SerializerReadException("%r (in %s) is corrupt!" %
                    (chunk, fp.path))

        try:
            self._load_chunk_from_tag(chunk, tag)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                    (chunk, e))
Beispiel #3
0
            raise SerializerReadException("%r (in %s) is corrupt!" %
                    (chunk, fp.path))

        try:
            self._load_chunk_from_tag(chunk, tag)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                    (chunk, e))

    def save_chunk(self, chunk):
        try:
            tag = self._save_chunk_to_tag(chunk)
        except Exception, e:
            raise SerializerWriteException(e)

        first, second, filename = names_for_chunk(chunk.x, chunk.z)
        fp = self.folder.child(first).child(second)
        if not fp.exists():
            fp.makedirs()
        fp = fp.child(filename)

        self._write_tag(fp, tag)

    def load_level(self, level):
        fp = self.folder.child("level.dat")
        if not fp.exists():
            raise SerializerReadException("Level doesn't exist!")

        tag = self._read_tag(self.folder.child("level.dat"))
        if not tag:
            raise SerializerReadException("Level (in %s) is corrupt!" %
Beispiel #4
0
 def test_names_for_chunk(self):
     self.assertEqual(names_for_chunk(-13, 44),
         ("1f", "18", "c.-d.18.dat"))
     self.assertEqual(names_for_chunk(-259, 266),
         ("1p", "a", "c.-77.7e.dat"))
Beispiel #5
0
            raise SerializerReadException("%r (in %s) is corrupt!" %
                    (chunk, fp.path))

        try:
            self._load_chunk_from_tag(chunk, tag)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                    (chunk, e))

    def save_chunk(self, chunk):
        try:
            tag = self._save_chunk_to_tag(chunk)
        except Exception, e:
            raise SerializerWriteException(e)

        first, second, filename = names_for_chunk(chunk.x, chunk.z)
        fp = self.folder.child(first).child(second)
        if not fp.exists():
            fp.makedirs()
        fp = fp.child(filename)

        self._write_tag(fp, tag)

    def load_level(self, level):
        fp = self.folder.child("level.dat")
        if not fp.exists():
            raise SerializerReadException("Level doesn't exist!")

        tag = self._read_tag(self.folder.child("level.dat"))
        if not tag:
            raise SerializerReadException("Level (in %s) is corrupt!" %