detect worlds in cwd, and print detected world paths

This commit is contained in:
Andrew Chin 2012-03-01 22:23:12 -05:00
parent a83518bc97
commit 6b5c421c9e
2 changed files with 23 additions and 16 deletions

View File

@ -428,9 +428,9 @@ def list_worlds():
# get max length of world name
worldNameLen = max([len(str(x)) for x in worlds] + [len("World")])
formatString = "%-" + str(worldNameLen) + "s | %-8s | %-8s | %-16s "
print formatString % ("World", "Size", "Playtime", "Modified")
print formatString % ("-"*worldNameLen, "-"*8, "-"*8, '-'*16)
formatString = "%-" + str(worldNameLen) + "s | %-8s | %-8s | %-16s | %s "
print formatString % ("World", "Size", "Playtime", "Modified", "Path")
print formatString % ("-"*worldNameLen, "-"*8, "-"*8, '-'*16, '-'*4)
for name, info in sorted(worlds.iteritems()):
if isinstance(name, basestring) and name.startswith("World") and len(name) == 6:
try:
@ -445,7 +445,8 @@ def list_worlds():
playtime = info['Time'] / 20
playstamp = '%d:%02d' % (playtime / 3600, playtime / 60 % 60)
size = "%.2fMB" % (info['SizeOnDisk'] / 1024. / 1024.)
print formatString % (name, size, playstamp, timestamp)
path = info['path']
print formatString % (name, size, playstamp, timestamp, path)
if __name__ == "__main__":
multiprocessing.freeze_support()

View File

@ -575,20 +575,26 @@ def get_worlds():
save_dir = get_save_dir()
# No dirs found - most likely not running from inside minecraft-dir
if save_dir is None:
return None
for dir in os.listdir(save_dir):
world_dat = os.path.join(save_dir, dir, "level.dat")
if not save_dir is None:
for dir in os.listdir(save_dir):
world_dat = os.path.join(save_dir, dir, "level.dat")
if not os.path.exists(world_dat): continue
info = nbt.load(world_dat)[1]
info['Data']['path'] = os.path.join(save_dir, dir)
if dir.startswith("World") and len(dir) == 6:
try:
world_n = int(dir[-1])
ret[world_n] = info['Data']
except ValueError:
pass
if 'LevelName' in info['Data'].keys():
ret[info['Data']['LevelName']] = info['Data']
for dir in os.listdir("."):
world_dat = os.path.join(dir, "level.dat")
if not os.path.exists(world_dat): continue
info = nbt.load(world_dat)[1]
info['Data']['path'] = os.path.join(save_dir, dir)
if dir.startswith("World") and len(dir) == 6:
try:
world_n = int(dir[-1])
ret[world_n] = info['Data']
except ValueError:
pass
info['Data']['path'] = os.path.join(".", dir)
if 'LevelName' in info['Data'].keys():
ret[info['Data']['LevelName']] = info['Data']