pfs.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 pfs_prepare(cmdr, size):
  17. """ Prepare for file creation.
  18. """
  19. size = int(str(size), 0)
  20. if size <= 0:
  21. raise exceptions.ParameterError('size out of range: %d' % size)
  22. # TODO: I guess catch errors
  23. ret = cmdr.send_prompt_command("pfs prepare %d" % size)
  24. if not ret[0].startswith("Success"):
  25. raise exceptions.PromptResponseError(ret)
  26. # TODO: pfs-write
  27. # Can't do it with pulse prompt :(
  28. @PebbleCommander.command()
  29. def pfs_litter(cmdr):
  30. """ Fragment the filesystem.
  31. Creates a bunch of fragmentation in the filesystem by creating a large
  32. number of small files and only deleting a small number of them.
  33. """
  34. ret = cmdr.send_prompt_command("litter pfs")
  35. if not ret[0].startswith("OK "):
  36. raise exceptions.PromptResponseError(ret)
  37. return [ret[0][3:]]