From cd3d98cb77751f02ce7038734e3fc0893a63738f Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 16 Jun 2006 15:48:44 -0400 Subject: [PATCH] A pass at fixing single-computer with more than one sugar instance work --- sugar/presence/PresenceService.py | 4 +++- sugar/shell/Owner.py | 6 ------ sugar/sugar | 9 +++++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sugar/presence/PresenceService.py b/sugar/presence/PresenceService.py index 7fb0a44d..ec30db4f 100644 --- a/sugar/presence/PresenceService.py +++ b/sugar/presence/PresenceService.py @@ -6,6 +6,7 @@ import os import string import random from sugar import util +from sugar import env def _get_local_ip_address(ifname): """Call Linux specific bits to retrieve our own IP address.""" @@ -196,7 +197,8 @@ class PresenceService(gobject.GObject): buddy.add_service(service) except KeyError: # Should this service mark the owner? - if service.get_address() in self._local_addrs.values(): + owner_nick = env.get_nick_name() + if name == owner_nick and service.get_address() in self._local_addrs.values(): buddy = Buddy.Owner(service) self._owner = buddy print "Set owner to %s" % name diff --git a/sugar/shell/Owner.py b/sugar/shell/Owner.py index b7074d70..ea6c5ff2 100644 --- a/sugar/shell/Owner.py +++ b/sugar/shell/Owner.py @@ -3,7 +3,6 @@ from sugar.presence import Service from sugar.presence import Buddy from sugar.presence import PresenceService from sugar.p2p import Stream -import pwd import os import random import base64 @@ -16,11 +15,6 @@ class ShellOwner(object): server portion of the Owner, paired with the client portion in Buddy.py.""" def __init__(self): nick = env.get_nick_name() - if not nick: - nick = pwd.getpwuid(os.getuid())[0] - if not nick or not len(nick): - nick = "Guest" - user_dir = env.get_user_dir() if not os.path.exists(user_dir): try: diff --git a/sugar/sugar b/sugar/sugar index f90ed4c5..259e9b65 100755 --- a/sugar/sugar +++ b/sugar/sugar @@ -2,6 +2,8 @@ import sys import os +import pwd +import random import pygtk pygtk.require('2.0') @@ -47,6 +49,13 @@ for arg in sys.argv: started_dbus = True i += 1 +if not os.environ.has_key("SUGAR_NICK_NAME"): + nick = pwd.getpwuid(os.getuid())[0] + if not nick or not len(nick): + nick = "Guest %d" % random.randint(1, 10000) + os.environ['SUGAR_NICK_NAME'] = nick + os.environ['SUGAR_USER_DIR'] = os.path.expanduser('~/.sugar') + curdir = os.path.dirname(__file__) if curdir == '.': basedir = os.path.dirname(os.getcwd())