574582e676068988a06ee1911fabe0bed0f97d75
[wifihood] / wifimap / wifiscan.py
1
2 import osso
3
4 import time
5
6 import gps
7
8 import gobject
9
10 class Scanner ( gps.GPSObject ) :
11
12     def __init__ ( self , widget=None , ifname="wlan0" ) :
13         gps.GPSObject.__init__( self , widget )
14         self.osso_context = osso.Context("wifi_scanner", "2.0", False)
15         osso_rpc = osso.Rpc(self.osso_context)
16         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
17         self._timer = None
18
19     def start ( self ) :
20         osso_rpc = osso.Rpc(self.osso_context)
21         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
22
23     def stop ( self ) :
24         osso_rpc = osso.Rpc(self.osso_context)
25         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
26
27     def scan ( self ) :
28         osso_rpc = osso.Rpc(self.osso_context)
29         try :
30             scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "scan", wait_reply = True)
31         except Exception , ex :
32             osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
33             return True
34         out_str = ""
35         for net in scan_out.split() :
36             items = net.rsplit(":", 1)
37             out_str += " %s %s" % ( items[0] , items[1] )
38         if self._debug :
39         # Use osso or hildon for notes ???
40             osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) )
41         #    hildon.hildon_banner_show_information( self._parent , "icon_path" , "Found %d APs" % len(scan_out) )
42         else :
43             fd = open( "/home/user/MyDocs/wiscan_gui.info" , 'a' )
44             fd.write( "%s %s%s\n" % ( time.time() , self.gps_info , out_str ) )
45             fd.close()
46             if self.satellites :
47                 loclist = open( "/home/user/MyDocs/location.info" , 'a' )
48                 loclist.write ( "%s\n" % ( self.satellites ,) )
49                 loclist.close()
50             if self.cell_info :
51                 celllist = open( "/home/user/MyDocs/cell.info" , 'a' )
52                 celllist.write ( "%s\n" % ( self.cell_info ,) )
53                 celllist.close()
54
55         return True
56
57
58 gobject.type_register(Scanner)
59