diff --git a/services/presence/buddy.py b/services/presence/buddy.py index 25bdb69a..ca3aff22 100644 --- a/services/presence/buddy.py +++ b/services/presence/buddy.py @@ -560,7 +560,7 @@ class TestOwner(GenericOwner): __gtype_name__ = "TestOwner" - def __init__(self, ps, bus_name, object_id, test_num): + def __init__(self, ps, bus_name, object_id, test_num, randomize): self._cp = ConfigParser() self._section = "Info" self._test_activities = [] @@ -588,7 +588,9 @@ class TestOwner(GenericOwner): GenericOwner.__init__(self, ps, bus_name, object_id, key=pubkey, nick=nick, color=color, icon=icon, registered=registered, key_hash=privkey_hash) - self._ps.connect('connection-status', self._ps_connection_status_cb) + # Only do the random stuff if randomize is true + if randomize: + self._ps.connect('connection-status', self._ps_connection_status_cb) def _share_reply_cb(self, actid, object_path): activity = self._ps.internal_get_activity(actid) diff --git a/services/presence/presenceservice.py b/services/presence/presenceservice.py index d90eb56c..46ac1a28 100644 --- a/services/presence/presenceservice.py +++ b/services/presence/presenceservice.py @@ -51,7 +51,7 @@ class PresenceService(DBusGObject): ([gobject.TYPE_BOOLEAN])) } - def __init__(self, test=0): + def __init__(self, test_num=0, randomize=False): self._next_object_id = 0 self._connected = False @@ -66,8 +66,8 @@ class PresenceService(DBusGObject): # Create the Owner object objid = self._get_next_object_id() - if test > 0: - self._owner = TestOwner(self, self._bus_name, objid, test) + if test_num > 0: + self._owner = TestOwner(self, self._bus_name, objid, test_num, randomize) else: self._owner = ShellOwner(self, self._bus_name, objid) self._buddies[self._owner.props.key] = self._owner @@ -357,9 +357,9 @@ class PresenceService(DBusGObject): return self._activities[actid] -def main(test=False): +def main(test_num=0, randomize=False): loop = gobject.MainLoop() - ps = PresenceService(test) + ps = PresenceService(test_num, randomize) try: loop.run() except KeyboardInterrupt: diff --git a/services/presence/sugar-presence-service b/services/presence/sugar-presence-service index 7eec6965..1680fea5 100755 --- a/services/presence/sugar-presence-service +++ b/services/presence/sugar-presence-service @@ -24,24 +24,36 @@ import os from sugar import logger from sugar import env +def usage(): + logging.debug("Usage: sugar-presence-service [] [randomize]") + sys.path.append(env.get_service_path('presence')) -test=0 -if len(sys.argv) > 1: +test_num = 0 +randomize = False +if len(sys.argv) in [2, 3]: try: - test = int(sys.argv[1]) + test_num = int(sys.argv[1]) except ValueError: logging.debug("Bad test user number.") - if test < 1 or test > 10: + if test_num < 1 or test_num > 10: logging.debug("Bad test user number.") -if test > 0: - logger.start('test-%d-presenceservice' % test) + if len(sys.argv) == 3 and sys.argv[2] == "randomize": + randomize = True +elif len(sys.argv) == 1: + pass +else: + usage() + os._exit(1) + +if test_num > 0: + logger.start('test-%d-presenceservice' % test_num) else: logger.start('presenceservice') import presenceservice -logging.info('Starting presence service') +logging.info('Starting presence service...') -presenceservice.main(test) +presenceservice.main(test_num, randomize)