示例#1
0
class TestRegion(TestCase):

    def setUp(self):
        self.temp = NamedTemporaryFile()
        self.fp = FilePath(self.temp.name)
        self.region = Region(self.fp)

    def test_trivial(self):
        pass

    def test_create(self):
        self.region.create()
        self.assertEqual(self.temp.read(), "\x00" * 8192)
示例#2
0
class TestRegion(TestCase):

    def setUp(self):
        self.fp = FilePath(self.mktemp())
        self.region = Region(self.fp)

    def test_trivial(self):
        pass

    def test_create(self):
        self.region.create()
        with self.fp.open("r") as handle:
            self.assertEqual(handle.read(), "\x00" * 8192)
示例#3
0
    def load_chunk(self, x, z):
        name = name_for_anvil(x, z)
        fp = self.folder.child("region").child(name)
        region = Region(fp)
        chunk = Chunk(x, z)

        try:
            data = region.get_chunk(x, z)
            tag = NBTFile(buffer=StringIO(data))
            self._load_chunk_from_tag(chunk, tag)
        except MissingChunk:
            raise SerializerReadException("No chunk %r in region" % chunk)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                                          (chunk, e))
示例#4
0
    def load_chunk(self, x, z):
        name = name_for_anvil(x, z)
        fp = self.folder.child("region").child(name)
        region = Region(fp)
        chunk = Chunk(x, z)

        try:
            data = region.get_chunk(x, z)
            tag = NBTFile(buffer=StringIO(data))
            self._load_chunk_from_tag(chunk, tag)
        except MissingChunk:
            raise SerializerReadException("No chunk %r in region" % chunk)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                    (chunk, e))
示例#5
0
    def save_chunk(self, chunk):
        tag = self._save_chunk_to_tag(chunk)

        b = StringIO()
        tag.write_file(buffer=b)
        data = b.getvalue()

        name = name_for_anvil(chunk.x, chunk.z)
        fp = self.folder.child("region").child(name)

        # Allocate the region and put the chunk into it. Use ensure() instead
        # of create() so that we don't trash the region.
        region = Region(fp)

        try:
            region.ensure()
            region.put_chunk(chunk.x, chunk.z, data)
        except IOError, e:
            raise SerializerWriteException("Couldn't write to region: %r" % e)
示例#6
0
    def save_chunk(self, chunk):
        tag = self._save_chunk_to_tag(chunk)

        b = StringIO()
        tag.write_file(buffer=b)
        data = b.getvalue()

        name = name_for_anvil(chunk.x, chunk.z)
        fp = self.folder.child("region").child(name)

        # Allocate the region and put the chunk into it. Use ensure() instead
        # of create() so that we don't trash the region.
        region = Region(fp)

        try:
            region.ensure()
            region.put_chunk(chunk.x, chunk.z, data)
        except IOError, e:
            raise SerializerWriteException("Couldn't write to region: %r" % e)
示例#7
0
 def setUp(self):
     self.temp = NamedTemporaryFile()
     self.fp = FilePath(self.temp.name)
     self.region = Region(self.fp)
示例#8
0
 def setUp(self):
     self.fp = FilePath(self.mktemp())
     self.region = Region(self.fp)
示例#9
0
import sys

from twisted.python.filepath import FilePath

from bravo.region import Region

if len(sys.argv) < 2:
    print "No path specified!"
    sys.exit()

fp = FilePath(sys.argv[1])

if not fp.exists():
    print "Region %r doesn't exist!" % fp.path
    sys.exit()

region = Region(fp)
region.load_pages()

if region.free_pages:
    print "Free pages:", sorted(region.free_pages)
else:
    print "No free pages."

print "Chunks:"

for (x, z) in region.positions:
    length, version = region.get_chunk_header(x, z)
    print " ~ (%d, %d): v%d, %.2fKiB" % (x, z, version, length / 1024)