#!/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 - print generator mappings for optional type' print 'set - 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()