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

« back to all changes in this revision

Viewing changes to ubuntu_sso/networkstate/windows.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:
26
26
from ctypes.wintypes import DWORD
27
27
from threading import Thread
28
28
 
29
 
from twisted.internet import defer
30
29
# pylint: disable=F0401
31
30
from win32com.server.policy import DesignatedWrapPolicy
32
31
from win32com.client import Dispatch
33
32
# pylint: enable=F0401
34
33
 
35
 
from ubuntu_sso.networkstate import NetworkFailException
36
34
from ubuntu_sso.logger import setup_logging
37
35
 
38
36
logger = setup_logging("ubuntu_sso.networkstate")
165
163
 
166
164
 
167
165
def is_machine_connected():
168
 
    """Return a deferred that when fired, will return True if the
169
 
 
170
 
    machine is online."""
171
 
    d = defer.Deferred()
172
 
 
173
 
    def got_state():
174
 
        """The state was retrieved from the Network Manager."""
175
 
        wininet = windll.wininet
176
 
        flags = DWORD()
177
 
        connected = wininet.InternetGetConnectedState(byref(flags), None)
178
 
        return connected == 1
179
 
 
180
 
    # pylint: disable=W0703, W0702
181
 
    try:
182
 
        d.callback(got_state())
183
 
    except Exception, e:
184
 
        logger.exception('is_machine_connected failed with:')
185
 
        d.errback(NetworkFailException(e))
186
 
    return d
187
 
    # pylint: enable=W0703, W0702
 
166
    """The state was retrieved from the Network Manager."""
 
167
    wininet = windll.wininet
 
168
    flags = DWORD()
 
169
    connected = wininet.InternetGetConnectedState(byref(flags), None)
 
170
    return connected == 1
188
171
 
189
172
 
190
173
class NetworkManagerState(object):