| #!/usr/bin/python |
| |
| import dbus, flimflam, sys |
| |
| from optparse import OptionParser |
| |
| parser = OptionParser('Usage: %prog [options...] [var=value...]') |
| parser.add_option('--interface', dest='intf', default='wlan0', |
| help='Device name') |
| (options, args) = parser.parse_args() |
| |
| flim = flimflam.FlimFlam(dbus.SystemBus()) |
| |
| device = flim.FindElementByNameSubstring('Device', options.intf) |
| if device is None: |
| device = flim.FindElementByPropertySubstring('Device', 'Interface', |
| options.intf) |
| |
| if not device: |
| print "Device not found." |
| sys.exit(1) |
| |
| attributes = {'ScanInterval': dbus.UInt16, |
| 'BgscanMethod': dbus.String, |
| 'BgscanShortInterval': dbus.UInt16, |
| 'BgscanSignalThreshold': dbus.Int32} |
| |
| if not args: |
| print "Background scan parameters for %s" % device.object_path |
| props = device.GetProperties(utf8_strings = True) |
| for attr in attributes.keys(): |
| if attr in props: |
| print " %s: %s" % (attr, props[attr]) |
| sys.exit(0) |
| |
| for assignment in args: |
| print 'Assigning parameters on device %s' % (device.object_path) |
| attr, sep, val = assignment.partition('=') |
| if sep != '=' or attr not in attributes.keys(): |
| print 'Bad assignment. Assignment must be in the form:' |
| print ' "var=val", where possible "var" are: %s' % attributes.keys() |
| sys.exit(1) |
| elif val == 'default': |
| device.ClearProperty(attr) |
| else: |
| device.SetProperty(attr, attributes[attr](val)) |