Unify headers and use logging in schematics

- Schematics: Import and use logging
 - Demos & test : Unify headers
This commit is contained in:
LeMagnesium 2016-03-06 13:35:45 +01:00
parent 9f7bccd024
commit a4669dca10
5 changed files with 11 additions and 6 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3.4
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
############################
## Demo of Python-Minetest :

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3.4
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
############################
## Demo of Python-Minetest :
@ -41,6 +41,9 @@ if __name__ == "__main__":
db.set_maxcachesize(40)
print("Reading schematic...")
schem = minetest.schematics.Schematic(schfile)
if not schem:
print("No schematic imported. Aborted.")
print("Importing schematic..")
db.import_schematic(pos_import, schem, stage_save=True)
print("Saving...")

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python3
# -*- encoding: UTF-8 -*-
##########################
## Logger for python-minetest

View File

@ -8,6 +8,7 @@
from nodes import Node
from utils import readU16, readU8, readU32, writeU16, writeU8, writeU32
from logger import logger
import zlib
from io import BytesIO
@ -68,7 +69,7 @@ class Schematic:
try:
assert(data.read(4) == b"MTSM")
except AssertionError:
print("ERROR: {0} couldn't load schematic from data : invalid signature".format(self))
logger.error("{0} : Couldn't load schematic from data : invalid signature".format(self))
return
self.version = readU16(data)
@ -144,7 +145,7 @@ class Schematic:
try:
ifile = open(filename, "rb")
except Exception as err:
print("ERROR: {0} couldn't open file {1} : {2}".format(self, filename, err))
logger.error("{0} : Couldn't open file {1} : {2}".format(self, filename, err))
return
self.load(ifile)
@ -153,7 +154,7 @@ class Schematic:
try:
ofile = open(filename, "wb")
except Exception as err:
print("ERROR: {0} couldn't open file {1} : {2}".format(self, filename, err))
logger.error("{0} : Couldn't open file {1} : {2}".format(self, filename, err))
return
ofile.write(self.export().read())

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3.4
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
############################
## Tests ran for Python-MT