1import os 2import sys 3 4pkgRelDir = sys.argv[1] 5pkgFiles = sys.argv[2:] 6 7getFileName = lambda f: os.path.splitext(os.path.basename(f))[0] 8importNames = ', '.join('"{}"'.format(getFileName(f)) for f in pkgFiles) 9 10script = """__all__ = [{import_names}] 11for x in __all__: 12 __import__('lldb.{pkg_name}.' + x) 13 14def __lldb_init_module(debugger, internal_dict): 15 import lldb 16 for x in __all__: 17 submodule = getattr(lldb.{pkg_name}, x) 18 lldb_init = getattr(submodule, '__lldb_init_module', None) 19 if lldb_init: 20 lldb_init(debugger, internal_dict) 21""".format(import_names=importNames, pkg_name=pkgRelDir.replace("/", ".")) 22 23pkgIniFile = os.path.normpath(os.path.join(pkgRelDir, "__init__.py")) 24with open(pkgIniFile, "w") as f: 25 f.write(script) 26