Controller.py 2.2 KB

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