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