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.
 
 
 
 

44 lines
1.5 KiB

  1. #!/usr/bin/env python3
  2. # This is called copy_one instead of copy to avoid name conflicts with
  3. # the Python standard library.
  4. import nilmtools.filter
  5. from nilmdb.client.numpyclient import NumpyClient
  6. def main(argv=None):
  7. f = nilmtools.filter.Filter()
  8. parser = f.setup_parser("Copy a stream")
  9. parser.add_argument('-n', '--nometa', action='store_true',
  10. help="Don't copy or check metadata")
  11. # Parse arguments
  12. try:
  13. args = f.parse_args(argv)
  14. except nilmtools.filter.MissingDestination as e:
  15. print("Source is %s (%s)" % (e.src.path, e.src.layout))
  16. print("Destination %s doesn't exist" % (e.dest.path))
  17. print("You could make it with a command like:")
  18. print(" nilmtool -u %s create %s %s" % (e.dest.url,
  19. e.dest.path, e.src.layout))
  20. raise SystemExit(1)
  21. # Copy metadata
  22. if not args.nometa:
  23. meta = f.client_src.stream_get_metadata(f.src.path)
  24. f.check_dest_metadata(meta)
  25. # Copy all rows of data using the faster Numpy interfaces
  26. extractor = NumpyClient(f.src.url).stream_extract_numpy
  27. inserter = NumpyClient(f.dest.url).stream_insert_numpy_context
  28. for i in f.intervals():
  29. print("Processing", i.human_string())
  30. with inserter(f.dest.path, i.start, i.end) as insert_ctx:
  31. for data in extractor(f.src.path, i.start, i.end):
  32. insert_ctx.insert(data)
  33. if __name__ == "__main__":
  34. main()