blob: 1d47ad2132fe2a009ae2736539ce9ffa12901a41 [file] [log] [blame]
Kate Stoneb9c1b512016-09-06 20:57:50 +00001import sys
2import os
3import lldb
4
5
Johnny Chen7f01ac32011-10-12 20:47:04 +00006def check_has_dir_in_path(dirname):
Kate Stoneb9c1b512016-09-06 20:57:50 +00007 return sys.path.__contains__(dirname)
8
Johnny Chen7f01ac32011-10-12 20:47:04 +00009
10def ensure_has_dir_in_path(dirname):
Kate Stoneb9c1b512016-09-06 20:57:50 +000011 dirname = os.path.abspath(dirname)
12 if not (check_has_dir_in_path(dirname)):
13 sys.path.append(dirname)
Johnny Chen7f01ac32011-10-12 20:47:04 +000014
Kate Stoneb9c1b512016-09-06 20:57:50 +000015
16def 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 Chen7f01ac32011-10-12 20:47:04 +000023
24def pyimport_cmd(debugger, args, result, dict):
Kate Stoneb9c1b512016-09-06 20:57:50 +000025 """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