summaryrefslogtreecommitdiff
path: root/packages/networkmanager/netm-cli-0.2/scan_support.patch
blob: efa3cd89b4da08a7b51fa201dd657e0f10c7a879 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
diff --git a/netm-cli/netm-cli b/netm-cli/netm-cli
index 46c3fa6..0a53036 100755
--- a/netm-cli/netm-cli
+++ b/netm-cli/netm-cli
@@ -29,6 +29,7 @@ __version__ = "0.2"
 import dbus
 import gobject
 import os
+import sys
 from dbus.mainloop.glib import DBusGMainLoop
 from ConfigParser import ConfigParser
 from optparse import OptionParser, OptionGroup
@@ -499,6 +500,14 @@ class NMCLI:
                                     self._we_cipher, self._hexkey,
                                     self._wpa_version, self._key_mgmt)
 
+    def scan(self):
+        """Scan the network and update the NM device struct."""
+        for devname in self.devices:
+            device = self.devices[devname]
+            if device['type'] == DEVICE_TYPE_802_11_WIRELESS:
+                devobj = self.bus.get_object(NM_DBUS_SERVICE, device['path'])
+                devobj.performScan()
+
     def sleep(self):
         """Tell NetworkManager to go into offline mode mode."""
         self.nm.sleep(ignore_reply=True)
@@ -782,7 +791,33 @@ def main():
     nm = NMCLI(device, essid, hexkey, contype, wep_alg, wpa_pairwise,
                                                      options.verbose)
 
+    loop = gobject.MainLoop()
+
     # Main actions
+    if options.networks:
+        print "Performing scan...",
+        sys.stdout.flush()
+        devices = [nm.devices[dev]['path'] for dev in nm.devices if
+                   nm.devices[dev]['type'] == DEVICE_TYPE_802_11_WIRELESS]
+
+        def scan_performed(device):
+            """Scan helper."""
+            if device in devices:
+                devices.remove(device)
+            if not devices:
+                loop.quit()
+
+        nm.bus.add_signal_receiver(
+                handler_function=scan_performed, signal_name="ScanPerformed",
+                path=NM_DBUS_PATH, dbus_interface=NM_DBUS_INTERFACE)
+        nm.scan()
+        loop.run()
+        nm.bus.remove_signal_receiver(
+                handler_or_match=scan_performed, signal_name="ScanPerformed",
+                path=NM_DBUS_PATH, dbus_interface=NM_DBUS_INTERFACE)
+        print "OK"
+        sys.stdout.flush()
+        nm.update_devices()
     if options.monitor:
         nm.set_signals()
     if options.nmstatus:
@@ -811,7 +846,6 @@ def main():
         config.save()
 
     if options.monitor:
-        loop = gobject.MainLoop()
         loop.run()
 
 # Run the program