From b40d84f92be235af67e10974afb4decd326048b4 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Wed, 23 Feb 2011 13:07:21 -0500 Subject: [PATCH] fixed crash on worlds named "World[not int]", and made world list play nice with world names --- gmap.py | 12 ++++++++++-- world.py | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gmap.py b/gmap.py index 6e528bf..acfacb1 100755 --- a/gmap.py +++ b/gmap.py @@ -183,13 +183,21 @@ def list_worlds(): print 'No world saves found in the usual place' return print "Detected saves:" - for num, info in sorted(worlds.iteritems()): + for name, info in sorted(worlds.iteritems()): + if isinstance(name, basestring) and name.startswith("World") and len(name) == 6: + try: + world_n = int(name[-1]) + # we'll catch this one later, when it shows up as an + # integer key + continue + except ValueError: + pass timestamp = time.strftime("%Y-%m-%d %H:%M", time.localtime(info['LastPlayed'] / 1000)) playtime = info['Time'] / 20 playstamp = '%d:%02d' % (playtime / 3600, playtime / 60 % 60) size = "%.2fMB" % (info['SizeOnDisk'] / 1024. / 1024.) - print "World %s: %s Playtime: %s Modified: %s" % (num, size, playstamp, timestamp) + print "World %s: %s Playtime: %s Modified: %s" % (name, size, playstamp, timestamp) if __name__ == "__main__": diff --git a/world.py b/world.py index 5df6a9a..b821651 100644 --- a/world.py +++ b/world.py @@ -406,8 +406,11 @@ def get_worlds(): info = nbt.load(world_dat)[1] info['Data']['path'] = os.path.join(save_dir, dir) if dir.startswith("World") and len(dir) == 6: - world_n = int(dir[-1]) - ret[world_n] = info['Data'] + 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']