settings.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from dotenv import load_dotenv, find_dotenv
  2. from pathlib import Path # Python 3.6+ only
  3. import configparser
  4. def get_config_by_items(config_dict):
  5. __config_dict = {}
  6. for i, k in config_dict:
  7. __config_dict[i] = k
  8. return __config_dict
  9. def get_dict_value(_dict, key, default=None):
  10. if key in _dict:
  11. return _dict[key]
  12. else:
  13. return default
  14. config = configparser.ConfigParser()
  15. config_name = "config.ini"
  16. config.read(config_name, encoding="utf-8")
  17. # 应用名称
  18. APP_NAME = config.get("app", "app_name")
  19. # 应用版本号
  20. APP_VERSION = config.get("app", "version")
  21. # 是否开启调试模式
  22. IS_DEBUG = config.get("app", "debug")
  23. # 应用端口号
  24. PORT = config.get("app", "port")
  25. # 应用线程数
  26. APP_WORKS = config.get("app", "works")
  27. # 应用host地址
  28. APP_HOST = config.get("app", "host")
  29. # 应用服务启动名称
  30. APP_RUN = config.get("app", "app_run")
  31. # 日志名称
  32. LOG_FILE_NAME = config.get("log", "log_file_name")
  33. # 最大字节数
  34. MAX_BYTES = config.get("log", "max_bytes")
  35. print("Max bytes is", MAX_BYTES)
  36. # 备份数量
  37. BACKUP_COUNTS = config.get("log", "backup_counts")
  38. # 远程服务器地址
  39. HLM_HOST = config.get("log", "hlm_host")
  40. # ----------------------------------
  41. mcu_config_dict = config.items("mcu_config")
  42. _mcu_config_dict = {}
  43. for i, k in mcu_config_dict:
  44. _mcu_config_dict[i] = int(k)
  45. # print(_mcu_config_dict)
  46. _config_mcu_config = get_config_by_items(config.items("mcu_config"))
  47. LEFT_FOOT_ACTION = _mcu_config_dict["left_foot_action"]
  48. LEFT_FOOT_PHOTOGRAPH = _mcu_config_dict["left_foot_photograph"]
  49. LEFT_FOOT_ACTION_1 = _mcu_config_dict["left_foot_action_1"]
  50. LEFT_FOOT_ACTION_2 = _mcu_config_dict["left_foot_action_2"]
  51. RIGHT_FOOT_ACTION = _mcu_config_dict["right_foot_action"]
  52. RIGHT_FOOT_PHOTOGRAPH = _mcu_config_dict["right_foot_photograph"]
  53. RIGHT_FOOT_ACTION_1 = _mcu_config_dict["right_foot_action_1"]
  54. RIGHT_FOOT_ACTION_2 = _mcu_config_dict["right_foot_action_2"]
  55. NEXT_STEP = int(get_dict_value(_config_mcu_config, "next_step", 6)) # 下一步
  56. MOVE_UP = _mcu_config_dict["move_up"]
  57. MOVE_DOWN = _mcu_config_dict["move_down"]
  58. STOP = _mcu_config_dict["stop"]