| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- from dotenv import load_dotenv, find_dotenv
- from pathlib import Path # Python 3.6+ only
- import configparser
- def get_config_by_items(config_dict):
- __config_dict = {}
- for i, k in config_dict:
- __config_dict[i] = k
- return __config_dict
- def get_dict_value(_dict, key, default=None):
- if key in _dict:
- return _dict[key]
- else:
- return default
- config = configparser.ConfigParser()
- config_name = "config.ini"
- config.read(config_name, encoding="utf-8")
- # 应用名称
- APP_NAME = config.get("app", "app_name")
- # 应用版本号
- APP_VERSION = config.get("app", "version")
- # 是否开启调试模式
- IS_DEBUG = config.get("app", "debug")
- # 应用端口号
- PORT = config.get("app", "port")
- # 应用线程数
- APP_WORKS = config.get("app", "works")
- # 应用host地址
- APP_HOST = config.get("app", "host")
- # 应用服务启动名称
- APP_RUN = config.get("app", "app_run")
- # 日志名称
- LOG_FILE_NAME = config.get("log", "log_file_name")
- # 最大字节数
- MAX_BYTES = config.get("log", "max_bytes")
- print("Max bytes is", MAX_BYTES)
- # 备份数量
- BACKUP_COUNTS = config.get("log", "backup_counts")
- # 远程服务器地址
- HLM_HOST = config.get("log", "hlm_host")
- # ----------------------------------
- mcu_config_dict = config.items("mcu_config")
- _mcu_config_dict = {}
- for i, k in mcu_config_dict:
- _mcu_config_dict[i] = int(k)
- # print(_mcu_config_dict)
- _config_mcu_config = get_config_by_items(config.items("mcu_config"))
- LEFT_FOOT_ACTION = _mcu_config_dict["left_foot_action"]
- LEFT_FOOT_PHOTOGRAPH = _mcu_config_dict["left_foot_photograph"]
- LEFT_FOOT_ACTION_1 = _mcu_config_dict["left_foot_action_1"]
- LEFT_FOOT_ACTION_2 = _mcu_config_dict["left_foot_action_2"]
- RIGHT_FOOT_ACTION = _mcu_config_dict["right_foot_action"]
- RIGHT_FOOT_PHOTOGRAPH = _mcu_config_dict["right_foot_photograph"]
- RIGHT_FOOT_ACTION_1 = _mcu_config_dict["right_foot_action_1"]
- RIGHT_FOOT_ACTION_2 = _mcu_config_dict["right_foot_action_2"]
- NEXT_STEP = int(get_dict_value(_config_mcu_config, "next_step", 6)) # 下一步
- MOVE_UP = _mcu_config_dict["move_up"]
- MOVE_DOWN = _mcu_config_dict["move_down"]
- STOP = _mcu_config_dict["stop"]
|