Controller.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import Alt, Stateful
  2. import datetime
  3. class Client():
  4. def get_config():
  5. # [todo 4]
  6. configs = ['DBType', 'DBPath', 'lang', 'listStyle', 'displayTimeZone']
  7. # rl == 'r'eturn 'l'ist
  8. rl = Stateful.MatchTomlKeys("dev_config.toml", configs)
  9. global lang, listStyle, dbType, dbPath, displayTimeZone, currentPath
  10. dbType = rl[0]
  11. dbPath = rl[1]
  12. lang = rl[2]
  13. listStyle = rl[3]
  14. displayTimeZone = rl[4]
  15. currentPath = ""
  16. # [todo 4]
  17. def get_help():
  18. print(Stateful.MatchTomlKey("clean_config.toml", lang, "command-help"))
  19. # [todo 3]
  20. def InUTC(timeZone=0):
  21. dt_now_UTC0 = str(datetime.datetime.now(datetime.timezone.utc))
  22. return(dt_now_UTC0)
  23. # [todo 2]
  24. # 前端只检查输入数量正确, 内容正确统一代回后端检查
  25. def InputCheck(inputs):
  26. pass
  27. def TransitCommand():
  28. # do while or for (1)
  29. while(1):
  30. app_commands = input(currentPath + "/: ", ).split(" ")
  31. # Input exception check
  32. # [todo 1]
  33. # Client.InputCheck(app_commands)
  34. if len(app_commands) < 5:
  35. # Add CurrentPath && DBType && Path
  36. app_commands.append(currentPath)
  37. app_commands.append(dbPath)
  38. app_commands.append(dbType)
  39. Stateful.Handler(app_commands)
  40. elif len(app_commands) >= 5:
  41. print("app_commands >5 error")
  42. # [todo 4]
  43. def GenDB():# Stateful里面还有一个一样的方法
  44. pass
  45. # 1. 先检查是否已经存在DB? y/n?
  46. # 2. 连接性检查(是否要切换到新建的DB)y/n?
  47. # [todo 4]
  48. def start():
  49. # 0. init
  50. # 1. get config
  51. Client.get_config()
  52. # 2.
  53. startState = Stateful.Handler(['/', dbPath, dbType])
  54. print(startState)
  55. Client.TransitCommand()
  56. class View:
  57. def ToDisplayTime(utcTime, TimeZone):
  58. displayTime = "displayTime translation not finished"
  59. return displayTime
  60. def Refresh():
  61. pass
  62. # For ChatGLM3-6B
  63. class LLMCall():
  64. pass
  65. if __name__ == "__main__":
  66. Client.start()