pm_project.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. import os
  4. import sys
  5. import subprocess
  6. from settings import settings
  7. from settings import talk
  8. from studio import studio_gtk
  9. from studio_console import sc_main
  10. from gi.repository import GLib
  11. def new(name):
  12. # Removing all the bad characters
  13. name = name.replace("/","_").replace(" ", "_")\
  14. .replace('"',"_").replace("(","_").replace(")","_").replace("'","_")\
  15. .replace("[","_").replace("]","_").replace("{","_").replace("}","_")
  16. # This function makes a new project.
  17. # If there is not such a folder. As in the settings.
  18. if not os.path.exists(settings.read("New-Project-Folder")):
  19. return False
  20. # If there is a project folder, or a file with it's name.
  21. elif os.path.exists(settings.read("New-Project-Folder")+"/"+name):
  22. return False
  23. #If all good
  24. else:
  25. try:
  26. fn = settings.read("New-Project-Folder")+"/"+name
  27. os.mkdir(fn)
  28. os.mkdir(fn+"/rnd")
  29. os.mkdir(fn+"/dev")
  30. os.mkdir(fn+"/ast")
  31. os.mkdir(fn+"/pln")
  32. os.mkdir(fn+"/mus")
  33. os.mkdir(fn+"/set")
  34. for f in ["chr","loc","veh","obj"]:
  35. os.mkdir(fn+"/ast/"+f)
  36. os.mkdir(fn+"/dev/"+f)
  37. register_project(fn)
  38. return True
  39. # If it fails to create a project for some reason.
  40. except:
  41. return False
  42. def register_project(path):
  43. prevdata = ""
  44. try:
  45. data = open("project_manager/projects_list.data")
  46. prevdata = data.read()
  47. except:
  48. pass
  49. data = open("project_manager/projects_list.data", "w")
  50. if path not in prevdata:
  51. data.write(prevdata+path+"\n")
  52. else:
  53. data.write(prevdata)
  54. data.close()
  55. def get_list():
  56. ret = []
  57. try:
  58. data = open("project_manager/projects_list.data")
  59. data = data.read()
  60. data = data.split("\n")
  61. for line in data:
  62. if os.path.exists(line):
  63. ret.append(line)
  64. except:
  65. pass
  66. return ret
  67. def scan():
  68. ret = []
  69. #scan the system for "ast/chr" a folder that accurs in a project
  70. for i in [x[0] for x in os.walk("/")]:
  71. if i.endswith("/ast/chr"):
  72. ret.append(i.replace("/ast/chr", ""))
  73. register_project(i.replace("/ast/chr", ""))
  74. return ret
  75. def load(path, win=False):
  76. #first let's figure out if it's an old Blender-Organizer
  77. #or a new VCStudio project.
  78. #if new
  79. if not is_legacy(path):
  80. # Console mode
  81. if len(sys.argv) > 1 and sys.argv[1] == "-c":
  82. sc_main.run(path)
  83. else:
  84. studio_gtk.run(path, win)
  85. #old organizer
  86. else:
  87. if not os.path.exists(path+"/MAIN_FILE"):
  88. n = "blender-organizer"
  89. else:
  90. n = open(path+"/MAIN_FILE")
  91. n = n.read()
  92. #let's look if there is python2 since it's legacy software
  93. if not os.system("python2 -V") == 0:
  94. return "No python2"
  95. #loading the python2 thingy
  96. sh = open("/tmp/run_legacy_organizer.sh", "w")
  97. sh.write("cd "+path+"\n")
  98. sh.write("python2 "+n+"\n")
  99. sh.write('read -p ""')
  100. sh.close()
  101. if not os.path.exists(path+"/MAIN_FILE"):
  102. os.system("gnome-terminal -- sh /tmp/run_legacy_organizer.sh")
  103. else:
  104. subprocess.Popen(["sh", "/tmp/run_legacy_organizer.sh"])
  105. if win:
  106. win.destroy()
  107. def is_legacy(project):
  108. # This function checks whether a given project is a Legacy ( Blender -
  109. # Organizer ) project.
  110. if not os.path.exists(project+"/set"):
  111. return True
  112. else:
  113. return False