summaryrefslogtreecommitdiffstats
path: root/src/sbin/Bcfg2debug
blob: 95508a5b4d2e9c6169ca03ec6d7688218305b81b (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
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
'''This tool loads the Bcfg2 core into an interactive debugger'''
__revision__ = '$Revision$'


from sys import argv
from time import sleep
from Bcfg2.Server.Core import Core, CoreInitError

def get_input():
    '''read commands from stdin'''
    try:
        return raw_input('> ').split(" ")
    except:
        return ['']

if __name__ == '__main__':
    settings = {}
    if '-c' in argv:
        cfile = argv[-1]
    else:
        cfile = '/etc/bcfg2.conf'
    try:
        core = Core({}, cfile)
    except CoreInitError, msg:
        print "Core load failed because %s" % msg
        raise SystemExit, 1
    for i in range(25):
        core.fam.Service()
        sleep(0.5)
    cmd = get_input()
    while cmd != ['']:
        if cmd[0] in ['exit', 'quit']:
            raise SystemExit, 0
        elif cmd[0] == 'generators':
            for generator in core.generators:
                print generator.__version__
        elif cmd[0] == 'help':
            print 'Commands:'
            print 'exit - quit'
            print 'generators - list current versions of generators'
            print 'help - print this text'
            print 'mappings <type*> - print generator mappings for optional type'
            print 'set <variable> <value> - set variable for later use'
            print 'settings - display all settings'
            print 'shell - shell out to native python interpreter'
            print 'update - process pending fam events'
            print 'version - print version of this tool'
        elif cmd[0] == 'set':
            settings[cmd[1]] = cmd[2]
        elif cmd[0] == 'settings':
            for (key, value) in settings.iteritems():
                print "%s --> %s" % (key, value)
        elif cmd[0] == 'shell':
            cmd = ['']
            continue
        elif cmd[0] == 'version':
            print 'Bcfg2debug v. %s' % __revision__
        elif cmd[0] == 'mappings':
            # dump all mappings unless type specified
            for generator in core.generators:
                print "Generator -> ", generator.__name__
                for key, value in generator.__provides__.iteritems():
                    for instance in generator.__provides__[key].keys():
                        print "   ", key, instance
        elif cmd[0] == 'update':
            core.fam.Service()
        else:
            print "Unknown command %s" % cmd[0]
        cmd = get_input()