~nmu-sscheel/gtg/rework-task-editor

« back to all changes in this revision

Viewing changes to GTG/tools/networkmanager.py

  • Committer: Luca Invernizzi
  • Date: 2010-09-08 14:15:11 UTC
  • mfrom: (825.1.227 liblarch_rebased)
  • Revision ID: invernizzi.l@gmail.com-20100908141511-vsctgw74dj1xp0wi
Liblarch is now in trunk.
Note that performances are still bad and it misses DnD and multi-select
support, but its state is better that the current trunk.
Backends are added in this merge too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/env python
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License along
 
14
# with this program; if not, write to the Free Software Foundation, Inc.,
 
15
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
16
#
 
17
# Copyright (C) 2010 Red Hat, Inc.
 
18
#
 
19
 
 
20
import dbus
 
21
 
 
22
 
 
23
def is_connection_up():
 
24
    '''
 
25
    Returns True if network-manager reports that at least one connection is up
 
26
 
 
27
    @returns bool
 
28
    '''
 
29
    state = False
 
30
    bus = dbus.SystemBus()
 
31
 
 
32
    proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager")
 
33
    manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
 
34
 
 
35
    manager_prop_iface = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
 
36
    active = manager_prop_iface.Get("org.freedesktop.NetworkManager", "ActiveConnections")
 
37
    for a in active:
 
38
        ac_proxy = bus.get_object("org.freedesktop.NetworkManager", a)
 
39
        prop_iface = dbus.Interface(ac_proxy, "org.freedesktop.DBus.Properties")
 
40
        state = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "State")
 
41
 
 
42
        # Connections in NM are a collection of settings that describe everything
 
43
        # needed to connect to a specific network.  Lets get those details so we
 
44
        # can find the user-readable name of the connection.
 
45
        con_path = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "Connection")
 
46
        con_service = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "ServiceName")
 
47
 
 
48
        # ask the provider of the connection for its details
 
49
        service_proxy = bus.get_object(con_service, con_path)
 
50
        con_iface = dbus.Interface(service_proxy, "org.freedesktop.NetworkManagerSettings.Connection")
 
51
        con_details = con_iface.GetSettings()
 
52
        con_name = con_details['connection']['id']
 
53
 
 
54
        if state == 2:   # activated
 
55
            state = True
 
56
    return state
 
57