config.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import os
  2. import uuid
  3. import socket
  4. from app.app_config import SPEAKER_CONFIG_FILE, LINPHONE_CONFIG_FILE, PROJECT_CONFIG
  5. from app import project_cf
  6. from app import speaker_cf
  7. from app import linphone_cf
  8. class Config(object):
  9. def __init__(self):
  10. speaker_cf.read(SPEAKER_CONFIG_FILE)
  11. linphone_cf.read(LINPHONE_CONFIG_FILE)
  12. project_cf.read(PROJECT_CONFIG)
  13. #设置型号
  14. self.model = speaker_cf.get("system", "model")
  15. #系统主机名
  16. self.hostname = socket.getfqdn(socket.gethostname())
  17. #系统ip地址
  18. self.ipaddr = self._get_host_ip()
  19. #系统硬件音量
  20. self.hard_volume = int(speaker_cf.get("system", "volume_out"))
  21. #系统强控开关
  22. self.hard_volume_control = speaker_cf.get("volume", "hard_volume_control")
  23. #系统分机号
  24. self.exten = linphone_cf.get("auth_info_0", "username")
  25. #系统分机密码
  26. self.exten_password = linphone_cf.get("auth_info_0", "passwd")
  27. #广播系统服务器地址
  28. self.server_ipaddr = linphone_cf.get("proxy_0", "reg_identity").split("@", 1)[1].lstrip().rstrip()
  29. #播放器初始化音量
  30. self.player_current_volume = int(project_cf.get("general", "player_init_volume"))
  31. #播放器初始化状态
  32. self.init_player_state = int(project_cf.get("general", "init_player_state"))
  33. #播放源j
  34. self.current_uri = project_cf.get("general", "current_uri")
  35. #设置mac
  36. self.mac = self._get_mac_address()
  37. """
  38. desc:
  39. 获取设备mac地址
  40. """
  41. def _get_mac_address(self):
  42. mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
  43. return ":".join([mac[e:e+2] for e in range(0,11,2)]).replace(":", "").lower()
  44. """
  45. desc:
  46. 获取设置出局ip地址
  47. """
  48. def _get_host_ip(self):
  49. try:
  50. s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  51. s.connect(('8.8.8.8',80))
  52. ip=s.getsockname()[0]
  53. finally:
  54. s.close()
  55. return ip