environment.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. bl_info = {"author": "A. A. Kalugin Jr."}
  7. ################################ CONSTANTS ###############################
  8. ENVIRO = ""
  9. ################################ CONSTANTS ###############################
  10. def get_common_environment_path():
  11. """
  12. Returns a string of the common path of a given environment variable
  13. """
  14. path_list = os.getenv(ENVIRO).split(":")
  15. return os.path.commonprefix(path_list)
  16. def get_environment():
  17. """
  18. Returns three dictionaries of various environment paths.
  19. Build, export and tools in the anki path environment.
  20. """
  21. environment_root = os.path.abspath(get_common_environment_path())
  22. # environment_root = (os.path.abspath(environment_root)) #clean the path
  23. # ANKI Environment
  24. anki_build_path = "{0}/build".format(environment_root)
  25. anki_shaders_path = "{0}/shaders".format(environment_root)
  26. anki_engine_data_path = "{0}/engine_data".format(environment_root)
  27. # Export Environment
  28. export_data_path = "{0}/data".format(environment_root)
  29. export_src_data = "{0}/src_data".format(export_data_path)
  30. export_map_path = "{0}/map".format(export_data_path)
  31. export_temp_dea = "{0}/tmp_scene.dae".format(export_src_data)
  32. export_texture_path = "{0}/texture".format(export_data_path)
  33. # Tools Environment
  34. tool_etcpack_path = "{0}/thirdparty/bin".format(environment_root)
  35. tools_path = "{0}/tools".format(anki_build_path)
  36. tools_scene_path = "{0}/scene".format(tools_path)
  37. tools_texture_path = "{0}/texture".format(tools_path)
  38. # Make the Export Paths
  39. for _path in [export_src_data, export_map_path, export_texture_path]:
  40. if not os.path.exists(_path):
  41. print ("Making directory:", _path)
  42. os.makedirs(_path)
  43. env_dct = {
  44. 'environment_root':environment_root+'/',
  45. 'anki_build_path':anki_build_path,
  46. 'anki_engine_data_path':anki_engine_data_path,
  47. 'anki_shaders_path':anki_shaders_path,
  48. }
  49. tools_dct = {
  50. 'tool_etcpack_path':tool_etcpack_path,
  51. 'tools_path':tools_path,
  52. 'tools_scene_path':tools_scene_path,
  53. 'tools_texture_path':tools_texture_path,
  54. }
  55. export_dct = {
  56. 'export_src_data':export_src_data,
  57. 'export_map_path':export_map_path,
  58. 'export_texture_path':export_texture_path,
  59. 'export_temp_dea':export_temp_dea,
  60. }
  61. return env_dct, export_dct, tools_dct
  62. def set_environment(anki_env_dct, tools_dct):
  63. """
  64. Sets the environment variable.
  65. """
  66. environment_path = ':'.join(anki_env_dct.values())
  67. os.environ[ENVIRO]=environment_path
  68. environment_path = ':'.join(tools_dct.values())
  69. os.environ[ENVIRO]=environment_path