Skip to main content

Crate marina

Crate marina 

Source
Expand description

Marina is a dataset manager for robotics built to organize, share, and discover datasets and bags across teams and storage backends.

§Add the dependency

[dependencies]
marina = "0.2"
tokio = { version = "1", features = ["rt", "macros"] }

Marina’s async methods require a tokio runtime. A single-threaded runtime (#[tokio::main(flavor = "current_thread")]) is sufficient.

§Resolve a dataset

Marina::resolve_target checks whether a dataset is already cached, available locally, or only reachable via a remote registry.

use marina::{Marina, ResolveResult};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let marina = Marina::load()?;

    match marina.resolve_target("outdoor-run:v2", None).await? {
        ResolveResult::LocalPath(p) | ResolveResult::Cached(p) => {
            println!("ready at {}", p.display());
        }
        ResolveResult::RemoteAvailable { bag, registry, .. } => {
            println!("remote: {bag} in {registry}");
        }
        ResolveResult::Ambiguous { candidates } => {
            println!("found in {} registries", candidates.len());
        }
    }
    Ok(())
}

Pass a registry name as the second argument to restrict the search:

marina.resolve_target("outdoor-run:v2", Some("team-ssh")).await?;

§Pull a dataset

Marina::pull_exact downloads a dataset if it is not already cached and returns the local path:

use marina::{Marina, BagRef};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut marina = Marina::load()?;
    let bag: BagRef = "outdoor-run:v2".parse()?;
    let path = marina.pull_exact(&bag, None).await?;
    println!("cached at {}", path.display());
    Ok(())
}

§Pull with progress reporting

Implement ProgressSink to receive phase events during download and decompression:

use marina::{Marina, BagRef, ProgressEvent, ProgressReporter, ProgressSink};

struct MyProgress;

impl ProgressSink for MyProgress {
    fn emit(&mut self, event: ProgressEvent) {
        println!("[{}] {}", event.phase, event.message);
    }
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut marina = Marina::load()?;
    let bag: BagRef = "outdoor-run:v2".parse()?;

    let mut sink = MyProgress;
    let mut reporter = ProgressReporter::new(&mut sink);
    let path = marina.pull_exact_with_progress(&bag, None, &mut reporter).await?;
    println!("done: {}", path.display());
    Ok(())
}

WriterProgress is a built-in sink that writes human-readable output to any std::io::Write:

use marina::{Marina, BagRef, ProgressReporter, WriterProgress};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut marina = Marina::load()?;
    let bag: BagRef = "outdoor-run:v2".parse()?;

    let mut stdout = std::io::stdout();
    let mut sink = WriterProgress::new(&mut stdout);
    let mut reporter = ProgressReporter::new(&mut sink);
    marina.pull_exact_with_progress(&bag, None, &mut reporter).await?;
    Ok(())
}

Re-exports§

pub use core::CachedBagInfo;
pub use core::CachedSizeStats;
pub use core::Marina;
pub use core::PullOptions;
pub use core::PushOptions;
pub use core::RemoteBagHit;
pub use core::RemovedRegistry;
pub use core::ResolveResult;
pub use model::bag_ref::BagRef;
pub use progress::ProgressEvent;
pub use progress::ProgressReporter;
pub use progress::ProgressSink;
pub use progress::WriterProgress;

Modules§

cleanup
cli
core
ffi
io
model
progress
registry
storage