summaryrefslogtreecommitdiff
path: root/tools/debug-helper.py
blob: 07338242dbdbae884802d953f9d3d6e30c9a90eb (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
#!/usr/bin/python
# Copyright (C) 2011 Mathieu Trudel-Lapierre <mathieu.tl@gmail.com>

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)
    print "Setting NetworkManager log level to '" + args.do_set_nm_logging + "'" + dom_msg

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

if args.do_set_mm_logging:
    print "Setting ModemManager log level to '" + args.do_set_mm_logging + "'"

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

if args.do_set_wpa_logging:
    print "Setting wpa_supplicant log level to '" + args.do_set_wpa_logging + "'"

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

    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')
    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))