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