environment.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Code licensed under the BSD License.
  2. # http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
  3. # keep methods in alphabetical order
  4. # system imports
  5. import os
  6. import sys
  7. bl_info = {"author": "A. A. Kalugin Jr."}
  8. ################################ CONSTANTS ###############################
  9. ENVIRO = ""
  10. ################################ CONSTANTS ###############################
  11. def get_common_environment_path():
  12. """
  13. Returns a string of the common path of a given environment variable
  14. """
  15. path_list = os.getenv(ENVIRO).split(":")
  16. return os.path.commonprefix(path_list)
  17. def get_environment():
  18. """
  19. Returns three dictionaries of various environment paths.
  20. Build, export and tools in the anki path environment.
  21. """
  22. environment_root = os.path.abspath(get_common_environment_path())
  23. # environment_root = (os.path.abspath(environment_root)) #clean the path
  24. # ANKI Environment
  25. anki_build_path = "{0}/build".format(environment_root)
  26. anki_shaders_path = "{0}/shaders".format(environment_root)
  27. anki_engine_data_path = "{0}/engine_data".format(environment_root)
  28. # Export Environment
  29. export_data_path = "{0}/data".format(environment_root)
  30. export_src_data = "{0}/src_data".format(export_data_path)
  31. export_map_path = "{0}/map".format(export_data_path)
  32. export_temp_dea = "{0}/tmp_scene.dae".format(export_src_data)
  33. export_texture_path = "{0}/texture".format(export_data_path)
  34. # Tools Environment
  35. tool_etcpack_path = "{0}/thirdparty/bin".format(environment_root)
  36. tools_path = "{0}/tools".format(anki_build_path)
  37. tools_scene_path = "{0}/tools/scene".format(environment_root)
  38. tools_texture_path = "{0}/tools/texture".format(environment_root)
  39. # Make the Export Paths
  40. for _path in [export_src_data, export_map_path, export_texture_path]:
  41. if not os.path.exists(_path):
  42. print ("Making directory:", _path)
  43. os.makedirs(_path)
  44. # anki checked out path dictionary
  45. env_dct = {
  46. 'anki_root_path':environment_root+'/',
  47. 'anki_build_path':anki_build_path,
  48. 'anki_engine_data_path':anki_engine_data_path,
  49. 'anki_shaders_path':anki_shaders_path,
  50. }
  51. # export path dictionary
  52. export_dct = {
  53. 'export_src_data':export_src_data,
  54. 'export_map_path':export_map_path,
  55. 'export_texture_path':export_texture_path,
  56. 'export_temp_dea':export_temp_dea,
  57. }
  58. # tools path dictionary
  59. tools_dct = {
  60. 'tool_etcpack_path':tool_etcpack_path,
  61. 'tools_path':tools_path,
  62. 'tools_scene_path':tools_scene_path,
  63. 'tools_texture_path':tools_texture_path,
  64. }
  65. return env_dct, export_dct, tools_dct
  66. def set_environment(anki_env_dct, tools_dct):
  67. """
  68. Sets the environment variable.
  69. """
  70. # Set the environment variable for anki
  71. environment_path = os.pathsep.join(anki_env_dct.values())
  72. os.environ[ENVIRO]=environment_path
  73. # Append the tools path to the $PATH
  74. tools_path = os.pathsep.join(tools_dct.values())
  75. # Create a clean PATH environment varaible
  76. os.environ["PATH"] += os.pathsep + tools_path
  77. path_l = os.getenv("PATH").split(os.pathsep)
  78. new_path = os.pathsep.join(set(path_l))
  79. os.environ["PATH"] = new_path