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.
 
 
 

41 lines
1.5 KiB

  1. from nilmdb.utils.printf import *
  2. import nilmdb.client
  3. def setup(self, sub):
  4. cmd = sub.add_parser("remove", help="Remove data",
  5. description="""
  6. Remove all data from a specified time range within a
  7. stream.
  8. """)
  9. cmd.set_defaults(handler = cmd_remove)
  10. group = cmd.add_argument_group("Data selection")
  11. group.add_argument("path",
  12. help="Path of stream, e.g. /foo/bar",
  13. ).completer = self.complete.path
  14. group.add_argument("-s", "--start", required=True,
  15. metavar="TIME", type=self.arg_time,
  16. help="Starting timestamp (free-form, inclusive)",
  17. ).completer = self.complete.time
  18. group.add_argument("-e", "--end", required=True,
  19. metavar="TIME", type=self.arg_time,
  20. help="Ending timestamp (free-form, noninclusive)",
  21. ).completer = self.complete.time
  22. group = cmd.add_argument_group("Output format")
  23. group.add_argument("-c", "--count", action="store_true",
  24. help="Output number of data points removed")
  25. return cmd
  26. def cmd_remove(self):
  27. try:
  28. count = self.client.stream_remove(self.args.path,
  29. self.args.start, self.args.end)
  30. except nilmdb.client.ClientError as e:
  31. self.die("error removing data: %s", str(e))
  32. if self.args.count:
  33. printf("%d\n", count)
  34. return 0