summaryrefslogtreecommitdiffstats
path: root/src/sbin/Bcfg2debug
blob: a5c15b939a06ebbc87ce9ab72479fc92a45fea95 (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
#!/usr/bin/env python

__revision__ = '$Revision$'
'''This tool loads the Bcfg2 core into an interactive debugger'''

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

def input():
    try:
        return raw_input('> ').split(" ")
    except:
        return ['']

if __name__ == '__main__':
    settings = {}
    if '-c' in argv:
        cfile = argv[-1]
    else:
        cfile = '/etc/bcfg2.conf'
    core = Core(cfile)
    while core.fam.fm.pending():
        while core.fam.fm.pending():
            core.fam.HandleEvent()
        sleep(0.5)
    cmd = 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 'set <variable> <value> - set variable for later use'
            print 'settings - display all settings'
            print 'shell - shell out to native python interpreter'
            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__
        else:
            print "Unknown command %s" % cmd[0]
        cmd = input()