From a4669dca107872f46f7e2108bf44d84ac97b91db Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Sun, 6 Mar 2016 13:35:45 +0100 Subject: [PATCH] Unify headers and use logging in schematics - Schematics: Import and use logging - Demos & test : Unify headers --- src/demo_clean_unknown.py | 2 +- src/demo_schematic_manipulation.py | 5 ++++- src/logger.py | 1 + src/schematics.py | 7 ++++--- src/test.py | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/demo_clean_unknown.py b/src/demo_clean_unknown.py index 319ad83..b8816f1 100755 --- a/src/demo_clean_unknown.py +++ b/src/demo_clean_unknown.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.4 +#!/usr/bin/env python3 # -*- encoding: utf-8 -*- ############################ ## Demo of Python-Minetest : diff --git a/src/demo_schematic_manipulation.py b/src/demo_schematic_manipulation.py index fce3aef..a97d920 100755 --- a/src/demo_schematic_manipulation.py +++ b/src/demo_schematic_manipulation.py @@ -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...") diff --git a/src/logger.py b/src/logger.py index f476eb8..9a7facb 100644 --- a/src/logger.py +++ b/src/logger.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- encoding: UTF-8 -*- ########################## ## Logger for python-minetest diff --git a/src/schematics.py b/src/schematics.py index f2690e7..6662086 100644 --- a/src/schematics.py +++ b/src/schematics.py @@ -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()) diff --git a/src/test.py b/src/test.py index e4343a5..dcd2f2c 100755 --- a/src/test.py +++ b/src/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.4 +#!/usr/bin/env python3 # -*- encoding: utf-8 -*- ############################ ## Tests ran for Python-MT