You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 lines
1.4 KiB

  1. from nilmdb.utils.printf import *
  2. import nilmdb.client
  3. from argparse import ArgumentDefaultsHelpFormatter as def_form
  4. def setup(self, sub):
  5. cmd = sub.add_parser("destroy", help="Delete a stream and all data",
  6. formatter_class = def_form,
  7. description="""
  8. Destroy the stream at the specified path.
  9. The stream must be empty. All metadata
  10. related to the stream is permanently deleted.
  11. """)
  12. cmd.set_defaults(handler = cmd_destroy)
  13. group = cmd.add_argument_group("Options")
  14. group.add_argument("-R", "--remove", action="store_true",
  15. help="Remove all data before destroying stream")
  16. group = cmd.add_argument_group("Required arguments")
  17. group.add_argument("path",
  18. help="Path of the stream to delete, e.g. /foo/bar",
  19. ).completer = self.complete.path
  20. return cmd
  21. def cmd_destroy(self):
  22. """Destroy stream"""
  23. if self.args.remove:
  24. try:
  25. count = self.client.stream_remove(self.args.path)
  26. except nilmdb.client.ClientError as e:
  27. self.die("error removing data: %s", str(e))
  28. try:
  29. self.client.stream_destroy(self.args.path)
  30. except nilmdb.client.ClientError as e:
  31. self.die("error destroying stream: %s", str(e))