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.
 
 
 

45 lines
1.6 KiB

  1. from nilmdb.utils.printf import *
  2. import nilmdb
  3. import nilmdb.client
  4. import sys
  5. def setup(self, sub):
  6. cmd = sub.add_parser("remove", help="Remove data",
  7. description="""
  8. Remove all data from a specified time range within a
  9. stream.
  10. """)
  11. cmd.set_defaults(verify = cmd_remove_verify,
  12. handler = cmd_remove)
  13. group = cmd.add_argument_group("Data selection")
  14. group.add_argument("path",
  15. help="Path of stream, e.g. /foo/bar")
  16. group.add_argument("-s", "--start", required=True,
  17. metavar="TIME", type=self.arg_time,
  18. help="Starting timestamp (free-form, inclusive)")
  19. group.add_argument("-e", "--end", required=True,
  20. metavar="TIME", type=self.arg_time,
  21. help="Ending timestamp (free-form, noninclusive)")
  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. def cmd_remove_verify(self):
  26. if self.args.start is not None and self.args.end is not None:
  27. if self.args.start > self.args.end:
  28. self.parser.error("start is after end")
  29. def cmd_remove(self):
  30. try:
  31. count = self.client.stream_remove(self.args.path,
  32. self.args.start, self.args.end)
  33. except nilmdb.client.ClientError as e:
  34. self.die("error removing data: %s", str(e))
  35. if self.args.count:
  36. printf("%d\n", count)
  37. return 0