configuration.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import json
  2. from sanic.log import error_logger
  3. import sys
  4. from AES_crypt import decrypt
  5. class Configuration:
  6. def __init__(self, path='config.json'):
  7. self.path = path
  8. def get_config(self):
  9. """"读取配置"""
  10. try:
  11. with open(self.path) as json_file:
  12. config = json.load(json_file)
  13. config['hardDiskdataBase']['password'] = decrypt(config['hardDiskdataBase']['password'])
  14. return config
  15. except FileNotFoundError as e:
  16. error_logger.error(f"config file does not exist:{e}")
  17. sys.exit()
  18. # 解密密码和序列号
  19. # config['hardDiskdataBase']['password'] = DesEncrypt(
  20. # config['hardDiskdataBase']['password']).decode('utf-8')
  21. # config['code'] = DesEncrypt(config['code']).decode('utf-8')
  22. def set_config(self):
  23. pass
  24. def add_device(self):
  25. pass
  26. def delete_device(self):
  27. pass
  28. def updata_device(self):
  29. pass
  30. if __name__ == '__main__':
  31. config = Configuration().get_config()
  32. print(config)