Blame examples/python/dbus/is-wwan-default.py
|
Packit |
5756e2 |
#!/usr/bin/env python
|
|
Packit Service |
87a54e |
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
Packit |
5756e2 |
#
|
|
Packit |
5756e2 |
# Copyright (C) 2011 - 2012 Red Hat, Inc.
|
|
Packit |
5756e2 |
#
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
import dbus, sys
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
# This example indicates whether the default network connection is known to be WWAN
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
bus = dbus.SystemBus()
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
# Exit early if NetworkManager is not running
|
|
Packit |
5756e2 |
proxy = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
|
|
Packit |
5756e2 |
busdaemon = dbus.Interface(proxy, "org.freedesktop.DBus")
|
|
Packit |
5756e2 |
if not busdaemon.NameHasOwner("org.freedesktop.NetworkManager"):
|
|
Packit |
5756e2 |
print("NetworkManager not running")
|
|
Packit |
5756e2 |
sys.exit(1)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
# Get a proxy for the NetworkManager object
|
|
Packit |
5756e2 |
proxy = bus.get_object(
|
|
Packit |
5756e2 |
"org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager"
|
|
Packit |
5756e2 |
)
|
|
Packit |
5756e2 |
props = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
# Shortcut #1, for NM 1.0
|
|
Packit |
5756e2 |
try:
|
|
Packit |
5756e2 |
ctype = props.Get("org.freedesktop.NetworkManager", "PrimaryConnectionType")
|
|
Packit |
5756e2 |
if ctype == "":
|
|
Packit |
5756e2 |
print("No active connection")
|
|
Packit |
5756e2 |
elif ctype in ["gsm", "cdma", "bluetooth"]:
|
|
Packit |
5756e2 |
print("WWAN is default")
|
|
Packit |
5756e2 |
else:
|
|
Packit |
5756e2 |
print("WWAN is not default")
|
|
Packit |
5756e2 |
sys.exit(0)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
except KeyError:
|
|
Packit |
5756e2 |
pass
|