app.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright 2024 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from .. import PebbleCommander, exceptions, parsers
  15. @PebbleCommander.command()
  16. def app_list(cmdr):
  17. """ List applications.
  18. """
  19. return cmdr.send_prompt_command("app list")
  20. @PebbleCommander.command()
  21. def app_load_metadata(cmdr):
  22. """ Ghetto metadata loading for pbw_image.py
  23. """
  24. ret = cmdr.send_prompt_command("app load metadata")
  25. if not ret[0].startswith("OK"):
  26. raise exceptions.PromptResponseError(ret)
  27. @PebbleCommander.command()
  28. def app_launch(cmdr, idnum):
  29. """ Launch an application.
  30. """
  31. idnum = int(str(idnum), 0)
  32. if idnum == 0:
  33. raise exceptions.ParameterError('idnum out of range: %d' % idnum)
  34. ret = cmdr.send_prompt_command("app launch %d" % idnum)
  35. if not ret[0].startswith("OK"):
  36. raise exceptions.PromptResponseError(ret)
  37. @PebbleCommander.command()
  38. def app_remove(cmdr, idnum):
  39. """ Remove an application.
  40. """
  41. idnum = int(str(idnum), 0)
  42. if idnum == 0:
  43. raise exceptions.ParameterError('idnum out of range: %d' % idnum)
  44. ret = cmdr.send_prompt_command("app remove %d" % idnum)
  45. if not ret[0].startswith("OK"):
  46. raise exceptions.PromptResponseError(ret)
  47. @PebbleCommander.command()
  48. def app_resource_bank(cmdr, idnum=0):
  49. """ Get resource bank info for an application.
  50. """
  51. idnum = int(str(idnum), 0)
  52. if idnum < 0:
  53. raise exceptions.ParameterError('idnum out of range: %d' % idnum)
  54. ret = cmdr.send_prompt_command("resource bank info %d" % idnum)
  55. if not ret[0].startswith("OK "):
  56. raise exceptions.PromptResponseError(ret)
  57. return [ret[0][3:]]
  58. @PebbleCommander.command()
  59. def app_next_id(cmdr):
  60. """ Get next free application ID.
  61. """
  62. return cmdr.send_prompt_command("app next id")
  63. @PebbleCommander.command()
  64. def app_available(cmdr, idnum):
  65. """ Check if an application is available.
  66. """
  67. idnum = int(str(idnum), 0)
  68. if idnum == 0:
  69. raise exceptions.ParameterError('idnum out of range: %d' % idnum)
  70. return cmdr.send_prompt_command("app available %d" % idnum)