pm_console.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. # This a console project manager.
  4. import os
  5. try:
  6. w, h = os.get_terminal_size()
  7. except:
  8. w, h, = 50,50
  9. from settings import settings
  10. from settings import talk
  11. from project_manager import pm_project
  12. # COMPLITTER
  13. try:
  14. import readline
  15. except:
  16. pass
  17. commands1 = [
  18. "help",# - help dialogue.
  19. "set_language",# - changes language settings.
  20. "projects_list",# - see projects list.
  21. "set_folder",# - set a folder where a new project is created.
  22. "new_project",# - creates a new project.
  23. "project",# - launch a given project.
  24. "scan",# - scans systems for VCStudio or Blender-Organizer projects.
  25. "convert",# - convert Blender-Organizer project to VCStudio project. (Please have a back up when using this one.)
  26. "exit"#
  27. ]
  28. commands = commands1.copy()
  29. def completer(text, state):
  30. options = [i for i in commands if i.startswith(text)]
  31. if state < len(options):
  32. return options[state]
  33. else:
  34. return None
  35. try:
  36. readline.parse_and_bind("tab: complete")
  37. readline.set_completer(completer)
  38. except:
  39. print("NO TABS, SORRY!")
  40. def cls():
  41. #cleaning the terminal
  42. os.system("clear")
  43. def run():
  44. cls()
  45. print("\033[1;33m\n VCStudio - Console \n")
  46. print("\033[1;32m"+talk.text("PMConsoleExplanation")+"\n")
  47. while True:
  48. # making sure Tab is doing autocomlete to the right functions
  49. global commands
  50. commands = commands1.copy()
  51. command = input("\033[1;35m : \033[1;m")
  52. ##############
  53. if command == "exit":
  54. cls()
  55. exit()
  56. ##############
  57. elif command == "help":
  58. print("\033[1;32m"+talk.text("pm_console_help")+"\n")
  59. ##############
  60. elif command == "set_language":
  61. # Getting list of available languages
  62. commands = []
  63. for lang in settings.list_languages():
  64. print("\033[1;35m "+lang)
  65. commands.append(lang)
  66. # special input for languages
  67. nlang = input("\033[1;33m : ")
  68. if nlang in settings.list_languages():
  69. settings.write("Language",nlang)
  70. print("\033[1;32m"+talk.text("checked"))
  71. else:
  72. print("\033[1;31m"+talk.text("failed"))
  73. ##############
  74. elif command == "set_folder":
  75. if settings.read("New-Project-Folder"):
  76. print("\033[1;35m"+talk.text("Current")+\
  77. " : "+settings.read("New-Project-Folder"))
  78. nfol = input("\033[1;33m : ")
  79. if nfol:
  80. if os.path.exists(nfol):
  81. settings.write("New-Project-Folder", nfol)
  82. else:
  83. print("\033[1;31m"+talk.text("failed"))
  84. ##############
  85. elif command == "new_project":
  86. if not settings.read("New-Project-Folder"):
  87. print("\033[1;33m"+talk.text("pm-do-new-project-error"))
  88. #if folder is configured
  89. else:
  90. nproj = input("\033[1;33m "+talk.text("Name")+" : ")
  91. if pm_project.new(nproj):
  92. print("\033[1;32m"+talk.text("checked"))
  93. else:
  94. print("\033[1;31m"+talk.text("failed"))
  95. ##############
  96. elif command == "projects_list":
  97. # Getting list of available projects
  98. for p in pm_project.get_list():
  99. print("\033[1;35m "+p)
  100. ##############
  101. elif command == "project":
  102. commands = pm_project.get_list()
  103. n = input("\033[1;33m : ")
  104. print("\033[1;35m "+talk.text("Wait"))
  105. pm_project.load(n)
  106. ##############
  107. elif command == "scan":
  108. print("\033[1;35m "+talk.text("Wait"))
  109. for proj in pm_project.scan():
  110. print("\033[1;35m "+proj)
  111. ##############
  112. elif command == "convert":
  113. print("\nNot Implemented yet\n")
  114. ## FAIL ##
  115. elif command != "":
  116. print("\033[1;31m"+talk.text("failed"))
  117. print("\033[1;m") #return terminal to normality