pylintize!!!

This commit is contained in:
Marco Pesenti Gritti 2006-05-13 01:28:51 -04:00
parent 4479a14eea
commit a3d69ab879
16 changed files with 143 additions and 251 deletions

33
pylint.sh Executable file
View 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

View File

@ -78,7 +78,7 @@ class AddressEntry(gtk.HBox):
return self.folded
def set_folded(self, folded):
self.folded = not self.folded
self.folded = folded
self._update_folded_state()
def __button_clicked_cb(self, button):
@ -253,7 +253,6 @@ class WebActivity(activity.Activity):
def activity_on_disconnected_from_shell(self):
gtk.main_quit()
gc.collect()
class BrowserShell(dbus.service.Object):
instance = None
@ -298,11 +297,7 @@ class BrowserShell(dbus.service.Object):
def main():
BrowserShell.get_instance().open_web_activity()
try:
gtk.main()
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()

View File

@ -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)

View File

@ -10,9 +10,11 @@ pygtk.require('2.0')
import gtk, gobject
from sugar.shell import activity
from sugar.p2p.Group import *
from sugar.p2p.StreamReader import *
from sugar.p2p.StreamWriter import *
from sugar.p2p.Group import Group
from sugar.p2p.Group import LocalGroup
from sugar.p2p.Service import Service
from sugar.p2p.StreamReader import StreamReader
from sugar.p2p.StreamWriter import StreamWriter
import sugar.env
import richtext
@ -71,14 +73,14 @@ class Chat(activity.Activity):
self._hbox = gtk.HBox(False, 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)
chat_vbox.show()
vbox.pack_start(self._hbox)
self._hbox.show()
toolbar = self._create_toolbar(buffer)
toolbar = self._create_toolbar(buf)
vbox.pack_start(toolbar, False)
toolbar.show()
@ -138,29 +140,29 @@ class Chat(activity.Activity):
def activity_on_got_focus(self):
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):
self._insert_rich_message(buddy.get_nick_name(), msg)
self._controller.notify_new_message(self, buddy)
def _insert_rich_message(self, nick, msg):
buffer = self._chat_view.get_buffer()
aniter = buffer.get_end_iter()
buffer.insert(aniter, nick + ": ")
buf = self._chat_view.get_buffer()
aniter = buf.get_end_iter()
buf.insert(aniter, nick + ": ")
serializer = richtext.RichTextSerializer()
serializer.deserialize(msg, buffer)
serializer.deserialize(msg, buf)
aniter = buffer.get_end_iter()
buffer.insert(aniter, "\n")
aniter = buf.get_end_iter()
buf.insert(aniter, "\n")
def _local_message(self, success, text):
if not success:
message = "Error: %s\n" % text
buffer = self._chat_view.get_buffer()
aniter = buffer.get_end_iter()
buffer.insert(aniter, message)
buf = self._chat_view.get_buffer()
aniter = buf.get_end_iter()
buf.insert(aniter, message)
else:
owner = self._controller.get_group().get_owner()
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():
# Do not show ourself in the buddy list
pass
elif action == BUDDY_JOIN:
elif action == Group.BUDDY_JOIN:
aniter = self._buddy_list_model.append(None)
self._buddy_list_model.set(aniter, self._MODEL_COL_NICK, buddy.get_nick_name(),
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)
if aniter:
self._buddy_list_model.remove(aniter)
@ -346,7 +348,7 @@ class GroupChat(Chat):
aniter = self._get_iter_for_buddy(buddy)
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)
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():
ChatShell.get_instance().open_group_chat()
try:
gtk.main()
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()

View File

@ -45,7 +45,7 @@ class RichTextView(gtk.TextView):
def __motion_notify_cb(self, widget, event):
if event.is_hint:
[x, y, state] = event.window.get_pointer();
event.window.get_pointer();
it = self.__get_event_iter(event)
if it:
@ -205,6 +205,7 @@ class RichTextToolbar(gtk.Toolbar):
class RichTextHandler(xml.sax.handler.ContentHandler):
def __init__(self, serializer, buf):
xml.sax.handler.ContentHandler.__init__(self)
self.buf = buf
self.serializer = serializer
self.tags = []
@ -286,7 +287,7 @@ class RichTextSerializer:
def serialize(self, buf):
self.buf = buf
xml = "<richtext>"
res = "<richtext>"
next_it = buf.get_start_iter()
while not next_it.is_end():
@ -299,27 +300,27 @@ class RichTextSerializer:
for tag in it.get_toggled_tags(False):
while 1:
open_tag = self._open_tags.pop()
xml += self.serialize_tag_end(tag)
res += self.serialize_tag_end(tag)
if open_tag == tag:
break
tags_to_reopen.append(open_tag)
for tag in tags_to_reopen:
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):
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():
self._open_tags.reverse()
for tag in self._open_tags:
xml += self.serialize_tag_end(tag)
res += self.serialize_tag_end(tag)
xml += "</richtext>"
res += "</richtext>"
return xml
@ -330,11 +331,11 @@ class RichTextSerializer:
parser.feed(xml_string)
parser.close()
def test_quit(window, rich_buf):
print RichTextSerializer().serialize(rich_buf)
def test_quit(w, rb):
print RichTextSerializer().serialize(rb)
gtk.main_quit()
def link_clicked(view, address):
def link_clicked(v, address):
print "Link clicked " + address
if __name__ == "__main__":
@ -350,15 +351,15 @@ if __name__ == "__main__":
rich_buf = view.get_buffer()
xml_string = "<richtext>"
test_xml = "<richtext>"
xml_string += "<bold><italic>Test</italic>one</bold>\n"
xml_string += "<bold><italic>Test two</italic></bold>"
xml_string += "<font size=\"xx-small\">Test three</font>"
xml_string += "<link href=\"http://www.gnome.org\">Test link</link>"
xml_string += "</richtext>"
test_xml += "<bold><italic>Test</italic>one</bold>\n"
test_xml += "<bold><italic>Test two</italic></bold>"
test_xml += "<font size=\"xx-small\">Test three</font>"
test_xml += "<link href=\"http://www.gnome.org\">Test link</link>"
test_xml += "</richtext>"
RichTextSerializer().deserialize(xml_string, rich_buf)
RichTextSerializer().deserialize(test_xml, rich_buf)
toolbar = RichTextToolbar(rich_buf)
vbox.pack_start(toolbar, False)

View File

@ -1,9 +1,7 @@
import os
try:
from sugar.__uninstalled__ import *
from sugar.__uninstalled__ import internal_get_data_file
except ImportError:
from sugar.__installed__ import *
from sugar.__installed__ import internal_get_data_file
def get_data_file(filename):
return internal_get_data_file(filename)

View File

@ -1,7 +1,7 @@
import pwd
import os
from Service import *
from Service import Service
PRESENCE_SERVICE_TYPE = "_olpc_presence._tcp"
PRESENCE_SERVICE_PORT = 6000

View File

@ -1,17 +1,17 @@
import avahi
import presence
from Buddy import *
from Service import *
from Buddy import Buddy
from Buddy import Owner
from Buddy import PRESENCE_SERVICE_TYPE
from Service import Service
import Model
import presence
class Group:
SERVICE_ADDED = "service_added"
SERVICE_REMOVED = "service_removed"
BUDDY_JOIN = "buddy_join"
BUDDY_LEAVE = "buddy_leave"
class Group:
def __init__(self):
self._service_listeners = []
self._presence_listeners = []
@ -20,7 +20,7 @@ class Group:
def get_store(self):
return self._store
def join(self, buddy):
def join(self):
pass
def add_service_listener(self, listener):
@ -31,19 +31,19 @@ class Group:
def _notify_service_added(self, service):
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:
listener(SERVICE_REMOVED,buddy)
listener(Group.SERVICE_REMOVED, service_id)
def _notify_buddy_join(self, buddy):
for listener in self._presence_listeners:
listener(BUDDY_JOIN, buddy)
listener(Group.BUDDY_JOIN, buddy)
def _notify_buddy_leave(self, buddy):
for listener in self._presence_listeners:
listener(BUDDY_LEAVE, buddy)
listener(Group.BUDDY_LEAVE, buddy)
class LocalGroup(Group):
def __init__(self):
@ -64,9 +64,9 @@ class LocalGroup(Group):
self._services[sid] = service
self._notify_service_added(service)
def remove_service(self, sid):
self._notify_service_removed(service)
del self._services[sid]
def remove_service(self, service_id):
self._notify_service_removed(service_id)
del self._services[service_id]
def join(self):
self._owner = Owner(self)

View File

@ -3,6 +3,7 @@ sugar_PYTHON = \
__init__.py \
Buddy.py \
Group.py \
Model.py \
Service.py \
StreamReader.py \
StreamWriter.py \

View File

@ -1,6 +1,7 @@
MODEL_SERVICE_TYPE = "_olpc_model._tcp"
MODEL_SERVICE_PORT = 6300
import socket
import xmlrpclib
from sugar.p2p.Service import Service
@ -59,7 +60,7 @@ class LocalModel:
p2p_server = network.GlibXMLRPCServer(("", port))
p2p_server.register_instance(ModelRequestHandler(self))
started = True
except:
except(socket.error):
port = port + 1
tries = tries - 1
service.set_port(port)

View File

@ -1,3 +1,5 @@
import socket
import network
class StreamReaderRequestHandler(object):
@ -5,7 +7,6 @@ class StreamReaderRequestHandler(object):
self._reader = reader
def message(self, nick_name, message):
address = network.get_authinfo()
self._reader.recv(nick_name, message)
return True
@ -37,7 +38,7 @@ class StreamReader:
p2p_server = network.GlibXMLRPCServer(("", port))
p2p_server.register_instance(StreamReaderRequestHandler(self))
started = True
except:
except(socket.error):
port = port + 1
tries = tries - 1
self._service.set_port(port)

View File

@ -31,7 +31,7 @@ class StreamWriter:
nick_name = self._group.get_owner().get_nick_name()
self._uclient.message(nick_name, data)
return True
except (socket.error, xmlrpclib.Fault, xmlrpclib.ProtocolError), e:
except (socket.error, xmlrpclib.Fault, xmlrpclib.ProtocolError):
traceback.print_exc()
return False

View File

@ -1,10 +1,6 @@
# -*- tab-width: 4; indent-tabs-mode: t -*-
import socket
import threading
import traceback
import select
import time
import xmlrpclib
import sys
@ -133,10 +129,6 @@ class GroupServer(object):
# Set some options to make it multicast-friendly
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_LOOP, 1)

View File

@ -1,15 +1,11 @@
# -*- tab-width: 4; indent-tabs-mode: t -*-
import string
import gc
import dbus
import dbus.service
import dbus.glib
import gobject
import pygtk
pygtk.require('2.0')
import gtk,sys
import gtk
class Activity(dbus.service.Object):

View File

@ -1,12 +1,9 @@
#!/usr/bin/python
# -*- tab-width: 4; indent-tabs-mode: t -*-
import string
import dbus
import dbus.service
import dbus.glib
import gobject
import pygtk
pygtk.require('2.0')
import gtk
@ -225,10 +222,11 @@ class ActivityContainer(dbus.service.Object):
self.window.add(self.notebook)
self.window.connect("destroy", lambda w: gtk.main_quit())
self.window.show()
self.current_activity = None
def show(self):
self.window.show()
def __focus_reply_cb(self):
pass
@ -295,11 +293,9 @@ def main():
service = dbus.service.BusName("com.redhat.Sugar.Shell", bus=session_bus)
activityContainer = ActivityContainer(service, session_bus)
activityContainer.show()
try:
gtk.main()
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()