~parthpanchl/gtg/workspace2

« back to all changes in this revision

Viewing changes to GTG/tools/networkmanager.py

  • Committer: Parin Porecha
  • Date: 2014-01-31 06:59:35 UTC
  • mfrom: (1240.2.94 port-to-gtk3-py3)
  • Revision ID: parinporecha@gmail.com-20140131065935-ub6evnrwpmmm25hz
Merged the gtk3 and python3 port with GTG trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python2
 
1
#!/usr/bin/env python3
2
2
# -*- coding: utf-8 -*-
3
3
# -----------------------------------------------------------------------------
4
4
# Getting Things GNOME! - a personal organizer for the GNOME desktop
18
18
# this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
# -----------------------------------------------------------------------------
20
20
 
21
 
""" Communicate with Network Manager over its D-Bus API
22
 
 
23
 
API spec: http://projects.gnome.org/NetworkManager/developers/api/09/spec.html
24
 
"""
25
 
 
26
 
import dbus
27
 
 
28
 
# A network device is connected, with global network connectivity.
29
 
NM_STATE_CONNECTED_GLOBAL = 70
 
21
""" Communicate with Network Manager """
 
22
 
 
23
from gi.repository import NetworkManager, NMClient
30
24
 
31
25
 
32
26
def is_connection_up():
33
27
    """ Returns True if GTG can access the Internet """
34
 
    bus = dbus.SystemBus()
35
 
    proxy = bus.get_object('org.freedesktop.NetworkManager',
36
 
                           '/org/freedesktop/NetworkManager')
37
 
    network_manager = dbus.Interface(proxy, 'org.freedesktop.NetworkManager')
38
 
 
39
 
    return network_manager.state() == NM_STATE_CONNECTED_GLOBAL
 
28
    state = NMClient.Client().get_state()
 
29
    return state == NetworkManager.State.CONNECTED_GLOBAL
40
30
 
41
31
if __name__ == "__main__":
42
 
    print "is_connection_up() == %s" % is_connection_up()
 
32
    print("is_connection_up() == %s" % is_connection_up())