[libc] Deprecate LLVM_ENABLE_PROJECTS in favor of LLVM_ENABLE_RUNTIMES. (#117265)
[llvm-project.git] / lldb / examples / customization / import-python / importcmd.py
blob7d90078f7d8c45c90879665ea5d639b089f1c903
1 import sys
2 import os
3 import lldb
6 def check_has_dir_in_path(dirname):
7 return sys.path.__contains__(dirname)
10 def ensure_has_dir_in_path(dirname):
11 dirname = os.path.abspath(dirname)
12 if not (check_has_dir_in_path(dirname)):
13 sys.path.append(dirname)
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)
24 def pyimport_cmd(debugger, args, result, dict):
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