From 8b4a4e2afe2e7b452b0e04683592d9c7bf677eca Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 22 May 2006 13:30:13 -0400 Subject: [PATCH] Ensure buddy icon is at least None; if the sugar directory doesn't exist, make it. --- sugar/p2p/Buddy.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sugar/p2p/Buddy.py b/sugar/p2p/Buddy.py index 04b34e5e..dd420819 100644 --- a/sugar/p2p/Buddy.py +++ b/sugar/p2p/Buddy.py @@ -23,6 +23,7 @@ class Buddy(object): self._services[service.get_type()] = service self._nick_name = service.get_name() self._address = service.get_address() + self._icon = None def get_icon(self): """Return the buddies icon, if any.""" @@ -70,10 +71,17 @@ class Owner(Buddy): self._presence_service = Service(nick, PRESENCE_SERVICE_TYPE, PRESENCE_SERVICE_PORT) Buddy.__init__(self, self._presence_service) - for fname in os.listdir(env.get_user_dir()): + user_dir = env.get_user_dir() + if not os.path.exists(user_dir): + try: + os.makedirs(user_dir) + except OSError: + pass + + for fname in os.listdir(user_dir): if not fname.startswith("buddy-icon."): continue - fd = open(os.path.join(env.get_user_dir(), fname), "r") + fd = open(os.path.join(user_dir, fname), "r") self._icon = fd.read() fd.close() break