1import sys,os,lldb 2def check_has_dir_in_path(dirname): 3 return sys.path.__contains__(dirname); 4 5def ensure_has_dir_in_path(dirname): 6 dirname = os.path.abspath(dirname) 7 if not (check_has_dir_in_path(dirname)): 8 sys.path.append(dirname); 9 10def do_import(debugger,modname): 11 if (len(modname) > 4 and modname[-4:] == '.pyc'): 12 modname = modname[:-4] 13 if (len(modname) > 3 and modname[-3:] == '.py'): 14 modname = modname[:-3] 15 debugger.HandleCommand("script import " + modname) 16 17def pyimport_cmd(debugger, args, result, dict): 18 """Import a Python module given its full path""" 19 if args == "": 20 return "no module path given"; 21 if not (os.sep in args): 22 modname = args 23 ensure_has_dir_in_path('.') 24 else: 25 endofdir = args.rfind(os.sep) 26 modname = args[endofdir+1:] 27 args = args[0:endofdir] 28 ensure_has_dir_in_path(args) 29 do_import(debugger,modname) 30 return None 31