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.
 
 
 

38 lines
1.4 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. group.add_argument("-s", "--start", required=True,
  14. metavar="TIME", type=self.arg_time,
  15. help="Starting timestamp (free-form, inclusive)")
  16. group.add_argument("-e", "--end", required=True,
  17. metavar="TIME", type=self.arg_time,
  18. help="Ending timestamp (free-form, noninclusive)")
  19. group = cmd.add_argument_group("Output format")
  20. group.add_argument("-c", "--count", action="store_true",
  21. help="Output number of data points removed")
  22. return cmd
  23. def cmd_remove(self):
  24. try:
  25. count = self.client.stream_remove(self.args.path,
  26. self.args.start, self.args.end)
  27. except nilmdb.client.ClientError as e:
  28. self.die("error removing data: %s", str(e))
  29. if self.args.count:
  30. printf("%d\n", count)
  31. return 0