Ticket #230: 0001-initial-review.patch

File 0001-initial-review.patch, 11.4 KB (added by dsd, 14 years ago)

actually its an incremental patch, hopefully makes review easier?

  • extensions/deviceicon/network.py

    From 160430eaba2984673d56c07a0fb707252e53bc5a Mon Sep 17 00:00:00 2001
    From: Daniel Drake <dsd@laptop.org>
    Date: Mon, 4 Jan 2010 12:48:01 +0000
    Subject: [PATCH] initial review
    
    ---
     extensions/deviceicon/network.py |   11 +++++--
     src/jarabe/desktop/meshbox.py    |   22 ++++---------
     src/jarabe/model/olpcmesh.py     |   63 +++++++++++++++++++------------------
     3 files changed, 47 insertions(+), 49 deletions(-)
    
    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index 875b8e4..2dabf2f 100644
    a b class OlpcMeshDeviceView(ToolButton): 
    567567
    568568    def _update_text(self):
    569569        state = self._device_state
    570         text = _("Mesh Network")
    571570        if state in (network.DEVICE_STATE_PREPARE, network.DEVICE_STATE_CONFIG,
    572571                     network.DEVICE_STATE_NEED_AUTH,
    573572                     network.DEVICE_STATE_IP_CONFIG,
    574573                     network.DEVICE_STATE_ACTIVATED):
    575             text += " " + str(self._channel)
     574            text = _("Mesh Network %d") % self._channel
     575        else:
     576            text = _("Mesh Network")
    576577        self._palette.props.primary_text = text
    577578
    578579    def _update(self):
    class WirelessDeviceObserver(object): 
    647648        self._device_view = None
    648649        self._tray = tray
    649650
    650         self._device_view = view_class(self._device)
     651        if view_class == WirelessDeviceView:
     652            self._device_view = WirelessDeviceView(self._device)
     653        elif view_class == OlpcMeshDeviceView:
     654            self._device_view = OlpcMeshDeviceView(self._device)
     655
    651656        self._tray.add_device(self._device_view)
    652657
    653658    def disconnect(self):
  • src/jarabe/desktop/meshbox.py

    diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
    index 70c836a..e78b5e1 100644
    a b class OlpcMeshView(CanvasPulsingIcon): 
    459459        self._device_state = None
    460460        self._connection = None
    461461        self._active = False
    462         device = mesh_mgr.meshdev
     462        device = mesh_mgr.mesh_device
    463463
    464464        self.connect('button-release-event', self.__button_release_event_cb)
    465465
    class OlpcMeshView(CanvasPulsingIcon): 
    489489        self.set_palette(self._palette)
    490490
    491491    def _create_palette(self):
    492         p = palette.Palette(_("Mesh Network") + " " + str(self._channel))
     492        _palette = palette.Palette(_("Mesh Network %d") % self._channel)
    493493
    494494        self._connect_item = MenuItem(_('Connect'), 'dialog-ok')
    495495        self._connect_item.connect('activate', self.__connect_activate_cb)
    496         p.menu.append(self._connect_item)
     496        _palette.menu.append(self._connect_item)
    497497
    498         self._disconnect_item = MenuItem(_('Disconnect'), 'media-eject')
    499         self._disconnect_item.connect('activate',
    500                                       self._disconnect_activate_cb)
    501         p.menu.append(self._disconnect_item)
    502 
    503         return p
     498        return _palette
    504499
    505500    def __get_device_state_reply_cb(self, state):
    506501        self._device_state = state
    class OlpcMeshView(CanvasPulsingIcon): 
    560555        else:
    561556            self.props.base_color = profile.get_color()
    562557
    563     def _disconnect_activate_cb(self, item):
    564         pass
    565 
    566558    def __connect_activate_cb(self, icon):
    567559        self._connect()
    568560
    class MeshBox(gtk.VBox): 
    11231115        self._layout.add(icon)
    11241116        self._mesh.append(icon)
    11251117
    1126     def enable_olpc_mesh(self, meshdev):
    1127         mesh_mgr = OlpcMeshManager(meshdev)
     1118    def enable_olpc_mesh(self, mesh_device):
     1119        mesh_mgr = OlpcMeshManager(mesh_device)
    11281120        self._add_olpc_mesh_icon(mesh_mgr, 1)
    11291121        self._add_olpc_mesh_icon(mesh_mgr, 6)
    11301122        self._add_olpc_mesh_icon(mesh_mgr, 11)
    class MeshBox(gtk.VBox): 
    11411133            self._layout.remove(net)
    11421134            del self.wireless_networks[hash]
    11431135
    1144     def disable_olpc_mesh(self, meshdev):
     1136    def disable_olpc_mesh(self, mesh_device):
    11451137        for icon in self._mesh:
    11461138            icon.disconnect()
    11471139            self._layout.remove(icon)
  • src/jarabe/model/olpcmesh.py

    diff --git a/src/jarabe/model/olpcmesh.py b/src/jarabe/model/olpcmesh.py
    index 26c8b53..0935de5 100644
    a b DEVICE_STATE_ACTIVATED = 8 
    4444DEVICE_STATE_FAILED = 9
    4545
    4646class OlpcMeshManager(object):
    47     def __init__(self, meshdev):
     47    def __init__(self, mesh_device):
    4848        self._bus = dbus.SystemBus()
    49         self.meshdev = meshdev
     49        self.mesh_device = mesh_device
    5050
    5151        # let's make sure we know the companion device early on
    5252        # (synchronous request)
    53         props = dbus.Interface(meshdev, 'org.freedesktop.DBus.Properties')
    54         ethdev_o = props.Get(_NM_OLPC_MESH_IFACE, 'Companion')
    55         self.ethdev = self._bus.get_object(_NM_SERVICE, ethdev_o)
     53        props = dbus.Interface(mesh_device, 'org.freedesktop.DBus.Properties')
     54        eth_device_o = props.Get(_NM_OLPC_MESH_IFACE, 'Companion')
     55        self.eth_device = self._bus.get_object(_NM_SERVICE, eth_device_o)
    5656
    5757        # asynchronously learn about mesh status
    5858        props.Get(_NM_DEVICE_IFACE, 'State',
    5959                  reply_handler=self.__get_mesh_state_reply_cb,
    6060                  error_handler=self.__get_state_error_cb)
    6161        # and companion
    62         props = dbus.Interface(self.ethdev, 'org.freedesktop.DBus.Properties')
     62        props = dbus.Interface(self.eth_device,
     63                               'org.freedesktop.DBus.Properties')
    6364        props.Get(_NM_DEVICE_IFACE, 'State',
    6465                  reply_handler=self.__get_eth_state_reply_cb,
    6566                  error_handler=self.__get_state_error_cb)
    class OlpcMeshManager(object): 
    6869        # we find one that works
    6970        self._connection_queue = []
    7071
    71         self._bus.add_signal_receiver(self.__ethdev_state_changed_cb,
     72        self._bus.add_signal_receiver(self.__eth_device_state_changed_cb,
    7273                                      signal_name='StateChanged',
    73                                       path=self.ethdev.object_path,
     74                                      path=self.eth_device.object_path,
    7475                                      dbus_interface=_NM_DEVICE_IFACE)
    7576
    7677        self._bus.add_signal_receiver(self.__mshdev_state_changed_cb,
    7778                                      signal_name='StateChanged',
    78                                       path=self.meshdev.object_path,
     79                                      path=self.mesh_device.object_path,
    7980                                      dbus_interface=_NM_DEVICE_IFACE)
    8081
    8182        self._idle_source = 0
    82         self._meshdev_state = DEVICE_STATE_UNKNOWN
    83         self._ethdev_state = DEVICE_STATE_UNKNOWN
     83        self._mesh_device_state = DEVICE_STATE_UNKNOWN
     84        self._eth_device_state = DEVICE_STATE_UNKNOWN
    8485
    8586        if len(network.get_settings().connections) == 0:
    8687            # if there are no configured APs, start meshing immediately
    class OlpcMeshManager(object): 
    9495        logging.debug('Error getting the device state: %s', err)
    9596
    9697    def __get_mesh_state_reply_cb(self, state):
    97         self._meshdev_state = state
     98        self._mesh_device_state = state
    9899        self._maybe_schedule_idle_check()
    99100
    100101    def __get_eth_state_reply_cb(self, state):
    101         self._ethdev_state = state
     102        self._eth_device_state = state
    102103        self._maybe_schedule_idle_check()
    103104
    104     def __ethdev_state_changed_cb(self, new_state, old_state, reason):
    105         self._ethdev_state = new_state
     105    def __eth_device_state_changed_cb(self, new_state, old_state, reason):
     106        """If a connection is activated on the eth device, stop trying our
     107        automatic connections."""
     108        self._eth_device_state = new_state
    106109        self._maybe_schedule_idle_check()
    107110
    108         # If a connection is activated on the eth device, stop trying our
    109         # automatic connections
    110111        if new_state >= DEVICE_STATE_PREPARE \
    111112                and new_state <= DEVICE_STATE_ACTIVATED \
    112113                and len(self._connection_queue) > 0:
    113114            self._connection_queue = []
    114115
    115116    def __mshdev_state_changed_cb(self, new_state, old_state, reason):
    116         self._meshdev_state = new_state
     117        self._mesh_device_state = new_state
    117118        self._maybe_schedule_idle_check()
    118119
    119120        if new_state == DEVICE_STATE_FAILED:
    class OlpcMeshManager(object): 
    125126            self._connection_queue = []
    126127
    127128    def _maybe_schedule_idle_check(self):
    128         # if both devices are disconnected, wait 10 seconds for some activity
    129         # and if nothing happens then we can start automatic meshing
    130         if self._meshdev_state == DEVICE_STATE_DISCONNECTED \
    131                 and self._ethdev_state == DEVICE_STATE_DISCONNECTED:
     129        """If both devices are disconnected, wait 10 seconds for some activity
     130        and if nothing happens then we can start automatic meshing."""
     131        if self._mesh_device_state == DEVICE_STATE_DISCONNECTED \
     132                and self._eth_device_state == DEVICE_STATE_DISCONNECTED:
    132133            if self._idle_source != 0:
    133134                gobject.source_remove(self._idle_source)
    134135            self._idle_source = gobject.timeout_add_seconds(10, self._idle_check)
    135136
    136137    def _idle_check(self):
    137         if self._meshdev_state == DEVICE_STATE_DISCONNECTED \
    138                 and self._ethdev_state == DEVICE_STATE_DISCONNECTED:
     138        if self._mesh_device_state == DEVICE_STATE_DISCONNECTED \
     139                and self._eth_device_state == DEVICE_STATE_DISCONNECTED:
    139140            logging.debug("starting automesh due to inactivity")
    140141            self.start_automesh()
    141142        return False
    class OlpcMeshManager(object): 
    164165        connection = self._make_connection(channel, anycast_addr)
    165166
    166167        netmgr.ActivateConnection(network.SETTINGS_SERVICE, connection.path,
    167                                   self.meshdev.object_path,
    168                                   self.meshdev.object_path,
     168                                  self.mesh_device.object_path,
     169                                  self.mesh_device.object_path,
    169170                                  reply_handler=self.__activate_reply_cb,
    170171                                  error_handler=self.__activate_error_cb)
    171172
    class OlpcMeshManager(object): 
    176177        channel, anycast = self._connection_queue.pop()
    177178        self.activate_connection(channel, anycast)
    178179
    179     # Activate a mesh connection on a user-specified channel
    180     # Looks for XS first, then resorts to simple mesh
    181180    def user_activate_channel(self, channel):
     181        """Activate a mesh connection on a user-specified channel.
     182        Looks for XS first, then resorts to simple mesh."""
    182183        # Empties any existing queue in order to abort any connection attempt
    183184        # that was already happening
    184185        self._connection_queue = [ (channel, None), (channel, _XS_ANYCAST) ]
    185186        self._activate_from_queue()
    186187
    187     # Start meshing, intended for when there are no better networks to
    188     # connect to. First looks for XS on all channels, then falls back to
    189     # simple mesh on channel 1.
    190188    def start_automesh(self):
     189        """Start meshing automatically, intended when there are no better
     190        networks to connect to. First looks for XS on all channels, then falls
     191        back to simple mesh on channel 1."""
    191192        # Empties any existing queue in order to abort any connection attempt
    192193        # that was already happening
    193194        self._connection_queue = [