From: Jeremy Stanley Date: Thu, 6 Nov 2014 01:41:56 +0000 (+0000) Subject: Log missing avatars X-Git-Tag: 0.0.1~225 X-Git-Url: https://mudpy.org/gitweb?a=commitdiff_plain;h=d9bc0e9251378f4b6eab0bd5537e0e9b0261a7bf;p=mudpy.git Log missing avatars If an avatar is missing, it's likely that it was created but not yet saved during a crash. This is usually safe to skip but could imply data corruption, so log the situation with a high log level. --- diff --git a/lib/mudpy/misc.py b/lib/mudpy/misc.py index 8e747dd..ead6f54 100644 --- a/lib/mudpy/misc.py +++ b/lib/mudpy/misc.py @@ -414,9 +414,13 @@ class Universe: # make a list of inactive avatars inactive_avatars = [] for account in self.categories["account"].values(): - inactive_avatars += [ - (self.contents[x]) for x in account.getlist("avatars") - ] + for avatar in account.get("avatars"): + try: + inactive_avatars.append(self.contents[avatar]) + except KeyError: + pending_loglines.append(( + "Missing avatar \"%s\", possible data corruption" % + avatar, 6)) for user in self.userlist: if user.avatar in inactive_avatars: inactive_avatars.remove(user.avatar) @@ -973,11 +977,14 @@ class User: def list_avatar_names(self): """List names of assigned avatars.""" - return [ - universe.contents[avatar].get( - "name" - ) for avatar in self.account.getlist("avatars") - ] + avatars = [] + for avatar in self.account.get("avatars"): + try: + avatars.append(universe.contents[avatar].get("name")) + except KeyError: + log("Missing avatar \"%s\", possible data corruption." % + avatar, 6) + return avatars def broadcast(message, add_prompt=True):