~diegosarmentero/ubuntu-sso-client/page-successful

« back to all changes in this revision

Viewing changes to ubuntu_sso/networkstate/linux.py

  • Committer: Diego Sarmentero
  • Date: 2011-11-08 15:06:00 UTC
  • Revision ID: diego.sarmentero@canonical.com-20111108150600-ka10g0zdxarrtkxb
Removed the code from network-detect

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import dbus
23
23
 
24
 
from twisted.internet import defer
25
 
 
26
 
from ubuntu_sso.networkstate import NetworkFailException
27
24
from ubuntu_sso.logger import setup_logging
28
25
logger = setup_logging("ubuntu_sso.networkstate")
29
26
 
128
125
                         error_handler=self.got_error)
129
126
        except Exception, e:  # pylint: disable=W0703
130
127
            self.got_error(e)
131
 
 
132
 
 
133
 
def is_machine_connected():
134
 
    """Return a deferred that when fired, returns if the machine is online."""
135
 
    d = defer.Deferred()
136
 
 
137
 
    def got_state(state):
138
 
        """The state was retrieved from the Network Manager."""
139
 
        result = int(state) in NM_STATE_CONNECTED_LIST
140
 
        d.callback(result)
141
 
 
142
 
    try:
143
 
        network = NetworkManagerState(got_state)
144
 
        network.find_online_state()
145
 
    except Exception, e:  # pylint: disable=W0702
146
 
        logger.exception('is_machine_connected failed with:')
147
 
        d.errback(NetworkFailException(e))
148
 
 
149
 
    return d