1# Copyright (C) 2010-2012 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16import traceback 17 18# Auto-load all functions/commands. 19 20# Modules to auto-load, and the paths where those modules exist. 21 22module_dict = { 23 'gdb.function': os.path.join(gdb.PYTHONDIR, 'gdb', 'function'), 24 'gdb.command': os.path.join(gdb.PYTHONDIR, 'gdb', 'command') 25} 26 27# Iterate the dictionary, collating the Python files in each module 28# path. Construct the module name, and import. 29 30for module, location in module_dict.iteritems(): 31 if os.path.exists(location): 32 py_files = filter(lambda x: x.endswith('.py') and x != '__init__.py', 33 os.listdir(location)) 34 35 for py_file in py_files: 36 # Construct from foo.py, gdb.module.foo 37 py_file = module + '.' + py_file[:-3] 38 try: 39 exec('import ' + py_file) 40 except: 41 print >> sys.stderr, traceback.format_exc() 42