changeset 375:91e352f81f63

The serializers will now use the LogManager instead of printing directly to console
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 21 Nov 2009 15:15:55 +0000
parents 1115f7cae9a3
children 22222a900751
files engine/extensions/fife_utils.py engine/extensions/loaders.py engine/extensions/serializers/__init__.py engine/extensions/serializers/xmlmap.py
diffstat 4 files changed, 24 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/engine/extensions/fife_utils.py	Sat Nov 21 13:11:56 2009 +0000
+++ b/engine/extensions/fife_utils.py	Sat Nov 21 15:15:55 2009 +0000
@@ -41,7 +41,7 @@
 	ret = False
 	m = _exc_re.search(str(original_exc))
 	if m:
-		if m.group(1) == type('').getTypeStr():
+		if m.group(1) == type('is_fife_exc test').getTypeStr():
 			ret = True
 	return ret
 
--- a/engine/extensions/loaders.py	Sat Nov 21 13:11:56 2009 +0000
+++ b/engine/extensions/loaders.py	Sat Nov 21 15:15:55 2009 +0000
@@ -26,7 +26,7 @@
 import fife
 
 from serializers.xmlmap import XMLMapLoader
-from serializers import WrongFileType, NameClash
+from serializers import WrongFileType, NameClash, logger
 
 from serializers.xmlobject import XMLObjectLoader
 
@@ -45,7 +45,7 @@
 	"""
 	map_loader = XMLMapLoader(engine, callback)
 	map = map_loader.loadResource(fife.ResourceLocation(path))
-	print "--- Loading map took: ", map_loader.time_to_load, " seconds."
+	logger.log(fife.LogManager.LEVEL_LOG, "--- Loading map took: " + str(map_loader.time_to_load) + " seconds.")
 	return map
 
 
@@ -54,13 +54,12 @@
 	res = None
 	try:
 		res = object_loader.loadResource(fife.ResourceLocation(path))
-		print 'imported object file ' + path
+		logger.log(fife.LogManager.LEVEL_LOG, 'imported object file ' + path)
 	except WrongFileType:
-		pass
-#		print 'ignored non-object file ' + path
+		logger.log(fife.LogManager.LEVEL_LOG, 'ignored non-object file ' + path)
 	except NameClash:
-		pass
-#		print 'ignored already loaded file ' + path
+		logger.log(fife.LogManager.LEVEL_LOG, 'ignored already loaded file ' + path)
+	
 	return res
 
 def loadImportDir(path, engine):
--- a/engine/extensions/serializers/__init__.py	Sat Nov 21 13:11:56 2009 +0000
+++ b/engine/extensions/serializers/__init__.py	Sat Nov 21 15:15:55 2009 +0000
@@ -24,7 +24,7 @@
 import fife, sys, os
 from traceback import print_exc
 
-__all__ = ('ET', 'SerializerError', 'InvalidFormat', 'WrongFileType', 'NameClash', 'NotFound', 'warn', 'root_subfile', 'reverse_root_subfile')
+__all__ = ('ET', 'SerializerError', 'InvalidFormat', 'WrongFileType', 'NameClash', 'NotFound', 'root_subfile', 'reverse_root_subfile', 'logger')
 
 try:
 	import xml.etree.cElementTree as ET
@@ -45,9 +45,8 @@
 
 class NotFound(SerializerError):
 	pass
-
-def warn(self, msg):
-	print 'Warning (%s): %s' % (self.filename, msg)
+	
+logger = fife.Logger(fife.LM_LOADERS)
 
 def root_subfile(masterfile, subfile):
 	'''
--- a/engine/extensions/serializers/xmlmap.py	Sat Nov 21 13:11:56 2009 +0000
+++ b/engine/extensions/serializers/xmlmap.py	Sat Nov 21 15:15:55 2009 +0000
@@ -29,6 +29,7 @@
 
 import loaders
 from serializers import *
+from fife_utils import *
 import time
 
 FORMAT = '1.0'
@@ -88,10 +89,13 @@
 		try:
 			self.map = self.model.createMap(str(id))
 			self.map.setResourceFile(self.source)
-		except fife.Exception, e: # NameClash appears as general fife.Exception; any ideas?
-			print e.getMessage()
-			print ''.join(['File: ', self.source, '. The map ', str(id), ' already exists! Ignoring map definition.'])
-			return None
+		except fife.Exception, e:
+			if is_fife_exc(fife.NameClash, e):
+				msg = e.getMessage()+" "
+				msg = msg + X+''.join(['File: ', self.source, '. The map ', str(id), ' already exists! Ignoring map definition.'])
+				logger.log(fife.LogManager.LEVEL_WARN, msg)
+				return None
+			raise
 
 		# xml-specific directory imports. This is used by xml savers.
 		self.map.importDirs = []
@@ -124,7 +128,7 @@
 
 			# Don't parse duplicate imports
 			if (dir,file) in parsedImports:
-				print "Duplicate import:" ,(dir,file)
+				logger.log(fife.LogManager.LEVEL_WARN, "Duplicate import:" + str((dir, file)))
 				continue
 			parsedImports[(dir,file)] = 1
 
@@ -136,7 +140,7 @@
 				loaders.loadImportDirRec(dir, self.engine)
 				map.importDirs.append(dir)
 			else:
-				print 'Empty import statement?'
+				logger.log(fife.LogManager.LEVEL_WARN, 'Empty import statement?')
 				
 			if self.callback:
 				i += 1				
@@ -187,7 +191,7 @@
 				layer_obj = map.createLayer(str(id), cellgrid)
 			except fife.Exception, e:
 				print e.getMessage()
-				print 'The layer ' + str(id) + ' already exists! Ignoring this layer.'
+				logger.log(fife.LogManager.LEVEL_WARN, 'The layer ' + str(id) + ' already exists! Ignoring this layer.')
 				continue
 
 			strgy = fife.CELL_EDGES_ONLY
@@ -238,7 +242,8 @@
 
 			object = self.model.getObject(str(objectID), str(nspace))
 			if not object:
-				print ''.join(['Object with id=', str(objectID), ' ns=', str(nspace), ' could not be found. Omitting...'])
+				msg = 'Object with id=' + str(objectID) + ' ns=' + str(nspace) + ' could not be found. Omitting...'
+				logger.log(fife.LogManager.LEVEL_WARN, msg)
 				continue
 
 			x = instance.get('x')
@@ -328,7 +333,7 @@
 				cam.setTilt(float(tilt))
 				cam.setZoom(float(zoom))
 			except fife.Exception, e:
-				print e.getMessage()
+				logger.log(fife.LogManager.LEVEL_WARN, "Error when parsing cameras: "+e.getMessage())
 				
 			if self.callback:
 				i += 1