device.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2012-2023 MOD Audio UG
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. import os
  5. from mod.settings import API_KEY, DEVICE_KEY, DEVICE_TAG, DEVICE_UID, IMAGE_VERSION
  6. def get_uid():
  7. if DEVICE_UID is None:
  8. raise Exception('Missing device uid')
  9. if os.path.isfile(DEVICE_UID):
  10. with open(DEVICE_UID, 'r') as fh:
  11. return fh.read().strip()
  12. return DEVICE_UID
  13. def get_tag():
  14. if DEVICE_TAG is None:
  15. raise Exception('Missing device tag')
  16. if os.path.isfile(DEVICE_TAG):
  17. with open(DEVICE_TAG, 'r') as fh:
  18. return fh.read().strip()
  19. return DEVICE_TAG
  20. def get_device_key():
  21. if DEVICE_KEY is None:
  22. raise Exception('Missing device key')
  23. if os.path.isfile(DEVICE_KEY):
  24. with open(DEVICE_KEY, 'r') as fh:
  25. return fh.read().strip()
  26. return DEVICE_KEY
  27. def get_server_key():
  28. if API_KEY is None:
  29. raise Exception('Missing API key')
  30. if os.path.isfile(API_KEY):
  31. with open(API_KEY, 'r') as fh:
  32. return fh.read().strip()
  33. return API_KEY
  34. def get_image_version():
  35. if IMAGE_VERSION is not None:
  36. return IMAGE_VERSION
  37. return 'none'