summary refs log tree commit diff
path: root/examples/python/gi
diff options
context:
space:
mode:
Diffstat (limited to 'examples/python/gi')
-rw-r--r--examples/python/gi/Makefile.am4
-rw-r--r--examples/python/gi/Makefile.in24
-rw-r--r--examples/python/gi/README2
-rwxr-xr-xexamples/python/gi/add_connection.py2
-rwxr-xr-xexamples/python/gi/deactivate-all.py83
-rwxr-xr-xexamples/python/gi/firewall-zone.py2
-rwxr-xr-xexamples/python/gi/show-wifi-networks.py64
-rwxr-xr-xexamples/python/gi/update-ip4-method.py2
8 files changed, 168 insertions, 15 deletions
diff --git a/examples/python/gi/Makefile.am b/examples/python/gi/Makefile.am
index dcf2dff0..9c69407f 100644
--- a/examples/python/gi/Makefile.am
+++ b/examples/python/gi/Makefile.am
@@ -6,4 +6,6 @@ EXTRA_DIST = \
 	get_ips.py \
 	add_connection.py \
 	get-active-connections.py \
-	update-ip4-method.py
+	update-ip4-method.py \
+	deactivate-all.py \
+	README
diff --git a/examples/python/gi/Makefile.in b/examples/python/gi/Makefile.in
index 21384364..972092ad 100644
--- a/examples/python/gi/Makefile.in
+++ b/examples/python/gi/Makefile.in
@@ -129,7 +129,7 @@ am__can_run_installinfo = \
     *) (install-info --version) >/dev/null 2>&1;; \
   esac
 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
-am__DIST_COMMON = $(srcdir)/Makefile.in
+am__DIST_COMMON = $(srcdir)/Makefile.in README
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 ALL_LINGUAS = @ALL_LINGUAS@
@@ -146,7 +146,6 @@ BLUEZ5_LIBS = @BLUEZ5_LIBS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
-CKDB_PATH = @CKDB_PATH@
 CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@
 CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@
 CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@
@@ -158,8 +157,6 @@ CXXDEPMODE = @CXXDEPMODE@
 CXXFLAGS = @CXXFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DBUS_CFLAGS = @DBUS_CFLAGS@
-DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@
-DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@
 DBUS_LIBS = @DBUS_LIBS@
 DBUS_SYS_DIR = @DBUS_SYS_DIR@
 DEFS = @DEFS@
@@ -169,6 +166,7 @@ DHCPCD_PATH = @DHCPCD_PATH@
 DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@
 DLLTOOL = @DLLTOOL@
 DNSMASQ_PATH = @DNSMASQ_PATH@
+DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@
 DSYMUTIL = @DSYMUTIL@
 DUMPBIN = @DUMPBIN@
 ECHO_C = @ECHO_C@
@@ -223,16 +221,13 @@ INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@
 INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@
 INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@
 IPTABLES_PATH = @IPTABLES_PATH@
-IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@
-IWMX_SDK_LIBS = @IWMX_SDK_LIBS@
 KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@
 LCOV = @LCOV@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@
+LIBAUDIT_LIBS = @LIBAUDIT_LIBS@
 LIBDL = @LIBDL@
-LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@
-LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@
-LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
 LIBICONV = @LIBICONV@
 LIBINTL = @LIBINTL@
 LIBM = @LIBM@
@@ -269,6 +264,8 @@ NEWT_LIBS = @NEWT_LIBS@
 NM = @NM@
 NMEDIT = @NMEDIT@
 NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@
+NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT = @NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@
+NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT = @NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@
 NM_MAJOR_VERSION = @NM_MAJOR_VERSION@
 NM_MICRO_VERSION = @NM_MICRO_VERSION@
 NM_MINOR_VERSION = @NM_MINOR_VERSION@
@@ -297,7 +294,6 @@ POLKIT_LIBS = @POLKIT_LIBS@
 POSUB = @POSUB@
 PPPD_PATH = @PPPD_PATH@
 PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@
-PPPOE_PATH = @PPPOE_PATH@
 QT_CFLAGS = @QT_CFLAGS@
 QT_LIBS = @QT_LIBS@
 RANLIB = @RANLIB@
@@ -312,6 +308,8 @@ SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@
 SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@
 SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@
 SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@
+SYSTEMD_JOURNAL_CFLAGS = @SYSTEMD_JOURNAL_CFLAGS@
+SYSTEMD_JOURNAL_LIBS = @SYSTEMD_JOURNAL_LIBS@
 SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@
 SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@
 SYSTEM_CA_PATH = @SYSTEM_CA_PATH@
@@ -372,6 +370,7 @@ mkdir_p = @mkdir_p@
 nmbinary = @nmbinary@
 nmconfdir = @nmconfdir@
 nmdatadir = @nmdatadir@
+nmlibdir = @nmlibdir@
 nmrundir = @nmrundir@
 nmstatedir = @nmstatedir@
 oldincludedir = @oldincludedir@
@@ -379,6 +378,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -402,7 +402,9 @@ EXTRA_DIST = \
 	get_ips.py \
 	add_connection.py \
 	get-active-connections.py \
-	update-ip4-method.py
+	update-ip4-method.py \
+	deactivate-all.py \
+	README
 
 all: all-am
 
diff --git a/examples/python/gi/README b/examples/python/gi/README
new file mode 100644
index 00000000..d7773329
--- /dev/null
+++ b/examples/python/gi/README
@@ -0,0 +1,2 @@
+These examples show how to call libnm from Python using
+GObject introspection.
diff --git a/examples/python/gi/add_connection.py b/examples/python/gi/add_connection.py
index 492d66d1..cfb40a9a 100755
--- a/examples/python/gi/add_connection.py
+++ b/examples/python/gi/add_connection.py
@@ -71,7 +71,7 @@ def added_cb(client, result, data):
         client.add_connection_finish(result)
         print("The connection profile has been succesfully added to NetworkManager.")
     except Exception, e:
-        print("Error: %s" % e)
+        sys.stderr.write("Error: %s\n" % e)
     main_loop.quit()
 
 if __name__ == "__main__":
diff --git a/examples/python/gi/deactivate-all.py b/examples/python/gi/deactivate-all.py
new file mode 100755
index 00000000..59842ac2
--- /dev/null
+++ b/examples/python/gi/deactivate-all.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+# vim: ft=python ts=4 sts=4 sw=4 et ai
+
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Copyright 2015 Red Hat, Inc.
+#
+
+#
+# This example deactivates all active connections (of certain type).
+# It makes use of libnm via GObject introspection.
+#
+# Links:
+# https://developer.gnome.org/libnm/1.0/
+# https://wiki.gnome.org/GObjectIntrospection
+# https://wiki.gnome.org/PyGObject
+#
+
+import sys
+import gi
+gi.require_version('NM', '1.0')
+from gi.repository import NM
+
+# suported connection types
+connection_types = {
+  NM.SETTING_VPN_SETTING_NAME,
+  NM.SETTING_WIRELESS_SETTING_NAME,
+  NM.SETTING_WIRED_SETTING_NAME,
+  NM.SETTING_BOND_SETTING_NAME,
+  NM.SETTING_BRIDGE_SETTING_NAME,
+  NM.SETTING_TEAM_SETTING_NAME,
+  NM.SETTING_INFINIBAND_SETTING_NAME,
+  NM.SETTING_PPPOE_SETTING_NAME,
+  NM.SETTING_ADSL_SETTING_NAME,
+  NM.SETTING_BLUETOOTH_SETTING_NAME,
+  NM.SETTING_WIMAX_SETTING_NAME,
+  NM.SETTING_OLPC_MESH_SETTING_NAME,
+  NM.SETTING_GENERIC_SETTING_NAME,
+}
+
+
+if __name__ == "__main__":
+    if len(sys.argv) == 1:
+        ctype = None
+    else:
+        allowed_types = ", ".join(connection_types)
+        if len(sys.argv) == 2:
+            ctype = sys.argv[1]
+            if ctype not in connection_types:
+                sys.exit('Usage: %s [<type>]\nAllowed types: %s' % (sys.argv[0], allowed_types))
+        else:
+            sys.exit('Usage: %s [<type>]\nAllowed types: %s' % (sys.argv[0], allowed_types))
+
+    # create Client object
+    client = NM.Client.new(None)
+
+    # get all active connections
+    connections = client.get_active_connections()
+
+    # deactivate the connections
+    for ac in connections:
+        if ctype == None or ctype == ac.get_connection_type():
+            sys.stdout.write("Deactivating %s (%s)" % (ac.get_id(), ac.get_uuid()))
+            try:
+                client.deactivate_connection(ac, None)
+                sys.stdout.write("\033[32m  -> succeeded\033[0m\n")
+            except Exception, e:
+               sys.stderr.write("\033[31m  -> failed\033[0m (%s)\n" % e.message)
+
diff --git a/examples/python/gi/firewall-zone.py b/examples/python/gi/firewall-zone.py
index a56760ae..979f2acf 100755
--- a/examples/python/gi/firewall-zone.py
+++ b/examples/python/gi/firewall-zone.py
@@ -77,5 +77,5 @@ if __name__ == "__main__":
                 print("'%s' zone set to '%s'") % (c.get_id(), new_zone)
             break
     if not found:
-        print ("Error: connection '%s' not found.") % (con_name)
+        sys.stderr.write("Error: connection '%s' not found.\n") % (con_name)
         main_loop.quit()
diff --git a/examples/python/gi/show-wifi-networks.py b/examples/python/gi/show-wifi-networks.py
index a8bfbbfe..db49b555 100755
--- a/examples/python/gi/show-wifi-networks.py
+++ b/examples/python/gi/show-wifi-networks.py
@@ -52,13 +52,77 @@ def print_device_info(device):
     print info
     print '=' * len(info)
 
+def mode_to_string(mode):
+    if mode == getattr(NM, '80211Mode').INFRA:
+        return "INFRA"
+    if mode == getattr(NM, '80211Mode').ADHOC:
+        return "ADHOC"
+    if mode == getattr(NM, '80211Mode').AP:
+        return "AP"
+    return "UNKNOWN"
+
+def flags_to_string(flags):
+    if flags & getattr(NM, '80211ApFlags').PRIVACY:
+        return "PRIVACY"
+    return "NONE"
+
+def security_flags_to_string(flags):
+    NM_AP_FLAGS = getattr(NM, '80211ApSecurityFlags')
+    str = ""
+    if flags & NM_AP_FLAGS.PAIR_WEP40:
+        str = str + " PAIR_WEP40"
+    if flags & NM_AP_FLAGS.PAIR_WEP104:
+        str = str + " PAIR_WEP104"
+    if flags & NM_AP_FLAGS.PAIR_TKIP:
+        str = str + " PAIR_TKIP"
+    if flags & NM_AP_FLAGS.PAIR_CCMP:
+        str = str + " PAIR_CCMP"
+    if flags & NM_AP_FLAGS.GROUP_WEP40:
+        str = str + " GROUP_WEP40"
+    if flags & NM_AP_FLAGS.GROUP_WEP104:
+        str = str + " GROUP_WEP104"
+    if flags & NM_AP_FLAGS.GROUP_TKIP:
+        str = str + " GROUP_TKIP"
+    if flags & NM_AP_FLAGS.GROUP_CCMP:
+        str = str + " GROUP_CCMP"
+    if flags & NM_AP_FLAGS.KEY_MGMT_PSK:
+        str = str + " KEY_MGMT_PSK"
+    if flags & NM_AP_FLAGS.KEY_MGMT_802_1X:
+        str = str + " KEY_MGMT_802_1X"
+    if str:
+        return str.lstrip()
+    else:
+        return "NONE"
+
+def flags_to_security(flags, wpa_flags, rsn_flags):
+    str = ""
+    if ((flags & getattr(NM, '80211ApFlags').PRIVACY) and
+        (wpa_flags == 0) and (rsn_flags == 0)):
+        str = str  + " WEP"
+    if wpa_flags != 0:
+        str = str + " WPA1"
+    if rsn_flags != 0:
+        str = str + " WPA2"
+    if ((wpa_flags & getattr(NM, '80211ApSecurityFlags').KEY_MGMT_802_1X) or
+        (rsn_flags & getattr(NM, '80211ApSecurityFlags').KEY_MGMT_802_1X)):
+        str = str + " 802.1X"
+    return str.lstrip()
+
 def print_ap_info(ap):
     strength = ap.get_strength()
     frequency = ap.get_frequency()
+    flags = ap.get_flags()
+    wpa_flags = ap.get_wpa_flags()
+    rsn_flags = ap.get_rsn_flags()
     print "SSID:      %s"      % (ssid_to_utf8(ap))
     print "BSSID:     %s"      % (ap.get_bssid())
     print "Frequency: %s"      % (frequency)
     print "Channel:   %s"      % (NM.utils_wifi_freq_to_channel(frequency))
+    print "Mode:      %s"      % (mode_to_string(ap.get_mode()))
+    print "Flags:     %s"      % (flags_to_string(flags))
+    print "WPA flags: %s"      % (security_flags_to_string(wpa_flags))
+    print "RSN flags: %s"      % (security_flags_to_string(rsn_flags))
+    print "Security:  %s"      % (flags_to_security(flags, wpa_flags, rsn_flags))
     print "Strength:  %s %s%%" % (NM.utils_wifi_strength_bars(strength), strength)
     print
 
diff --git a/examples/python/gi/update-ip4-method.py b/examples/python/gi/update-ip4-method.py
index 5e058031..12124599 100755
--- a/examples/python/gi/update-ip4-method.py
+++ b/examples/python/gi/update-ip4-method.py
@@ -82,6 +82,6 @@ if __name__ == "__main__":
             c.commit_changes(True, None)
             print("The connection profile has been updated.")
         except Exception, e:
-            print("Error: %s" % e)
+            sys.stderr.write("Error: %s\n" % e)
         break