Added ctrl-c handling, output is a single line (verbose reports what error occured), added optparsing, supports multipule files or a dir
This commit is contained in:
@@ -1,12 +1,9 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
usage = "python contrib/%prog [OPTIONS] <regionfilename>"
|
usage = "python contrib/%prog [OPTIONS] (<regionfilename>)*"
|
||||||
|
|
||||||
description = """
|
description = """
|
||||||
This script will delete files from the old chunk-based cache, a lot
|
This script will valide a minecraft region file for errors
|
||||||
like the old `gmap.py -d World/` command. You should only use this if
|
|
||||||
you're updating from an older version of Overviewer, and you want to
|
|
||||||
clean up your world folder.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
@@ -21,56 +18,74 @@ sys.path.insert(0, overviewer_dir)
|
|||||||
|
|
||||||
import nbt
|
import nbt
|
||||||
import chunk
|
import chunk
|
||||||
|
import quadtree
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = OptionParser(usage=usage, description=description)
|
parser = OptionParser(usage=usage, description=description)
|
||||||
# parser.add_option("-d", "--dry-run", dest="dry", action="store_true",
|
parser.add_option("-r", "--regions", dest="regiondir", help="Use path to the regions instead of a list of files")
|
||||||
# help="Don't actually delete anything. Best used with -v.")
|
parser.add_option("-v", dest="verbose", action="store_true", help="Lists why a chunk in a region failed")
|
||||||
|
|
||||||
opt, args = parser.parse_args()
|
opt, args = parser.parse_args()
|
||||||
|
|
||||||
if not len(args) == 1:
|
if opt.regiondir:
|
||||||
|
if os.path.exists(opt.regiondir):
|
||||||
|
for dirpath, dirnames, filenames in os.walk(opt.regiondir, 'region'):
|
||||||
|
if not dirnames and filenames and "DIM-1" not in dirpath:
|
||||||
|
for f in filenames:
|
||||||
|
if f.startswith("r.") and f.endswith(".mcr"):
|
||||||
|
p = f.split(".")
|
||||||
|
args.append(os.path.join(dirpath, f))
|
||||||
|
|
||||||
|
if len(args) < 1:
|
||||||
|
print "You must list at least one region file"
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
regionfile = args[0]
|
for regionfile in args:
|
||||||
|
_,shortname = os.path.split(regionfile)
|
||||||
if not os.path.exists(regionfile):
|
|
||||||
parser.print_help()
|
|
||||||
print "\nFile not found"
|
|
||||||
sys.exit(1)
|
|
||||||
chunk_pass = 0
|
chunk_pass = 0
|
||||||
chunk_total = 0
|
chunk_total = 0
|
||||||
print( "Loading region: %s" % ( regionfile))
|
if not os.path.exists(regionfile):
|
||||||
|
print("Region:%s Passed %s/%s"%(shortname,chunk_pass,chunk_total))
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
mcr = nbt.load_region(regionfile)
|
mcr = nbt.load_region(regionfile)
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
|
if options.verbose:
|
||||||
print("Error opening regionfile. It may be corrupt. %s"%( e))
|
print("Error opening regionfile. It may be corrupt. %s"%( e))
|
||||||
pass
|
|
||||||
if mcr is not None:
|
if mcr is not None:
|
||||||
try:
|
try:
|
||||||
chunks = mcr.get_chunk_info(False)
|
chunks = mcr.get_chunk_info(False)
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
|
if options.verbose:
|
||||||
print("Error opening regionfile(bad header info). It may be corrupt. %s"%( e))
|
print("Error opening regionfile(bad header info). It may be corrupt. %s"%( e))
|
||||||
chunks = []
|
chunks = []
|
||||||
pass
|
|
||||||
for x, y in chunks:
|
for x, y in chunks:
|
||||||
chunk_total += 1
|
chunk_total += 1
|
||||||
#try:
|
#try:
|
||||||
chunk_data = mcr.load_chunk(x, y)
|
chunk_data = mcr.load_chunk(x, y)
|
||||||
if chunk_data is None:
|
if chunk_data is None:
|
||||||
|
if options.verbose:
|
||||||
print("Chunk %s:%s is unexpectedly empty"%(x, y))
|
print("Chunk %s:%s is unexpectedly empty"%(x, y))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
processed = chunk_data.read_all()
|
processed = chunk_data.read_all()
|
||||||
if processed == []:
|
if processed == []:
|
||||||
|
if options.verbose:
|
||||||
print("Chunk %s:%s is an unexpectedly empty set"%(x, y))
|
print("Chunk %s:%s is an unexpectedly empty set"%(x, y))
|
||||||
else:
|
else:
|
||||||
chunk_pass += 1
|
chunk_pass += 1
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
if options.verbose:
|
||||||
print("Error opening chunk (%i, %i) It may be corrupt. %s"%( x, y, e))
|
print("Error opening chunk (%i, %i) It may be corrupt. %s"%( x, y, e))
|
||||||
else:
|
else:
|
||||||
|
if options.verbose:
|
||||||
print("Error opening regionfile.")
|
print("Error opening regionfile.")
|
||||||
print("Done; Passed %s/%s"%(chunk_pass,chunk_total))
|
|
||||||
|
print("Region:%s Passed %s/%s"%(shortname,chunk_pass,chunk_total))
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
main()
|
main()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print "Caught Ctrl-C"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user