pylintize!!!
This commit is contained in:
parent
4479a14eea
commit
a3d69ab879
33
pylint.sh
Executable file
33
pylint.sh
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Errors that we may fix in the future
|
||||||
|
#
|
||||||
|
# C0301 Line length
|
||||||
|
# W0603 Using the global statement
|
||||||
|
# W0201 Attribute defined outside __init__
|
||||||
|
# R0201 Method could be a function
|
||||||
|
TODO="C0301,W0603,W0201,R0201"
|
||||||
|
|
||||||
|
# Errors we don't like
|
||||||
|
#
|
||||||
|
# W0613 Unused argument (glib signals)
|
||||||
|
# W0511 - FIXME/TODO/XXX
|
||||||
|
DISABLE="W0613,W0511"
|
||||||
|
|
||||||
|
MSGS="$TODO,$DISABLE"
|
||||||
|
ARG="sugar"
|
||||||
|
|
||||||
|
pylint \
|
||||||
|
--disable-all \
|
||||||
|
--include-ids=y \
|
||||||
|
--enable-variables=y \
|
||||||
|
--enable-exceptions=y \
|
||||||
|
--enable-miscellaneous=y \
|
||||||
|
--enable-format=y \
|
||||||
|
--enable-classes=y \
|
||||||
|
--disable-msg=$MSGS \
|
||||||
|
--reports=n \
|
||||||
|
--enable-metrics=n \
|
||||||
|
--indent-string=" " \
|
||||||
|
--ignore="SVGdraw.py" \
|
||||||
|
$ARG
|
@ -78,7 +78,7 @@ class AddressEntry(gtk.HBox):
|
|||||||
return self.folded
|
return self.folded
|
||||||
|
|
||||||
def set_folded(self, folded):
|
def set_folded(self, folded):
|
||||||
self.folded = not self.folded
|
self.folded = folded
|
||||||
self._update_folded_state()
|
self._update_folded_state()
|
||||||
|
|
||||||
def __button_clicked_cb(self, button):
|
def __button_clicked_cb(self, button):
|
||||||
@ -253,7 +253,6 @@ class WebActivity(activity.Activity):
|
|||||||
|
|
||||||
def activity_on_disconnected_from_shell(self):
|
def activity_on_disconnected_from_shell(self):
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
class BrowserShell(dbus.service.Object):
|
class BrowserShell(dbus.service.Object):
|
||||||
instance = None
|
instance = None
|
||||||
@ -298,11 +297,7 @@ class BrowserShell(dbus.service.Object):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
BrowserShell.get_instance().open_web_activity()
|
BrowserShell.get_instance().open_web_activity()
|
||||||
|
|
||||||
try:
|
|
||||||
gtk.main()
|
gtk.main()
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@ -1,121 +0,0 @@
|
|||||||
# -*- tab-width: 4; indent-tabs-mode: t -*-
|
|
||||||
|
|
||||||
import presence
|
|
||||||
import avahi
|
|
||||||
|
|
||||||
ACTION_BUDDY_ADDED = "added"
|
|
||||||
ACTION_BUDDY_REMOVED = "removed"
|
|
||||||
|
|
||||||
|
|
||||||
class Buddy(object):
|
|
||||||
def __init__(self, nick, realname, servicename, host, address, port, key=None):
|
|
||||||
self._nick = nick
|
|
||||||
self._realname = realname
|
|
||||||
self._servicename = servicename
|
|
||||||
self._key = key
|
|
||||||
self._host = host
|
|
||||||
self._address = str(address)
|
|
||||||
self._port = int(port)
|
|
||||||
self._chat = None
|
|
||||||
|
|
||||||
def set_chat(self, chat):
|
|
||||||
self._chat = chat
|
|
||||||
|
|
||||||
def chat(self):
|
|
||||||
return self._chat
|
|
||||||
|
|
||||||
def nick(self):
|
|
||||||
return self._nick
|
|
||||||
|
|
||||||
def realname(self):
|
|
||||||
return self._realname
|
|
||||||
|
|
||||||
def servicename(self):
|
|
||||||
return self._servicename
|
|
||||||
|
|
||||||
def host(self):
|
|
||||||
return self._host
|
|
||||||
|
|
||||||
def address(self):
|
|
||||||
return self._address
|
|
||||||
|
|
||||||
def port(self):
|
|
||||||
return self._port
|
|
||||||
|
|
||||||
def key(self):
|
|
||||||
return self._key
|
|
||||||
|
|
||||||
class BuddyList(object):
|
|
||||||
""" Manage a list of buddies """
|
|
||||||
|
|
||||||
def __init__(self, servicename):
|
|
||||||
self._listeners = []
|
|
||||||
self._buddies = {}
|
|
||||||
self._servicename = servicename
|
|
||||||
self._pdiscovery = presence.PresenceDiscovery()
|
|
||||||
self._pdiscovery.add_service_listener(self._on_service_change)
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
self._pdiscovery.start()
|
|
||||||
|
|
||||||
def add_buddy_listener(self, listener):
|
|
||||||
self._listeners.append(listener)
|
|
||||||
|
|
||||||
def _add_buddy(self, host, address, port, servicename, data):
|
|
||||||
# Ignore ourselves
|
|
||||||
if servicename == self._servicename:
|
|
||||||
return
|
|
||||||
|
|
||||||
if len(data) > 0 and 'name' in data.keys():
|
|
||||||
buddy = self._find_buddy_by_service_name(servicename)
|
|
||||||
if not buddy:
|
|
||||||
buddy = Buddy(data['name'], data['realname'], servicename, host, address, port)
|
|
||||||
self._buddies[data['name']] = buddy
|
|
||||||
self._notify_listeners(ACTION_BUDDY_ADDED, buddy)
|
|
||||||
|
|
||||||
def _remove_buddy(self, buddy):
|
|
||||||
nick = buddy.nick()
|
|
||||||
self._notify_listeners(ACTION_BUDDY_REMOVED, buddy)
|
|
||||||
del self._buddies[nick]
|
|
||||||
|
|
||||||
def _find_buddy_by_service_name(self, servicename):
|
|
||||||
for buddy in self._buddies.values():
|
|
||||||
if buddy.servicename() == servicename:
|
|
||||||
return buddy
|
|
||||||
return None
|
|
||||||
|
|
||||||
def find_buddy_by_address(self, address):
|
|
||||||
for buddy_name in self._buddies.keys():
|
|
||||||
buddy = self._buddies[buddy_name]
|
|
||||||
if buddy.address() == address:
|
|
||||||
return buddy
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _notify_listeners(self, action, buddy):
|
|
||||||
for listener in self._listeners:
|
|
||||||
listener(action, buddy)
|
|
||||||
|
|
||||||
def _on_service_change(self, action, interface, protocol, name, stype, domain, flags):
|
|
||||||
if stype != presence.OLPC_CHAT_SERVICE:
|
|
||||||
return
|
|
||||||
if action == presence.ACTION_SERVICE_NEW:
|
|
||||||
self._pdiscovery.resolve_service(interface, protocol, name, stype, domain, self._on_service_resolved)
|
|
||||||
elif action == presence.ACTION_SERVICE_REMOVED:
|
|
||||||
buddy = self._find_buddy_by_service_name(name)
|
|
||||||
if buddy:
|
|
||||||
self._remove_buddy(buddy)
|
|
||||||
|
|
||||||
def _pair_to_dict(self, l):
|
|
||||||
res = {}
|
|
||||||
for el in l:
|
|
||||||
tmp = el.split('=', 1)
|
|
||||||
if len(tmp) > 1:
|
|
||||||
res[tmp[0]] = tmp[1]
|
|
||||||
else:
|
|
||||||
res[tmp[0]] = ''
|
|
||||||
return res
|
|
||||||
|
|
||||||
def _on_service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
|
|
||||||
data = self._pair_to_dict(avahi.txt_array_to_string_array(txt))
|
|
||||||
self._add_buddy(host, address, port, name, data)
|
|
||||||
|
|
@ -10,9 +10,11 @@ pygtk.require('2.0')
|
|||||||
import gtk, gobject
|
import gtk, gobject
|
||||||
|
|
||||||
from sugar.shell import activity
|
from sugar.shell import activity
|
||||||
from sugar.p2p.Group import *
|
from sugar.p2p.Group import Group
|
||||||
from sugar.p2p.StreamReader import *
|
from sugar.p2p.Group import LocalGroup
|
||||||
from sugar.p2p.StreamWriter import *
|
from sugar.p2p.Service import Service
|
||||||
|
from sugar.p2p.StreamReader import StreamReader
|
||||||
|
from sugar.p2p.StreamWriter import StreamWriter
|
||||||
import sugar.env
|
import sugar.env
|
||||||
|
|
||||||
import richtext
|
import richtext
|
||||||
@ -71,14 +73,14 @@ class Chat(activity.Activity):
|
|||||||
self._hbox = gtk.HBox(False, 12)
|
self._hbox = gtk.HBox(False, 12)
|
||||||
self._hbox.set_border_width(12)
|
self._hbox.set_border_width(12)
|
||||||
|
|
||||||
[chat_vbox, buffer] = self._create_chat()
|
[chat_vbox, buf] = self._create_chat()
|
||||||
self._hbox.pack_start(chat_vbox)
|
self._hbox.pack_start(chat_vbox)
|
||||||
chat_vbox.show()
|
chat_vbox.show()
|
||||||
|
|
||||||
vbox.pack_start(self._hbox)
|
vbox.pack_start(self._hbox)
|
||||||
self._hbox.show()
|
self._hbox.show()
|
||||||
|
|
||||||
toolbar = self._create_toolbar(buffer)
|
toolbar = self._create_toolbar(buf)
|
||||||
vbox.pack_start(toolbar, False)
|
vbox.pack_start(toolbar, False)
|
||||||
toolbar.show()
|
toolbar.show()
|
||||||
|
|
||||||
@ -138,29 +140,29 @@ class Chat(activity.Activity):
|
|||||||
|
|
||||||
def activity_on_got_focus(self):
|
def activity_on_got_focus(self):
|
||||||
print "act %d: in activity_on_got_focus" % self.activity_get_id()
|
print "act %d: in activity_on_got_focus" % self.activity_get_id()
|
||||||
self._controller.notify_activate(self)
|
# FIXME self._controller.notify_activate(self)
|
||||||
|
|
||||||
def recv_message(self, buddy, msg):
|
def recv_message(self, buddy, msg):
|
||||||
self._insert_rich_message(buddy.get_nick_name(), msg)
|
self._insert_rich_message(buddy.get_nick_name(), msg)
|
||||||
self._controller.notify_new_message(self, buddy)
|
self._controller.notify_new_message(self, buddy)
|
||||||
|
|
||||||
def _insert_rich_message(self, nick, msg):
|
def _insert_rich_message(self, nick, msg):
|
||||||
buffer = self._chat_view.get_buffer()
|
buf = self._chat_view.get_buffer()
|
||||||
aniter = buffer.get_end_iter()
|
aniter = buf.get_end_iter()
|
||||||
buffer.insert(aniter, nick + ": ")
|
buf.insert(aniter, nick + ": ")
|
||||||
|
|
||||||
serializer = richtext.RichTextSerializer()
|
serializer = richtext.RichTextSerializer()
|
||||||
serializer.deserialize(msg, buffer)
|
serializer.deserialize(msg, buf)
|
||||||
|
|
||||||
aniter = buffer.get_end_iter()
|
aniter = buf.get_end_iter()
|
||||||
buffer.insert(aniter, "\n")
|
buf.insert(aniter, "\n")
|
||||||
|
|
||||||
def _local_message(self, success, text):
|
def _local_message(self, success, text):
|
||||||
if not success:
|
if not success:
|
||||||
message = "Error: %s\n" % text
|
message = "Error: %s\n" % text
|
||||||
buffer = self._chat_view.get_buffer()
|
buf = self._chat_view.get_buffer()
|
||||||
aniter = buffer.get_end_iter()
|
aniter = buf.get_end_iter()
|
||||||
buffer.insert(aniter, message)
|
buf.insert(aniter, message)
|
||||||
else:
|
else:
|
||||||
owner = self._controller.get_group().get_owner()
|
owner = self._controller.get_group().get_owner()
|
||||||
self._insert_rich_message(owner.get_nick_name(), text)
|
self._insert_rich_message(owner.get_nick_name(), text)
|
||||||
@ -325,11 +327,11 @@ class GroupChat(Chat):
|
|||||||
if buddy.get_nick_name() == self._group.get_owner().get_nick_name():
|
if buddy.get_nick_name() == self._group.get_owner().get_nick_name():
|
||||||
# Do not show ourself in the buddy list
|
# Do not show ourself in the buddy list
|
||||||
pass
|
pass
|
||||||
elif action == BUDDY_JOIN:
|
elif action == Group.BUDDY_JOIN:
|
||||||
aniter = self._buddy_list_model.append(None)
|
aniter = self._buddy_list_model.append(None)
|
||||||
self._buddy_list_model.set(aniter, self._MODEL_COL_NICK, buddy.get_nick_name(),
|
self._buddy_list_model.set(aniter, self._MODEL_COL_NICK, buddy.get_nick_name(),
|
||||||
self._MODEL_COL_ICON, None, self._MODEL_COL_BUDDY, buddy)
|
self._MODEL_COL_ICON, None, self._MODEL_COL_BUDDY, buddy)
|
||||||
elif action == BUDDY_LEAVE:
|
elif action == Group.BUDDY_LEAVE:
|
||||||
aniter = self._get_iter_for_buddy(buddy)
|
aniter = self._get_iter_for_buddy(buddy)
|
||||||
if aniter:
|
if aniter:
|
||||||
self._buddy_list_model.remove(aniter)
|
self._buddy_list_model.remove(aniter)
|
||||||
@ -346,7 +348,7 @@ class GroupChat(Chat):
|
|||||||
aniter = self._get_iter_for_buddy(buddy)
|
aniter = self._get_iter_for_buddy(buddy)
|
||||||
self._buddy_list_model.set(aniter, self._MODEL_COL_ICON, self._pixbuf_new_message)
|
self._buddy_list_model.set(aniter, self._MODEL_COL_ICON, self._pixbuf_new_message)
|
||||||
|
|
||||||
def notify_activate(self, chat):
|
def notify_activate(self, chat, buddy):
|
||||||
aniter = self._get_iter_for_buddy(buddy)
|
aniter = self._get_iter_for_buddy(buddy)
|
||||||
self._buddy_list_model.set(aniter, self._MODEL_COL_ICON, self._pixbuf_active_chat)
|
self._buddy_list_model.set(aniter, self._MODEL_COL_ICON, self._pixbuf_active_chat)
|
||||||
|
|
||||||
@ -396,10 +398,7 @@ class ChatShell(dbus.service.Object):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
ChatShell.get_instance().open_group_chat()
|
ChatShell.get_instance().open_group_chat()
|
||||||
try:
|
|
||||||
gtk.main()
|
gtk.main()
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@ -45,7 +45,7 @@ class RichTextView(gtk.TextView):
|
|||||||
|
|
||||||
def __motion_notify_cb(self, widget, event):
|
def __motion_notify_cb(self, widget, event):
|
||||||
if event.is_hint:
|
if event.is_hint:
|
||||||
[x, y, state] = event.window.get_pointer();
|
event.window.get_pointer();
|
||||||
|
|
||||||
it = self.__get_event_iter(event)
|
it = self.__get_event_iter(event)
|
||||||
if it:
|
if it:
|
||||||
@ -205,6 +205,7 @@ class RichTextToolbar(gtk.Toolbar):
|
|||||||
|
|
||||||
class RichTextHandler(xml.sax.handler.ContentHandler):
|
class RichTextHandler(xml.sax.handler.ContentHandler):
|
||||||
def __init__(self, serializer, buf):
|
def __init__(self, serializer, buf):
|
||||||
|
xml.sax.handler.ContentHandler.__init__(self)
|
||||||
self.buf = buf
|
self.buf = buf
|
||||||
self.serializer = serializer
|
self.serializer = serializer
|
||||||
self.tags = []
|
self.tags = []
|
||||||
@ -286,7 +287,7 @@ class RichTextSerializer:
|
|||||||
def serialize(self, buf):
|
def serialize(self, buf):
|
||||||
self.buf = buf
|
self.buf = buf
|
||||||
|
|
||||||
xml = "<richtext>"
|
res = "<richtext>"
|
||||||
|
|
||||||
next_it = buf.get_start_iter()
|
next_it = buf.get_start_iter()
|
||||||
while not next_it.is_end():
|
while not next_it.is_end():
|
||||||
@ -299,27 +300,27 @@ class RichTextSerializer:
|
|||||||
for tag in it.get_toggled_tags(False):
|
for tag in it.get_toggled_tags(False):
|
||||||
while 1:
|
while 1:
|
||||||
open_tag = self._open_tags.pop()
|
open_tag = self._open_tags.pop()
|
||||||
xml += self.serialize_tag_end(tag)
|
res += self.serialize_tag_end(tag)
|
||||||
if open_tag == tag:
|
if open_tag == tag:
|
||||||
break
|
break
|
||||||
tags_to_reopen.append(open_tag)
|
tags_to_reopen.append(open_tag)
|
||||||
|
|
||||||
for tag in tags_to_reopen:
|
for tag in tags_to_reopen:
|
||||||
self._open_tags.append(tag)
|
self._open_tags.append(tag)
|
||||||
xml += self.serialize_tag_start(tag, it)
|
res += self.serialize_tag_start(tag, it)
|
||||||
|
|
||||||
for tag in it.get_toggled_tags(True):
|
for tag in it.get_toggled_tags(True):
|
||||||
self._open_tags.append(tag)
|
self._open_tags.append(tag)
|
||||||
xml += self.serialize_tag_start(tag, it)
|
res += self.serialize_tag_start(tag, it)
|
||||||
|
|
||||||
xml += buf.get_text(it, next_it, False)
|
res += buf.get_text(it, next_it, False)
|
||||||
|
|
||||||
if next_it.is_end():
|
if next_it.is_end():
|
||||||
self._open_tags.reverse()
|
self._open_tags.reverse()
|
||||||
for tag in self._open_tags:
|
for tag in self._open_tags:
|
||||||
xml += self.serialize_tag_end(tag)
|
res += self.serialize_tag_end(tag)
|
||||||
|
|
||||||
xml += "</richtext>"
|
res += "</richtext>"
|
||||||
|
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
@ -330,11 +331,11 @@ class RichTextSerializer:
|
|||||||
parser.feed(xml_string)
|
parser.feed(xml_string)
|
||||||
parser.close()
|
parser.close()
|
||||||
|
|
||||||
def test_quit(window, rich_buf):
|
def test_quit(w, rb):
|
||||||
print RichTextSerializer().serialize(rich_buf)
|
print RichTextSerializer().serialize(rb)
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
|
|
||||||
def link_clicked(view, address):
|
def link_clicked(v, address):
|
||||||
print "Link clicked " + address
|
print "Link clicked " + address
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -350,15 +351,15 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
rich_buf = view.get_buffer()
|
rich_buf = view.get_buffer()
|
||||||
|
|
||||||
xml_string = "<richtext>"
|
test_xml = "<richtext>"
|
||||||
|
|
||||||
xml_string += "<bold><italic>Test</italic>one</bold>\n"
|
test_xml += "<bold><italic>Test</italic>one</bold>\n"
|
||||||
xml_string += "<bold><italic>Test two</italic></bold>"
|
test_xml += "<bold><italic>Test two</italic></bold>"
|
||||||
xml_string += "<font size=\"xx-small\">Test three</font>"
|
test_xml += "<font size=\"xx-small\">Test three</font>"
|
||||||
xml_string += "<link href=\"http://www.gnome.org\">Test link</link>"
|
test_xml += "<link href=\"http://www.gnome.org\">Test link</link>"
|
||||||
xml_string += "</richtext>"
|
test_xml += "</richtext>"
|
||||||
|
|
||||||
RichTextSerializer().deserialize(xml_string, rich_buf)
|
RichTextSerializer().deserialize(test_xml, rich_buf)
|
||||||
|
|
||||||
toolbar = RichTextToolbar(rich_buf)
|
toolbar = RichTextToolbar(rich_buf)
|
||||||
vbox.pack_start(toolbar, False)
|
vbox.pack_start(toolbar, False)
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from sugar.__uninstalled__ import *
|
from sugar.__uninstalled__ import internal_get_data_file
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from sugar.__installed__ import *
|
from sugar.__installed__ import internal_get_data_file
|
||||||
|
|
||||||
def get_data_file(filename):
|
def get_data_file(filename):
|
||||||
return internal_get_data_file(filename)
|
return internal_get_data_file(filename)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import pwd
|
import pwd
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from Service import *
|
from Service import Service
|
||||||
|
|
||||||
PRESENCE_SERVICE_TYPE = "_olpc_presence._tcp"
|
PRESENCE_SERVICE_TYPE = "_olpc_presence._tcp"
|
||||||
PRESENCE_SERVICE_PORT = 6000
|
PRESENCE_SERVICE_PORT = 6000
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import avahi
|
from Buddy import Buddy
|
||||||
|
from Buddy import Owner
|
||||||
import presence
|
from Buddy import PRESENCE_SERVICE_TYPE
|
||||||
from Buddy import *
|
from Service import Service
|
||||||
from Service import *
|
|
||||||
import Model
|
import Model
|
||||||
|
import presence
|
||||||
|
|
||||||
|
class Group:
|
||||||
SERVICE_ADDED = "service_added"
|
SERVICE_ADDED = "service_added"
|
||||||
SERVICE_REMOVED = "service_removed"
|
SERVICE_REMOVED = "service_removed"
|
||||||
|
|
||||||
BUDDY_JOIN = "buddy_join"
|
BUDDY_JOIN = "buddy_join"
|
||||||
BUDDY_LEAVE = "buddy_leave"
|
BUDDY_LEAVE = "buddy_leave"
|
||||||
|
|
||||||
class Group:
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._service_listeners = []
|
self._service_listeners = []
|
||||||
self._presence_listeners = []
|
self._presence_listeners = []
|
||||||
@ -20,7 +20,7 @@ class Group:
|
|||||||
def get_store(self):
|
def get_store(self):
|
||||||
return self._store
|
return self._store
|
||||||
|
|
||||||
def join(self, buddy):
|
def join(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def add_service_listener(self, listener):
|
def add_service_listener(self, listener):
|
||||||
@ -31,19 +31,19 @@ class Group:
|
|||||||
|
|
||||||
def _notify_service_added(self, service):
|
def _notify_service_added(self, service):
|
||||||
for listener in self._service_listeners:
|
for listener in self._service_listeners:
|
||||||
listener(SERVICE_ADDED, buddy)
|
listener(Group.SERVICE_ADDED, service)
|
||||||
|
|
||||||
def _notify_service_removed(self, service):
|
def _notify_service_removed(self, service_id):
|
||||||
for listener in self._service_listeners:
|
for listener in self._service_listeners:
|
||||||
listener(SERVICE_REMOVED,buddy)
|
listener(Group.SERVICE_REMOVED, service_id)
|
||||||
|
|
||||||
def _notify_buddy_join(self, buddy):
|
def _notify_buddy_join(self, buddy):
|
||||||
for listener in self._presence_listeners:
|
for listener in self._presence_listeners:
|
||||||
listener(BUDDY_JOIN, buddy)
|
listener(Group.BUDDY_JOIN, buddy)
|
||||||
|
|
||||||
def _notify_buddy_leave(self, buddy):
|
def _notify_buddy_leave(self, buddy):
|
||||||
for listener in self._presence_listeners:
|
for listener in self._presence_listeners:
|
||||||
listener(BUDDY_LEAVE, buddy)
|
listener(Group.BUDDY_LEAVE, buddy)
|
||||||
|
|
||||||
class LocalGroup(Group):
|
class LocalGroup(Group):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -64,9 +64,9 @@ class LocalGroup(Group):
|
|||||||
self._services[sid] = service
|
self._services[sid] = service
|
||||||
self._notify_service_added(service)
|
self._notify_service_added(service)
|
||||||
|
|
||||||
def remove_service(self, sid):
|
def remove_service(self, service_id):
|
||||||
self._notify_service_removed(service)
|
self._notify_service_removed(service_id)
|
||||||
del self._services[sid]
|
del self._services[service_id]
|
||||||
|
|
||||||
def join(self):
|
def join(self):
|
||||||
self._owner = Owner(self)
|
self._owner = Owner(self)
|
||||||
|
@ -3,6 +3,7 @@ sugar_PYTHON = \
|
|||||||
__init__.py \
|
__init__.py \
|
||||||
Buddy.py \
|
Buddy.py \
|
||||||
Group.py \
|
Group.py \
|
||||||
|
Model.py \
|
||||||
Service.py \
|
Service.py \
|
||||||
StreamReader.py \
|
StreamReader.py \
|
||||||
StreamWriter.py \
|
StreamWriter.py \
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
MODEL_SERVICE_TYPE = "_olpc_model._tcp"
|
MODEL_SERVICE_TYPE = "_olpc_model._tcp"
|
||||||
MODEL_SERVICE_PORT = 6300
|
MODEL_SERVICE_PORT = 6300
|
||||||
|
|
||||||
|
import socket
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
|
|
||||||
from sugar.p2p.Service import Service
|
from sugar.p2p.Service import Service
|
||||||
@ -59,7 +60,7 @@ class LocalModel:
|
|||||||
p2p_server = network.GlibXMLRPCServer(("", port))
|
p2p_server = network.GlibXMLRPCServer(("", port))
|
||||||
p2p_server.register_instance(ModelRequestHandler(self))
|
p2p_server.register_instance(ModelRequestHandler(self))
|
||||||
started = True
|
started = True
|
||||||
except:
|
except(socket.error):
|
||||||
port = port + 1
|
port = port + 1
|
||||||
tries = tries - 1
|
tries = tries - 1
|
||||||
service.set_port(port)
|
service.set_port(port)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
import network
|
import network
|
||||||
|
|
||||||
class StreamReaderRequestHandler(object):
|
class StreamReaderRequestHandler(object):
|
||||||
@ -5,7 +7,6 @@ class StreamReaderRequestHandler(object):
|
|||||||
self._reader = reader
|
self._reader = reader
|
||||||
|
|
||||||
def message(self, nick_name, message):
|
def message(self, nick_name, message):
|
||||||
address = network.get_authinfo()
|
|
||||||
self._reader.recv(nick_name, message)
|
self._reader.recv(nick_name, message)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ class StreamReader:
|
|||||||
p2p_server = network.GlibXMLRPCServer(("", port))
|
p2p_server = network.GlibXMLRPCServer(("", port))
|
||||||
p2p_server.register_instance(StreamReaderRequestHandler(self))
|
p2p_server.register_instance(StreamReaderRequestHandler(self))
|
||||||
started = True
|
started = True
|
||||||
except:
|
except(socket.error):
|
||||||
port = port + 1
|
port = port + 1
|
||||||
tries = tries - 1
|
tries = tries - 1
|
||||||
self._service.set_port(port)
|
self._service.set_port(port)
|
||||||
|
@ -31,7 +31,7 @@ class StreamWriter:
|
|||||||
nick_name = self._group.get_owner().get_nick_name()
|
nick_name = self._group.get_owner().get_nick_name()
|
||||||
self._uclient.message(nick_name, data)
|
self._uclient.message(nick_name, data)
|
||||||
return True
|
return True
|
||||||
except (socket.error, xmlrpclib.Fault, xmlrpclib.ProtocolError), e:
|
except (socket.error, xmlrpclib.Fault, xmlrpclib.ProtocolError):
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
# -*- tab-width: 4; indent-tabs-mode: t -*-
|
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
import select
|
|
||||||
import time
|
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -133,10 +129,6 @@ class GroupServer(object):
|
|||||||
|
|
||||||
# Set some options to make it multicast-friendly
|
# Set some options to make it multicast-friendly
|
||||||
self._listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
self._listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
try:
|
|
||||||
self._listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
self._listen_sock.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_TTL, 20)
|
self._listen_sock.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_TTL, 20)
|
||||||
self._listen_sock.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_LOOP, 1)
|
self._listen_sock.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_LOOP, 1)
|
||||||
|
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
# -*- tab-width: 4; indent-tabs-mode: t -*-
|
# -*- tab-width: 4; indent-tabs-mode: t -*-
|
||||||
|
|
||||||
import string
|
|
||||||
|
|
||||||
import gc
|
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.service
|
import dbus.service
|
||||||
import dbus.glib
|
import dbus.glib
|
||||||
import gobject
|
|
||||||
import pygtk
|
import pygtk
|
||||||
pygtk.require('2.0')
|
pygtk.require('2.0')
|
||||||
import gtk,sys
|
import gtk
|
||||||
|
|
||||||
|
|
||||||
class Activity(dbus.service.Object):
|
class Activity(dbus.service.Object):
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- tab-width: 4; indent-tabs-mode: t -*-
|
# -*- tab-width: 4; indent-tabs-mode: t -*-
|
||||||
|
|
||||||
import string
|
|
||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.service
|
import dbus.service
|
||||||
import dbus.glib
|
import dbus.glib
|
||||||
import gobject
|
|
||||||
import pygtk
|
import pygtk
|
||||||
pygtk.require('2.0')
|
pygtk.require('2.0')
|
||||||
import gtk
|
import gtk
|
||||||
@ -225,10 +222,11 @@ class ActivityContainer(dbus.service.Object):
|
|||||||
self.window.add(self.notebook)
|
self.window.add(self.notebook)
|
||||||
|
|
||||||
self.window.connect("destroy", lambda w: gtk.main_quit())
|
self.window.connect("destroy", lambda w: gtk.main_quit())
|
||||||
self.window.show()
|
|
||||||
|
|
||||||
self.current_activity = None
|
self.current_activity = None
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
self.window.show()
|
||||||
|
|
||||||
def __focus_reply_cb(self):
|
def __focus_reply_cb(self):
|
||||||
pass
|
pass
|
||||||
@ -295,11 +293,9 @@ def main():
|
|||||||
service = dbus.service.BusName("com.redhat.Sugar.Shell", bus=session_bus)
|
service = dbus.service.BusName("com.redhat.Sugar.Shell", bus=session_bus)
|
||||||
|
|
||||||
activityContainer = ActivityContainer(service, session_bus)
|
activityContainer = ActivityContainer(service, session_bus)
|
||||||
|
activityContainer.show()
|
||||||
|
|
||||||
try:
|
|
||||||
gtk.main()
|
gtk.main()
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user