core_extensions.py 920 B

12345678910111213141516171819202122232425262728
  1. import sys
  2. main_dir = Filename()
  3. if sys.argv and sys.argv[0]:
  4. main_dir = Filename.from_os_specific(sys.argv[0])
  5. if main_dir.empty():
  6. # We must be running in the Python interpreter directly, so return the CWD.
  7. main_dir = ExecutionEnvironment.get_cwd()
  8. else:
  9. main_dir.make_absolute()
  10. main_dir = Filename(main_dir.get_dirname())
  11. ExecutionEnvironment.shadow_environment_variable('MAIN_DIR', main_dir.to_os_specific())
  12. del sys, main_dir
  13. def Dtool_funcToMethod(func, cls, method_name=None):
  14. """Adds func to class so it is an accessible method; use method_name to specify the name to be used for calling the method.
  15. The new method is accessible to any instance immediately."""
  16. #if sys.version_info < (3, 0):
  17. # func.im_class = cls
  18. func.im_func = func
  19. func.im_self = None
  20. if not method_name:
  21. method_name = func.__name__
  22. cls.DtoolClassDict[method_name] = func;