in below/src/main.rs [1237:1315]
fn convert_store(
logger: slog::Logger,
below_config: &BelowConfig,
start_time: String,
end_time: String,
from_store_dir: Option<PathBuf>,
to_store_dir: PathBuf,
host: Option<String>,
port: Option<u16>,
compress_opts: &CompressOpts,
) -> Result<()> {
let (time_begin, time_end) = cliutil::system_time_range_from_date_and_adjuster(
start_time.as_str(),
Some(end_time.as_str()),
/* days_adjuster */ None,
)?;
let (timestamp_begin, timestamp_end) = (
common::util::get_unix_timestamp(time_begin),
common::util::get_unix_timestamp(time_end),
);
let pb = ProgressBar::new(timestamp_end - timestamp_begin);
let mut store: Box<dyn Store<SampleType = DataFrame>> = match (from_store_dir, host) {
(Some(_from_store_dir), Some(_host)) => {
bail!("Only one of --from-store-dir and --host should be specified");
}
(Some(from_store_dir), None) => {
pb.set_message(&format!("Using local store at {:?}", from_store_dir));
Box::new(store::LocalStore::new(logger.clone(), from_store_dir))
}
(None, Some(host)) => {
pb.set_message(&format!("Using remote store for {}", host));
Box::new(store::RemoteStore::new(host, port)?)
}
(None, None) => {
pb.set_message(&format!(
"Using local store at {:?}",
&below_config.store_dir
));
Box::new(store::LocalStore::new(
logger.clone(),
below_config.store_dir.clone(),
))
}
};
let mut dest_store = store::StoreWriter::new(
logger.clone(),
&to_store_dir,
compress_opts.to_compression_mode()?,
store::Format::Cbor,
)?;
pb.set_message(&format!("Writing to local store at {:?}", to_store_dir));
let mut nr_samples = 0;
let mut cur_time = time_begin;
while cur_time < time_end {
match store.get_sample_at_timestamp(cur_time, store::Direction::Forward)? {
Some((frame_time, frame)) => {
cur_time = frame_time;
pb.set_message(&format!("Storing frame at t = {:?}", frame_time));
dest_store.put(frame_time, &frame)?;
nr_samples += 1;
}
None => {
pb.set_message(&format!(
"Error: Breaking early. Couldn't find any frames after t = {:?}",
cur_time
));
break;
}
}
pb.set_position(common::util::get_unix_timestamp(cur_time) - timestamp_begin);
cur_time += Duration::from_secs(1); // To actually move forward
}
pb.set_message(&format!("Done. Logged {} samples.", nr_samples));
Ok(())
}