troubleshooter.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. import os
  4. w, h = os.get_terminal_size()
  5. from settings import settings
  6. from settings import talk
  7. from troubleshooter import fix
  8. commands = []
  9. def completer(text, state):
  10. options = [i for i in commands if i.startswith(text)]
  11. if state < len(options):
  12. return options[state]
  13. else:
  14. return None
  15. try:
  16. import readline
  17. readline.parse_and_bind("tab: complete")
  18. readline.set_completer(completer)
  19. except:
  20. print("NO TABS, SORRY!")
  21. def cls():
  22. #cleaning the terminal
  23. os.system("clear")
  24. global w
  25. global h
  26. w, h = os.get_terminal_size()
  27. if (w % 2) == 0:
  28. w = w - 1
  29. def output(form, text=""):
  30. #Basically a fancy print() function
  31. while len(text) < w:
  32. text = text + " "
  33. print(form + text)
  34. # COFIGURING LANGUAGE
  35. def lang_setting():
  36. title = "TYPE YOUR LANGUAGE AND HIT ENTER"
  37. while True:
  38. cls()
  39. #getting the configuration
  40. language = settings.read("Language")
  41. # Testing if I cal load the language file.
  42. try:
  43. open("settings/languages/"+language+".data")
  44. return
  45. except:
  46. pass
  47. talk.alert("Select Language. Look in console.")
  48. # Getting list of available languages
  49. all_langs = settings.list_languages()
  50. # Make them auto-comelitable
  51. global commands
  52. commands = []
  53. for lang in all_langs:
  54. commands.append(lang)
  55. # Counting them
  56. len_langs = len(all_langs)
  57. output("\033[1;44m")
  58. #Title
  59. output("\033[1;44m", \
  60. " " * int(round((w-len(title))/2)) \
  61. + title + \
  62. " " * int((w-len(title))/2) \
  63. )
  64. output("\033[1;44m")
  65. for raws in range(int((h-5-len_langs)/2)):
  66. output("\033[1;40m")
  67. for lang in all_langs:
  68. output("\033[1;40m", \
  69. " " * int(round((w-len(lang))/2)) \
  70. + lang + \
  71. " " * int((w-len(lang))/2) \
  72. )
  73. for raws in range(int((h-5-len_langs)/2)):
  74. output("\033[1;40m")
  75. print("\033[1;m")
  76. # Trying to write language setting.
  77. command = input(":")
  78. if command != "":
  79. if command not in all_langs:
  80. title = "THERE IS NO " + command + " FILE"
  81. else:
  82. settings.write("Language",command)
  83. return
  84. lang_setting()
  85. def modules_test(Modules, title, setting):
  86. # TESTING THAT MODULES ARE INSTALLED CORRECTLY
  87. cls()
  88. import time # IK it's crazy but user needs to understand what's
  89. # going on. So there be some delay between them.
  90. title = talk.text(title)
  91. def drawmodules():
  92. cls()
  93. output("\033[1;44m")
  94. output("\033[1;44m", \
  95. " " * int((w-len(title))/2) \
  96. + title + \
  97. " " * int((w-len(title))/2) \
  98. )
  99. output("\033[1;44m")
  100. for raws in range(int((h-5-len(Modules))/2)):
  101. output("\033[1;40m")
  102. for mod2 in Modules:
  103. if Modules[mod2] == None:
  104. ans = mod2
  105. output("\033[1;40m", " "+ans)
  106. elif Modules[mod2] == True:
  107. ans = mod2 + " "*int(w/2-len(mod2)) + talk.text("checked")
  108. output("\033[1;42m", " "+ans)
  109. else:
  110. ans = mod2 + " "*int(w/2-len(mod2)) + talk.text("failed")
  111. output("\033[1;41m", " "+ans)
  112. for raws in range(int((h-6-len(Modules))/2)):
  113. output("\033[1;40m")
  114. errors = 0
  115. for mod in Modules:
  116. drawmodules()
  117. try:
  118. try:
  119. exec( "import " + mod)
  120. Modules[mod] = True
  121. except:
  122. Modules[mod] = False
  123. errors = errors + 1
  124. except:
  125. pass
  126. time.sleep(0.1)
  127. drawmodules()
  128. if errors:
  129. global commands
  130. commands = ["Fix"]
  131. talk.alert(talk.text("missingmodulenotification"))
  132. title = str(errors)+" "+talk.text("missingmoduleserror")
  133. output("\033[1;40m\033[1;31m", \
  134. " " * int((w-len(title))/2) \
  135. + title + \
  136. " " * int((w-len(title))/2) \
  137. )
  138. #fix thing
  139. print("\033[1;m")
  140. command = input(":")
  141. if command == "Fix":
  142. fix.autofix(Modules)
  143. else:
  144. #if no errors
  145. settings.write(setting, "Checked-by-troubleshooter")
  146. print("\033[1;m")
  147. Modules = {
  148. "os":None,
  149. "gi":None,
  150. "gi.repository.Gtk":None,
  151. "gi.repository.GLib":None,
  152. "cairo":None,
  153. "PIL":None,
  154. "PIL.Image":None,
  155. "subprocess":None,
  156. "datetime":None,
  157. "sys":None,
  158. "urllib":None,
  159. "urllib3":None,
  160. "socket":None,
  161. "readline":None,
  162. "json":None,
  163. "threading":None
  164. }
  165. modules_test(Modules, "checkingpythonmodules", "Python-is-good")
  166. missing = []
  167. try:
  168. # Let's get the list of files that supposed to be in here.
  169. udata = open("settings/update.data")
  170. udata = udata.read()
  171. udata = udata.split("\n")
  172. # Let's parse it
  173. files = []
  174. for f in udata:
  175. if f and not f.startswith("VERSION") and not f.startswith("[") \
  176. and not f.startswith("#") and f not in files:
  177. files.append(f)
  178. Modules = {}
  179. num = 1
  180. for f in sorted(files):
  181. if num == h-5:
  182. modules_test(Modules, "checkingpartsoftheprogramm", "VCStudio-is-good")
  183. Modules = {}
  184. num = 1
  185. try:
  186. test = open(f)
  187. test = test.read()
  188. if f.endswith(".py") and not "import bpy" in test\
  189. and "-" not in f and f != "run.py" and not "network" in f:
  190. Modules[f.replace("/", ".")[:-3]] = None
  191. num += 1
  192. except:
  193. if not os.path.exists(os.getcwd()+"/"+f):
  194. missing.append(f)
  195. modules_test(Modules, "checkingpartsoftheprogramm", "VCStudio-is-good")
  196. except:
  197. i = "settings/update.data"
  198. ans = i + " "*int(w/2-len(i)) + talk.text("failed")
  199. output("\033[1;41m", " "+ans)
  200. for i in missing:
  201. ans = i + " "*int(w/2-len(i)) + talk.text("failed")
  202. output("\033[1;41m", " "+ans)
  203. desktop = """[Desktop Entry]
  204. Name=Blender-Pipeline
  205. GenericName=Blender-Organizer
  206. Path="""+os.getcwd()+"""
  207. Exec=python3 run.py
  208. Icon="""+os.getcwd()+"""/tinyicon.png
  209. Terminal=false
  210. Type=Application
  211. Categories=Graphics;3DGraphics;Office
  212. """
  213. if os.path.exists(os.environ['HOME']+"/.local/share/applications") \
  214. and not os.path.exists(os.environ['HOME']+"/.local/share/applications/Blender-Pipeline.desktop"):
  215. o = open(os.environ['HOME']+"/.local/share/applications/Blender-Pipeline.desktop", "w")
  216. o.write(desktop)
  217. o.close()
  218. output("\033[1;42m", talk.text("desktopcreated"))
  219. print("\033[1;m")