Jason Abele | cf5d651 | 2013-03-11 17:15:28 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | # usage: |
| 7 | # list-active-service [[service-type [[service-prop1] ... [service-propN]]]] |
| 8 | # service-type: shill service type: wifi, ethernet, etc |
| 9 | # service-propX: shill service property: Connectable, Name, etc |
| 10 | # |
| 11 | # Queries the currently active services from shill, optionally filtering |
| 12 | # for specific service types and properties |
| 13 | |
| 14 | import dbus, flimflam, sys |
| 15 | |
| 16 | def main(): |
| 17 | if len(sys.argv) > 1 and str(sys.argv[1]) in ['-h','-?','--help','-help']: |
| 18 | print('usage: %s [[service-type [[service-prop1] ... [service-propN]]]]' |
| 19 | % str(sys.argv[0])) |
| 20 | return |
| 21 | |
| 22 | flim = flimflam.FlimFlam(dbus.SystemBus()) |
| 23 | |
| 24 | for service in flim.GetObjectList('Service'): |
| 25 | properties = service.GetProperties(utf8_strings = True) |
| 26 | if not bool(properties['IsActive']): |
| 27 | continue |
| 28 | |
| 29 | if len(sys.argv) > 1 and str(properties['Type']) != sys.argv[1]: |
| 30 | continue |
| 31 | |
| 32 | if len(sys.argv) > 2: |
| 33 | requested_keys = sys.argv[2:] |
| 34 | else: |
| 35 | print('[ %s ]' % service.object_path) |
| 36 | requested_keys = properties.keys() |
| 37 | |
| 38 | for key in requested_keys: |
| 39 | print(' %s = %s' % ( |
| 40 | key, flimflam.convert_dbus_value(properties[key], 4))) |
| 41 | |
| 42 | if __name__ == '__main__': |
| 43 | main() |