debug-helper.py 2.67 KB
Newer Older
1
#!/usr/bin/python
2
# Copyright (C) 2011 Mathieu Trudel-Lapierre <mathieu.tl@gmail.com>
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

import dbus
import argparse

bus = dbus.SystemBus()

parser = argparse.ArgumentParser(description='Interface to easily control logging levels for NetworkManager, ModemManager, and wpasupplicant.')

# NM options
parser.add_argument('--nm', dest='do_set_nm_logging', action='store',
                   help='modify log level for NetworkManager (debug, info, etc.)')
parser.add_argument('--domains', dest='log_domains', action='store',
                   default=[], nargs='+',
                   help='log "domains" to use with NetworkManager (HW, CORE, etc.)')

# MM options
parser.add_argument('--mm', dest='do_set_mm_logging', action='store',
                   help='modify log level for ModemManager (debug, info, etc.)')

# wpasupplicant options
parser.add_argument('--wpa', dest='do_set_wpa_logging', action='store',
                   help='modify log level for wpasupplicant (debug, msgdump, info, etc.)')

args = parser.parse_args()

if args.do_set_nm_logging:
    #print args.log_domains
    dom_msg = ""
    if args.log_domains:
            dom_msg = " for domains: " + ','.join(args.log_domains)
33
    print("Setting NetworkManager log level to '" + args.do_set_nm_logging + "'" + dom_msg)
34 35 36

    nm_bus = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
    nm = dbus.Interface(nm_bus, dbus_interface='org.freedesktop.NetworkManager')
37 38 39
    nm.SetLogging(args.do_set_nm_logging, ','.join(args.log_domains))

if args.do_set_mm_logging:
40
    print("Setting ModemManager log level to '" + args.do_set_mm_logging + "'")
41 42 43

    mm_bus = bus.get_object('org.freedesktop.ModemManager', '/org/freedesktop/ModemManager')
    mm = dbus.Interface(mm_bus, dbus_interface='org.freedesktop.ModemManager')
44 45 46
    mm.SetLogging(args.do_set_mm_logging)

if args.do_set_wpa_logging:
47
    print("Setting wpa_supplicant log level to '" + args.do_set_wpa_logging + "'")
48

49
    if 'debug' in args.do_set_wpa_logging or 'msgdump' in args.do_set_wpa_logging:
50
        print("Enabling timestamps for wpasupplicant debugging logs")
51 52
        use_timestamps = dbus.Boolean(True, variant_level=1)
    else:
53
        print("Disabling timestamps for wpasupplicant debugging logs")
54 55
        use_timestamps = dbus.Boolean(False, variant_level=1)

56 57
    wpa_bus = bus.get_object('fi.w1.wpa_supplicant1', '/fi/w1/wpa_supplicant1')
    wpa_properties = dbus.Interface(wpa_bus, dbus_interface='org.freedesktop.DBus.Properties')
58 59 60 61
    wpa_properties.Set('fi.w1.wpa_supplicant1', 'DebugTimestamp', use_timestamps)
    wpa_properties.Set('fi.w1.wpa_supplicant1', 'DebugLevel',
                           dbus.String(args.do_set_wpa_logging, variant_level=1))