Compare commits

...

5 Commits

5 changed files with 245 additions and 151 deletions

View File

@ -5,6 +5,26 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/).
## [git] - 2020-02-29
(Poikilos)
### Added
- Support the `--backend` argument.
- Look for it in `get_db`.
- Support the `--colors` argument.
### Changed
- Change the `world_dir` argument to `-i` or `--input`.
- Allow `-o` as shorthand for `--output`
- No longer add `os.path.sep` to `args.input`
### Fixed
- Use `os.path.join`
- ...when looking for world.mt if `backend` is not
specified in minetestmapper-numpy.py.
- No longer add `os.path.sep` to `args.input` and other paths.
- Use `elif` with database formats to prevent overlaying converted
databases onto each other in minetestmapper-numpy.py.
## [git] - 2020-02-10
(Poikilos)
### Removed

194
minetestmapper-numpy.py Normal file → Executable file
View File

@ -47,15 +47,20 @@ except ImportError:
exit()
#
# wrapper around PIL 1.1.6 Image.save to preserve PNG metadata
#
# public domain, Nick Galbreath
# http://blog.client9.com/2007/08/28/python-pil-and-png-metadata-take-2.html
#
def join_as_str(delimiter, arr):
return delimiter.join(str(x) for x in arr)
def pngsave(im, file):
# these can be automatically added to Image.info dict
# they are not user-added metadata
"""
This is a wrapper around PIL 1.1.6 Image.save to preserve PNG
metadata.
CC0 Nick Galbreath
<http://blog.client9.com/2007/08/28/
python-pil-and-png-metadata-take-2.html>
These can be automatically added to Image.info dict.
They are not user-added metadata.
"""
reserved = ('interlace', 'gamma', 'dpi', 'transparency', 'aspect')
# undocumented class
@ -136,11 +141,14 @@ def int_to_hex4(i):
# return i
# else:
# return i + 2*max_positive
# def getBlockAsInteger(p):
# return signedToUnsigned(p[2],2048)*16777216
# + signedToUnsigned(p[1],2048)*4096
# + signedToUnsigned(p[0],2048)
def getBlockAsInteger(p):
return p[2]*16777216 + p[1]*4096 + p[0]
@ -226,6 +234,22 @@ def read_content(mapdata, version, datapos=None):
def parse_args():
# Pre-process geometry so argparse doesn't interpret negative as
# an option.
geometry = ''
i = 0
while i < len(sys.argv):
if sys.argv[i] == "--geometry":
del sys.argv[i]
geometry = None
elif geometry is None:
geometry = sys.argv[i]
del sys.argv[i]
else:
i += 1
i = None
ap = argparse.ArgumentParser(description='A mapper for minetest')
ap.add_argument('--bgcolor', default='black', metavar='COLOR',
type=ImageColor.getrgb,
@ -297,36 +321,45 @@ def parse_args():
help=('direction to face when drawing (north,'
' south, east or west will draw a'
' cross-section)'))
ap.add_argument('--geometry', type=str, default='',
help=('accepted for compatibility but'
' NOT YET IMPLEMENTED in this version'))
ap.add_argument('--geometry', type=geometry_to_ints, default=None,
action='store',
help=('Specify a region in X:Y+W+H format.'))
# ^ handle hyphen as negative number not option
# See:
# - <https://docs.python.org/3.2/library/
# argparse.html#arguments-containing>
# - <https://stackoverflow.com/questions/9025204/python-
# argparse-issue-with-optional-arguments-which-are-negative-
# numbers> (says to use action='store'--didn't work)
ap.add_argument('--scales', type=str, default='',
help=('accepted for compatibility but'
' NOT YET IMPLEMENTED in this version'))
ap.add_argument('--colors', type=str, default='colors.txt',
help=('accepted for compatibility but'
' NOT YET IMPLEMENTED in this version'))
ap.add_argument('--backend', type=str, choices=('leveldb'),
default='leveldb',
help=('accepted for compatibility but'
' NOT YET IMPLEMENTED in this version'))
help=('specify a colors list in colors.txt format'
'"80c 183 183 222 # CONTENT_GLASS"'
'or "default:stone 128 128 128")'))
ap.add_argument('--backend', type=str,
choices=('leveldb', 'sqlite3'), default='leveldb',
help=('manually specify leveldb or sqlite3'
' (others are NOT YET IMPLEMENTED)'))
ap.add_argument('--fog', type=float, metavar=('FOGSTRENGTH'),
default=0.0, help=('use fog strength of'
' FOGSTRENGTH (0.0 by'
' default, max of 1.0)'))
ap.add_argument('world_dir',
ap.add_argument('-i', '--input',
help='the path to the world you want to map')
ap.add_argument('output', nargs='?', default='map.png',
ap.add_argument('-o', '--output', nargs="?", default='map.png',
help='the output filename')
args = ap.parse_args()
if args.world_dir is None:
if args.input is None:
print("Please select world path (eg. -i ../worlds/yourworld)"
" (or use --help)")
sys.exit(1)
if not os.path.isdir(args.world_dir):
if not os.path.isdir(args.input):
print("World does not exist")
sys.exit(1)
args.world_dir = os.path.abspath(args.world_dir) + os.path.sep
args.input = os.path.abspath(args.input)
args.geometry = geometry
return args
@ -373,19 +406,21 @@ def load_colors(fname="colors.txt"):
def legacy_fetch_sector_data(args, sectortype, sector_data, ypos):
yhex = int_to_hex4(ypos)
if sectortype == "old":
ss_path = args.world_dir + "sectors/"
filename = ss_path + sector_data[0] + "/" + yhex.lower()
ss_path = os.path.join(args.input, "sectors")
filename = os.path.join(ss_path, sector_data[0], + yhex.lower())
else:
ss2_path = args.world_dir + "sectors2/"
filename = ss2_path + sector_data[1] + "/" + yhex.lower()
ss2_path = os.path.join(args.input, "sectors2")
filename = os.path.join(ss2_path, sector_data[1], yhex.lower())
return open(filename, "rb")
def legacy_sector_scan(args, sectors_xmin, sector_xmax, sector_zmin,
sector_zmax):
if os.path.exists(args.world_dir + "sectors2"):
for filename in os.listdir(args.world_dir + "sectors2"):
ss2_f_path = args.world_dir + "sectors2/" + filename
ss_path = os.path.join(args.input, "sectors")
ss2_path = os.path.join(args.input, "sectors2")
if os.path.exists(ss2_path):
for filename in os.listdir(ss2_path):
ss2_f_path = os.path.join(ss2_path, filename)
for filename2 in os.listdir(ss2_f_path):
x = hex_to_int(filename)
z = hex_to_int(filename2)
@ -395,9 +430,8 @@ def legacy_sector_scan(args, sectors_xmin, sector_xmax, sector_zmin,
continue
xlist.append(x)
zlist.append(z)
if os.path.exists(args.world_dir + "sectors"):
for filename in os.listdir(args.world_dir + "sectors"):
elif os.path.exists(ss_path):
for filename in os.listdir(ss_path):
x = hex4_to_int(filename[:4])
z = hex4_to_int(filename[-4:])
if x < sector_xmin or x > sector_xmax:
@ -416,13 +450,15 @@ def legacy_fetch_ylist(args, xpos, zpos, ylist):
zhex4 = int_to_hex4(zpos)
sector1 = xhex4.lower() + zhex4.lower()
sector2 = xhex.lower() + "/" + zhex.lower()
sector2 = os.path.join(xhex.lower(), zhex.lower())
ss_path = os.path.join(args.input, "sectors")
ss2_path = os.path.join(args.input, "sectors2")
try:
ss_s1_path = args.world_dir + "sectors/" + sector1
ss_s1_path = ss_path + sector1
for filename in os.listdir(ss_s1_path):
if(filename != "meta"):
if (filename != "meta"):
pos = int(filename, 16)
if(pos > 32767):
if (pos > 32767):
pos -= 65536
ylist.append(pos)
@ -431,11 +467,11 @@ def legacy_fetch_ylist(args, xpos, zpos, ylist):
if sectortype == "":
try:
ss2_s2_path = args.world_dir + "sectors2/" + sector2
ss2_s2_path = os.path.join(ss2_path, sector2)
for filename in os.listdir(ss2_s2_path):
if(filename != "meta"):
if (filename != "meta"):
pos = int(filename, 16)
if(pos > 32767):
if (pos > 32767):
pos -= 65536
ylist.append(pos)
sectortype = "new"
@ -548,20 +584,25 @@ def map_block_ug(mapdata, version, ypos, maxy, cdata, hdata, udata,
def get_db(args):
if not os.path.exists(args.world_dir+"world.mt"):
return None
with open(args.world_dir+"world.mt") as f:
keyvals = f.read().splitlines()
keyvals = [kv.split("=") for kv in keyvals]
backend = None
for k, v in keyvals:
if k.strip() == "backend":
backend = v.strip()
break
backend = args.backend
if args.backend is None:
# This should never happen.
print("* detecting db type from world.mt in "
"{}".format(args.input))
if not os.path.exists(os.path.join(args.input, "world.mt")):
return None
with open(os.path.join(args.input, "world.mt")) as f:
keyvals = f.read().splitlines()
keyvals = [kv.split("=") for kv in keyvals]
backend = None
for k, v in keyvals:
if k.strip() == "backend":
backend = v.strip()
break
if backend == "sqlite3":
return SQLDB(args.world_dir + "map.sqlite")
return SQLDB(os.path.join(args.input, "map.sqlite"))
if backend == "leveldb":
return LVLDB(args.world_dir + "map.db")
return LVLDB(os.path.join(args.input, "map.db"))
class SQLDB:
@ -574,9 +615,9 @@ class SQLDB:
self.cur.execute("SELECT `pos` FROM `blocks`")
while True:
r = self.cur.fetchone()
print(("getting int from first index of value "+str(r)))
if not r:
break
# print("getting int from first index of value " + str(r))
x, y, z = getIntegerAsBlock(r[0])
yield x, y, z, r[0]
@ -613,6 +654,19 @@ R_MSG = ("<(The following issue occurred while handling the exception"
" above) Could not finish writing r error since r was not"
" initialized>")
def geometry_to_ints(s):
"""Convert a string in the format X:Y+W+H to a 4-part tuple"""
chunks = s.split("+")
if len(chunks) != 3:
raise ValueError("Geometry must be in the format X:Y+W+H"
" not {}".format(s))
topleft = chunks[0].split(":")
if len(topleft) != 2:
raise ValueError("Geometry must be in the format X:Y+W+H"
" not {}".format(s))
return (int(topleft[0]), int(topleft[1]),
int(chunks[1]), int(chunks[2]))
class World:
def __init__(self, args):
@ -641,12 +695,15 @@ class World:
resulting picture.
'''
args = self.args
rect = args.region
if len(args.geometry) > 0:
rect = geometry_to_ints(args.geometry)
(
sector_xmin,
sector_xmax,
sector_zmin,
sector_zmax
) = numpy.array(args.region)/16
) = numpy.array(rect)/16
sector_ymin = args.minheight/16
sector_ymax = args.maxheight/16
xlist = []
@ -683,7 +740,7 @@ class World:
self.maxx = max(xlist)
self.maxz = max(zlist)
x0, x1, z0, z1 = numpy.array(args.region)
x0, x1, z0, z1 = numpy.array(rect)
y0 = args.minheight
y1 = args.maxheight
self.minypos = self.facing(int(x0), int(y0), int(z0))[1]
@ -1127,8 +1184,8 @@ def draw_image(world, uid_to_color):
ugstrength = (ugstrength - (ugstrength - 0.75)
* (ugstrength > 0.75))
ugstrength = ugstrength[:, :, numpy.newaxis]
print(('ugmin', stuff['undergroundh'].min()))
print(('ugmax', stuff['undergroundh'].max()))
print('ugmin', stuff['undergroundh'].min())
print('ugmax', stuff['undergroundh'].max())
ugdepth = (
1.0 * (stuff['undergroundh']-stuff['undergroundh'].min())
/ (stuff['undergroundh'].max()-stuff['undergroundh'].min())
@ -1296,8 +1353,9 @@ def draw_image(world, uid_to_color):
if args.drawplayers:
try:
for filename in os.listdir(args.world_dir + "players"):
f = open(args.world_dir + "players/" + filename)
players_path = os.path.join(args.input, "players")
for filename in os.listdir(players_path):
f = open(os.path.join(players_path, filename))
lines = f.readlines()
name = ""
position = []
@ -1305,10 +1363,10 @@ def draw_image(world, uid_to_color):
p = line.split()
if p[0] == "name":
name = p[2]
print((filename + ": name = " + name))
print(filename + ": name = " + name)
if p[0] == "position":
position = p[2][1:-1].split(",")
print((filename + ": position = " + p[2]))
print(filename + ": position = " + p[2])
if len(name) < 0 and len(position) == 3:
x, y, z = [int(float(p)/10) for p in position]
x, y, z = world.facing(x, y, z)
@ -1347,16 +1405,16 @@ def draw_image(world, uid_to_color):
pngmaxz = maxz*16+16
pngregion = [pngminx, pngmaxx, pngminz, pngmaxz]
print(("Saving to: " + args.output))
print(("PNG Region: ", pngregion))
print(("pngMinX: ", str(pngminx)))
print(("pngMaxZ: ", str(pngmaxz)))
print(("Pixels PerNode: ", args.pixelspernode))
print(("border: ", border))
print("Saving to: " + args.output)
print("PNG Region: ", pngregion)
print("pngMinX: ", str(pngminx))
print("pngMaxZ: ", str(pngmaxz))
print("Pixels PerNode: ", args.pixelspernode)
print("border: ", border)
# This saves data in tEXt chunks (non-standard naming tags are
# allowed according to the PNG specification)
im.info["pngRegion"] = ",".join(pngregion)
im.info["pngRegion"] = join_as_str(",", pngregion)
im.info["pngMinX"] = str(pngminx)
im.info["pngMaxZ"] = str(pngmaxz)
im.info["border"] = str(border)
@ -1392,7 +1450,7 @@ def draw_image(world, uid_to_color):
def main():
args = parse_args()
uid_to_color, str_to_uid = load_colors()
uid_to_color, str_to_uid = load_colors(fname=args.colors)
world = World(args)

123
minetestmapper.py Normal file → Executable file
View File

@ -148,6 +148,13 @@ def readS32(f):
ord(f.read(1)), 2**31)
colors_msg = """<color> format: '#000000'
NOTE: colors.txt must be in same directory as
this script or in the current working
directory (or util directory if installed).
Otherwise, use the --colors option followed by a path.
"""
usagetext = """minetestmapper.py [options]
-i/--input <world_path>
-o/--output <output_image.png>
@ -161,10 +168,8 @@ usagetext = """minetestmapper.py [options]
--region <xmin>:<xmax>,<zmin>:<zmax>
--geometry <xmin>:<zmin>+<width>+<height>
--drawunderground
Color format: '#000000'
NOTE: colors.txt must be in same directory as
this script or in the current working
directory (or util directory if installed).
--colors <path to colors.txt>
--backend <sqlite3> (other db formats are NOT YET IMPLEMENTED)
"""
@ -179,10 +184,10 @@ try:
"bgcolor=", "scalecolor=", "origincolor=",
"playercolor=", "draworigin", "drawplayers",
"drawscale", "drawunderground", "geometry=",
"region="])
"region=", "colors=", "backend="])
except getopt.GetoptError as err:
# print help information and exit:
print((str(err))) # will print something like "option -a not recognized"
print(str(err)) # something like "option -a not recognized"
usage()
sys.exit(2)
@ -199,6 +204,7 @@ draworigin = False
drawunderground = False
geometry_string = None
region_string = None
colors_path = None
for o, a in opts:
if o in ("-h", "--help"):
@ -229,22 +235,22 @@ for o, a in opts:
geometry_string = a
elif o == "--region":
region_string = a
elif o == "--drawalpha":
print(("# ignored (NOT YET IMPLEMENTED) " + o))
elif o == "--noshading":
print(("# ignored (NOT YET IMPLEMENTED) " + o))
elif o == "--min-y":
print(("# ignored (NOT YET IMPLEMENTED) " + o))
elif o == "--max-y":
print(("# ignored (NOT YET IMPLEMENTED) " + o))
elif o == "--backend":
print(("# ignored (NOT YET IMPLEMENTED) " + o))
elif o == "--zoom":
print(("# ignored (NOT YET IMPLEMENTED) " + o))
elif o == "--colors":
print(("# ignored (NOT YET IMPLEMENTED) " + o))
colors_path = a
elif o == "--drawalpha":
print("# ignored (NOT YET IMPLEMENTED) " + o)
elif o == "--noshading":
print("# ignored (NOT YET IMPLEMENTED) " + o)
elif o == "--min-y":
print("# ignored (NOT YET IMPLEMENTED) " + o)
elif o == "--max-y":
print("# ignored (NOT YET IMPLEMENTED) " + o)
elif o == "--backend":
print("# ignored (NOT YET IMPLEMENTED) " + o)
elif o == "--zoom":
print("# ignored (NOT YET IMPLEMENTED) " + o)
elif o == "--scales":
print(("# ignored (NOT YET IMPLEMENTED) " + o))
print("# ignored (NOT YET IMPLEMENTED) " + o)
else:
assert False, "unhandled option"
@ -277,13 +283,14 @@ if geometry_string is not None:
+ " zmin:" + str(nonchunky_zmin) + "\n"
+ " zmax:" + str(nonchunky_zmax))
else:
print(("ERROR: Missing coordinates in '" + geometry_string +
"' for geometry (must be in the form: x:z+width+height)"))
print("ERROR: Missing coordinates in '" + geometry_string
+ "' for geometry (must be in the form:"
+ " x:z+width+height)")
usage()
sys.exit(2)
else:
print(("ERROR: Incorrect geometry syntax '" + geometry_string +
"' (must be in the form: x:z+width+height)"))
print("ERROR: Incorrect geometry syntax '" + geometry_string
+ "' (must be in the form: x:z+width+height)")
usage()
sys.exit(2)
elif region_string is not None:
@ -304,8 +311,9 @@ elif region_string is not None:
+ " zmin:" + str(nonchunky_zmin) + "\n"
+ " zmax:" + str(nonchunky_zmax))
else:
print(("ERROR: Incorrect value '" + region_string +
"' for region (must be in the form: xmin:xmax,zmin:zmax)"))
print("ERROR: Incorrect value '" + region_string
+ "' for region (must be in the form:"
+ " xmin:xmax,zmin:zmax)")
usage()
sys.exit(2)
@ -323,7 +331,7 @@ if path[-1:] != "/" and path[-1:] != "\\":
# Load color information for the blocks.
colors = {}
colors_path = "colors.txt"
colors_name = "colors.txt"
profile_path = None
if 'HOME' in os.environ:
@ -333,24 +341,27 @@ elif 'USERPROFILE' in os.environ:
mt_path = None
mt_util_path = None
abs_colors_path = None
if not os.path.isfile(colors_path):
colors_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"colors.txt")
try_dot_mt_path = os.path.join(profile_path, ".minetest")
mt_path = os.path.join(profile_path, "minetest")
mt_util_path = os.path.join(mt_path, "util")
if not os.path.isfile(colors_path):
if profile_path is not None:
try_path = os.path.join(profile_path, "minetest")
if os.path.isdir(try_path):
mt_path = try_path
mt_util_path = os.path.join(mt_path, "util")
abs_colors_path = os.path.join(mt_util_path, "colors.txt")
if os.path.isfile(abs_colors_path):
colors_path = abs_colors_path
if colors_path is None:
try_paths = []
try_paths.append(try_dot_mt_path, colors_name)
try_paths.append(
os.path.join(os.path.dirname(os.path.abspath(__file__)),
colors_name)
)
try_paths.append(mt_path, colors_name)
try_paths.append(mt_util_path, colors_name)
for try_path in try_paths:
if os.path.isfile(try_path):
colos_path = try_path
break
if not os.path.isfile(colors_path):
print("ERROR: could not find colors.txt")
if (colors_path is None) or (not os.path.isfile(colors_path)):
print("ERROR: could not find {}".format(colors_name))
usage()
sys.exit(1)
@ -358,7 +369,7 @@ try:
f = open(colors_path)
except IOError:
f = open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"colors.txt"))
colors_name))
for line in f:
values = line.split()
if len(values) < 4:
@ -392,6 +403,8 @@ zlist = []
conn = None
cur = None
look_for_names = ["map.sqlite", "sectors2", "sectors"]
look_for_paths = [os.path.join(path, x) for x in look_for_names]
if os.path.exists(path + "map.sqlite"):
import sqlite3
conn = sqlite3.connect(path + "map.sqlite")
@ -412,8 +425,7 @@ if os.path.exists(path + "map.sqlite"):
xlist.append(x)
zlist.append(z)
if os.path.exists(path + "sectors2"):
elif os.path.exists(path + "sectors2"):
for filename in os.listdir(path + "sectors2"):
for filename2 in os.listdir(path + "sectors2/" + filename):
x = hex_to_int(filename)
@ -424,8 +436,7 @@ if os.path.exists(path + "sectors2"):
continue
xlist.append(x)
zlist.append(z)
if os.path.exists(path + "sectors"):
elif os.path.exists(path + "sectors"):
for filename in os.listdir(path + "sectors"):
x = hex4_to_int(filename[:4])
z = hex4_to_int(filename[-4:])
@ -437,7 +448,8 @@ if os.path.exists(path + "sectors"):
zlist.append(z)
if len(xlist) == 0 or len(zlist) == 0:
print("Data does not exist at this location.")
print("A compatible database was not found ({})."
"".format(look_for_paths))
sys.exit(1)
# Get rid of doubles
@ -451,8 +463,8 @@ maxz = max(zlist)
w = (maxx - minx) * 16 + 16
h = (maxz - minz) * 16 + 16
print(("Result image (w=" + str(w) + " h=" + str(h) + ") will be written to " +
output))
print("Result image (w=" + str(w) + " h=" + str(h)
+ ") will be written to " + output)
im = Image.new("RGB", (w + border, h + border), bgcolor)
draw = ImageDraw.Draw(im)
@ -501,8 +513,8 @@ def read_mapdata(mapdata, version, pixellist, water, day_night_differs,
global unknown_node_ids
if(len(mapdata) < 4096):
print(("bad: " + xhex + "/" + zhex + "/" + yhex + " " +
str(len(mapdata))))
print("bad: " + xhex + "/" + zhex + "/" + yhex + " " +
str(len(mapdata)))
else:
chunkxpos = xpos * 16
chunkypos = ypos * 16
@ -701,7 +713,8 @@ for n in range(len(xlist)):
# zlib-compressed node metadata list
dec_o = zlib.decompressobj()
try:
metaliststr = array.array("B", dec_o.decompress(f.read()))
metaliststr = array.array("B",
dec_o.decompress(f.read()))
# And do nothing with it
except:
metaliststr = []
@ -966,10 +979,10 @@ if drawplayers:
p = line.split()
if p[0] == "name":
name = p[2]
print((filename + ": name = " + name))
print(filename + ": name = " + name)
if p[0] == "position":
position = p[2][1:-1].split(",")
print((filename + ": position = " + p[2]))
print(filename + ": position = " + p[2])
if len(name) > 0 and len(position) == 3:
x = (int(float(position[0]) / 10 - minx * 16))
z = int(h - (float(position[2]) / 10 - minz * 16))

View File

@ -1,31 +1,34 @@
#!/bin/sh
if [ ! -f "`command -v pycodestyle-3`" ]; then
echo "You must install the python3-pycodestyle package before using the quality script."
exit 1
echo "You must install the python3-pycodestyle package before using the quality script."
exit 1
fi
target="minetestmapper-numpy.py"
# target="__init__.py"
# if [ ! -z "$1" ]; then
# target="$1"
# target="$1"
# fi
if [ -f err.txt ]; then
rm err.txt
fi
if [ -f "`command -v outputinspector`" ]; then
pycodestyle-3 "minetestmapper.py" > err.txt
pycodestyle-3 "$target" >> err.txt
# For one-liner, would use `||` not `&&`, because pycodestyle-3 returns nonzero (error state) if there are any errors
if [ -s "err.txt" ]; then
outputinspector
else
echo "No quality issues were detected."
rm err.txt
# echo "Deleted empty 'err.txt'."
fi
else
pycodestyle-3 "minetestmapper.py"
pycodestyle-3 "$target"
echo
echo "If you install outputinspector, this output can be examined automatically, allowing double-click to skip to line in Geany/Kate"
echo
fi
ext="py"
if [ -f "`command -v outputinspector`" ]; then
for f in *.$ext; do
pycodestyle-3 "$f" >> err.txt
done
# For one-liner, would use `||` not `&&`, because pycodestyle-3 returns nonzero (error state) if there are any errors
if [ -s "err.txt" ]; then
# -s: exists and >0 bytes
outputinspector
else
echo "No quality issues were detected."
rm err.txt
# echo "Deleted empty 'err.txt'."
fi
else
for f in *.$ext; do
pycodestyle-3 "$f" >> err.txt
done
echo
echo "If you install outputinspector, this output can be examined automatically, allowing double-click to skip to line in Geany/Kate"
echo
fi

View File

@ -76,7 +76,7 @@ def getSectorPos(dirname):
x = parseSigned12bit(dirname[:3])
z = parseSigned12bit(dirname[4:])
else:
print(('Terrible sector at ' + dirname))
print('Terrible sector at ' + dirname)
return
return x, z
@ -89,7 +89,7 @@ def getBlockPos(sectordir, blockfile):
return
if len(blockfile) != 4:
print(("Invalid block filename: " + blockfile))
print("Invalid block filename: " + blockfile)
y = parseSigned16bit(blockfile)
@ -115,7 +115,7 @@ cur = conn.cursor()
if create:
cur.execute("CREATE TABLE IF NOT EXISTS `blocks` (`pos` INT NOT NULL PRIMARY KEY, `data` BLOB);")
conn.commit()
print(('Created database at ' + path + 'map.sqlite'))
print('Created database at ' + path + 'map.sqlite')
# Crawl the folders
@ -128,7 +128,7 @@ for base in paths:
elif base == 'sectors2':
v= 2
else:
print(('Ignoring base ' + base))
print('Ignoring base ' + base)
continue
for root, dirs, files in os.walk(path + base):
@ -137,7 +137,7 @@ for base in paths:
pos = getBlockAsInteger(getBlockPos(root[(-8 if v == 1 else -7 if v == 2 else 0):], block))
if pos is None:
print(('Ignoring broken path ' + root + '/' + block))
print('Ignoring broken path ' + root + '/' + block)
continue
f = open(root+'/'+block, 'rb')
@ -152,7 +152,7 @@ for base in paths:
if(time.time() - t > 3):
t = time.time()
print((str(count)+' blocks processed...'))
print(str(count)+' blocks processed...')
conn.commit()