__init__.py 635 B

1234567891011121314151617181920212223
  1. import importlib
  2. import os
  3. from ._core import ShellDetectionFailure
  4. __version__ = "1.5.4"
  5. def detect_shell(pid=None, max_depth=10):
  6. name = os.name
  7. try:
  8. impl = importlib.import_module(".{}".format(name), __name__)
  9. except ImportError:
  10. message = "Shell detection not implemented for {0!r}".format(name)
  11. raise RuntimeError(message)
  12. try:
  13. get_shell = impl.get_shell
  14. except AttributeError:
  15. raise RuntimeError("get_shell not implemented for {0!r}".format(name))
  16. shell = get_shell(pid, max_depth=max_depth)
  17. if shell:
  18. return shell
  19. raise ShellDetectionFailure()