Permalink
Browse files

Refactor: Change log statements to use `log.info()` instead of `info=…

…log.info; info()`
  • Loading branch information...
codewarrior0 committed Oct 31, 2012
1 parent ecac4fa commit 35bbbdc576043420ba55bc75bfd76e5e032bb5f6
Showing with 38 additions and 48 deletions.
  1. +3 −4 indev.py
  2. +4 −6 java.py
  3. +4 −6 level.py
  4. +9 −10 materials.py
  5. +13 −15 mclevel.py
  6. +0 −1 mclevelbase.py
  7. +4 −5 schematic.py
  8. +1 −1 test/schematic_test.py
View
@@ -68,7 +68,6 @@
import os
log = getLogger(__name__)
-warn, error, info, debug = log.warn, log.error, log.info, log.debug
MinecraftLevel = "MinecraftLevel"
@@ -215,7 +214,7 @@ def numbersToDoubles(ent):
self.LocalPlayer = localPlayerList[0]
else:
- info(u"Creating new Indev levels is not yet implemented.!")
+ log.info(u"Creating new Indev levels is not yet implemented.!")
raise ValueError("Can't do that yet")
# self.SurroundingGroundHeight = root_tag[Environment][SurroundingGroundHeight].value
# self.SurroundingGroundType = root_tag[Environment][SurroundingGroundType].value
@@ -244,7 +243,7 @@ def rotateLeft(self):
8, 9, 10, 11, 12, 13, 14, 15])
torchIndexes = (self.Blocks == self.materials.Torch.ID)
- info(u"Rotating torches: {0}".format(len(torchIndexes.nonzero()[0])))
+ log.info(u"Rotating torches: {0}".format(len(torchIndexes.nonzero()[0])))
self.Data[torchIndexes] = torchRotation[self.Data[torchIndexes]]
def decodePos(self, v):
@@ -260,7 +259,7 @@ def saveToFile(self, filename=None):
if filename is None:
filename = self.filename
if filename is None:
- warn(u"Attempted to save an unnamed file in place")
+ log.warn(u"Attempted to save an unnamed file in place")
return # you fool!
self.Data <<= 4
View
10 java.py
@@ -15,8 +15,6 @@
import re
log = getLogger(__name__)
-warn, error, info, debug = log.warn, log.error, log.info, log.debug
-
class MCJavaLevel(MCLevel):
def setBlockDataAt(self, *args):
@@ -42,7 +40,7 @@ def guessSize(self, data):
Length = 64
Height = 64
if data.shape[0] <= (32 * 32 * 64) * 2:
- warn(u"Can't guess the size of a {0} byte level".format(data.shape[0]))
+ log.warn(u"Can't guess the size of a {0} byte level".format(data.shape[0]))
raise IOError("MCJavaLevel attempted for smaller than 64 blocks cubed")
if data.shape[0] > (64 * 64 * 64) * 2:
Width = 128
@@ -80,12 +78,12 @@ def __init__(self, filename, data):
if r and len(r) >= 3:
(w, l, h) = map(int, r[-3:])
if w * l * h > data.shape[0]:
- info("Not enough blocks for size " + str((w, l, h)))
+ log.info("Not enough blocks for size " + str((w, l, h)))
w, l, h = self.guessSize(data)
else:
w, l, h = self.guessSize(data)
- info(u"MCJavaLevel created for potential level of size " + str((w, l, h)))
+ log.info(u"MCJavaLevel created for potential level of size " + str((w, l, h)))
blockCount = h * l * w
if blockCount > data.shape[0]:
@@ -131,7 +129,7 @@ def saveInPlace(self):
with open(self.filename, 'wb') as f:
f.write(s.getvalue())
except Exception, e:
- info(u"Error while saving java level in place: {0}".format(e))
+ log.info(u"Error while saving java level in place: {0}".format(e))
try:
os.remove(self.filename)
except:
View
@@ -18,8 +18,6 @@
import os.path
log = getLogger(__name__)
-warn, error, info, debug = log.warn, log.error, log.info, log.debug
-
def computeChunkHeightMap(materials, blocks, HeightMap=None):
"""Computes the HeightMap array for a chunk, which stores the lowest
@@ -276,7 +274,7 @@ def getAllChunkSlices(self):
def _getSlices(self, box):
if box == self.bounds:
- info("All chunks selected! Selecting %s chunks instead of %s", self.chunkCount, box.chunkCount)
+ log.info("All chunks selected! Selecting %s chunks instead of %s", self.chunkCount, box.chunkCount)
y = box.miny
slices = slice(0, 16), slice(0, 16), slice(0, box.maxy)
@@ -447,7 +445,7 @@ def removeEntitiesInBox(self, box):
newEnts.append(ent)
entsRemoved = len(self.Entities) - len(newEnts)
- debug("Removed {0} entities".format(entsRemoved))
+ log.debug("Removed {0} entities".format(entsRemoved))
self.Entities.value[:] = newEnts
@@ -464,7 +462,7 @@ def removeTileEntitiesInBox(self, box):
newEnts.append(ent)
entsRemoved = len(self.TileEntities) - len(newEnts)
- debug("Removed {0} tile entities".format(entsRemoved))
+ log.debug("Removed {0} tile entities".format(entsRemoved))
self.TileEntities.value[:] = newEnts
@@ -486,7 +484,7 @@ def tileEntityAt(self, x, y, z):
entities.append(entityTag)
if len(entities) > 1:
- info("Multiple tile entities found: {0}".format(entities))
+ log.info("Multiple tile entities found: {0}".format(entities))
if len(entities) == 0:
return None
View
@@ -13,7 +13,6 @@
import yaml
log = getLogger(__file__)
-debug, info, warn, error, critical = log.debug, log.info, log.warn, log.error, log.critical
class Block(object):
@@ -162,12 +161,12 @@ def addYamlBlocksFromFile(self, filename):
f = file(path)
try:
- info(u"Loading block info from %s", f)
+ log.info(u"Loading block info from %s", f)
blockyaml = yaml.load(f)
self.addYamlBlocks(blockyaml)
except Exception, e:
- warn(u"Exception while loading block info from %s: %s", f, e)
+ log.warn(u"Exception while loading block info from %s: %s", f, e)
traceback.print_exc()
def addYamlBlocks(self, blockyaml):
@@ -176,9 +175,9 @@ def addYamlBlocks(self, blockyaml):
try:
self.addYamlBlock(block)
except Exception, e:
- warn(u"Exception while parsing block: %s", e)
+ log.warn(u"Exception while parsing block: %s", e)
traceback.print_exc()
- warn(u"Block definition: \n%s", pformat(block))
+ log.warn(u"Block definition: \n%s", pformat(block))
def addYamlBlock(self, kw):
blockID = kw['id']
@@ -819,13 +818,13 @@ def conversionFunc(destMats, sourceMats):
return func
filters, unavailable = guessFilterTable(sourceMats, destMats)
- debug("")
- debug("%s %s %s", sourceMats.name, "=>", destMats.name)
+ log.debug("")
+ log.debug("%s %s %s", sourceMats.name, "=>", destMats.name)
for a, b in [(sourceMats.blockWithID(*a), destMats.blockWithID(*b)) for a, b in filters]:
- debug("{0:20}: \"{1}\"".format('"' + a.name + '"', b.name))
+ log.debug("{0:20}: \"{1}\"".format('"' + a.name + '"', b.name))
- debug("")
- debug("Missing blocks: %s", [sourceMats.blockWithID(*a).name for a in unavailable])
+ log.debug("")
+ log.debug("Missing blocks: %s", [sourceMats.blockWithID(*a).name for a in unavailable])
table = _filterTable(filters, unavailable, (35, 0))
func = filterConversion(table)
View
@@ -184,8 +184,6 @@ def fillBlocks(self, box, blockType, blockData = 0):
import traceback
log = getLogger(__name__)
-warn, error, info, debug = log.warn, log.error, log.info, log.debug
-
class LoadingError(RuntimeError):
pass
@@ -195,24 +193,24 @@ def fromFile(filename, loadInfinite=True):
''' The preferred method for loading Minecraft levels of any type.
pass False to loadInfinite if you'd rather not load infdev levels.
'''
- info(u"Identifying " + filename)
+ log.info(u"Identifying " + filename)
if not filename:
raise IOError("File not found: " + filename)
if not os.path.exists(filename):
raise IOError("File not found: " + filename)
if ZipSchematic._isLevel(filename):
- info("Zipfile found, attempting zipped infinite level")
+ log.info("Zipfile found, attempting zipped infinite level")
lev = ZipSchematic(filename)
- info("Detected zipped Infdev level")
+ log.info("Detected zipped Infdev level")
return lev
if PocketWorld._isLevel(filename):
return PocketWorld(filename)
if MCInfdevOldLevel._isLevel(filename):
- info(u"Detected Infdev level.dat")
+ log.info(u"Detected Infdev level.dat")
if loadInfinite:
return MCInfdevOldLevel(filename=filename)
else:
@@ -232,7 +230,7 @@ def fromFile(filename, loadInfinite=True):
raise ValueError("{0} contains only zeroes. This file is damaged beyond repair.")
if MCJavaLevel._isDataLevel(data):
- info(u"Detected Java-style level")
+ log.info(u"Detected Java-style level")
lev = MCJavaLevel(filename, data)
lev.compressed = False
return lev
@@ -243,15 +241,15 @@ def fromFile(filename, loadInfinite=True):
try:
unzippedData = nbt.gunzip(rawdata)
except Exception, e:
- info(u"Exception during Gzip operation, assuming {0} uncompressed: {1!r}".format(filename, e))
+ log.info(u"Exception during Gzip operation, assuming {0} uncompressed: {1!r}".format(filename, e))
if unzippedData is None:
compressed = False
unzippedData = rawdata
#data =
data = unzippedData
if MCJavaLevel._isDataLevel(data):
- info(u"Detected compressed Java-style level")
+ log.info(u"Detected compressed Java-style level")
lev = MCJavaLevel(filename, data)
lev.compressed = compressed
return lev
@@ -260,9 +258,9 @@ def fromFile(filename, loadInfinite=True):
root_tag = nbt.load(buf=data)
except Exception, e:
- info(u"Error during NBT load: {0!r}".format(e))
- info(traceback.format_exc())
- info(u"Fallback: Detected compressed flat block array, yzx ordered ")
+ log.info(u"Error during NBT load: {0!r}".format(e))
+ log.info(traceback.format_exc())
+ log.info(u"Fallback: Detected compressed flat block array, yzx ordered ")
try:
lev = MCJavaLevel(filename, data)
lev.compressed = compressed
@@ -272,14 +270,14 @@ def fromFile(filename, loadInfinite=True):
else:
if MCIndevLevel._isTagLevel(root_tag):
- info(u"Detected Indev .mclevel")
+ log.info(u"Detected Indev .mclevel")
return MCIndevLevel(root_tag, filename)
if MCSchematic._isTagLevel(root_tag):
- info(u"Detected Schematic.")
+ log.info(u"Detected Schematic.")
return MCSchematic(root_tag=root_tag, filename=filename)
if INVEditChest._isTagLevel(root_tag):
- info(u"Detected INVEdit inventory file")
+ log.info(u"Detected INVEdit inventory file")
return INVEditChest(root_tag=root_tag, filename=filename)
raise IOError("Cannot detect file type.")
View
@@ -9,7 +9,6 @@
import os
log = getLogger(__name__)
-warn, error, info, debug = log.warn, log.error, log.info, log.debug
@contextmanager
def notclosing(f):
View
@@ -20,7 +20,6 @@
from numpy import array, swapaxes, uint8, zeros
log = getLogger(__name__)
-warn, error, info, debug = log.warn, log.error, log.info, log.debug
__all__ = ['MCSchematic', 'INVEditChest']
@@ -181,7 +180,7 @@ def rotateLeft(self):
blockrotation.RotateLeft(self.Blocks, self.Data)
- info(u"Relocating entities...")
+ log.info(u"Relocating entities...")
for entity in self.Entities:
for p in "Pos", "Motion":
if p == "Pos":
@@ -231,7 +230,7 @@ def flipNorthSouth(self):
northSouthPaintingMap = [0, 3, 2, 1]
- info(u"N/S Flip: Relocating entities...")
+ log.info(u"N/S Flip: Relocating entities...")
for entity in self.Entities:
entity["Pos"][0].value = self.Width - entity["Pos"][0].value
@@ -257,7 +256,7 @@ def flipEastWest(self):
eastWestPaintingMap = [2, 1, 0, 3]
- info(u"E/W Flip: Relocating entities...")
+ log.info(u"E/W Flip: Relocating entities...")
for entity in self.Entities:
entity["Pos"][2].value = self.Length - entity["Pos"][2].value
@@ -340,7 +339,7 @@ def __init__(self, root_tag, filename):
try:
root_tag = nbt.load(filename)
except IOError, e:
- info(u"Failed to load file {0}".format(e))
+ log.info(u"Failed to load file {0}".format(e))
raise
else:
assert root_tag, "Must have either root_tag or filename"
View
@@ -15,7 +15,7 @@ def setUp(self):
self.anvilLevel = TempLevel("AnvilWorld")
def testCreate(self):
- # info("Schematic from indev")
+ # log.info("Schematic from indev")
size = (64, 64, 64)
temp = mktemp("testcreate.schematic")

0 comments on commit 35bbbdc

Please sign in to comment.