From fefd8bf02748d4b47cb467acb1be7d557401f8e4 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 10 Jan 2021 15:59:50 +0000 Subject: [PATCH] otterlib: load shapes Signed-off-by: Ian Jackson --- Cargo.lock.example | 1 + Cargo.toml | 1 + src/bin/otterlib.rs | 30 ++++++++++++++++++++++++++---- src/shapelib.rs | 7 +++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Cargo.lock.example b/Cargo.lock.example index 22a2e4a1..7e06f5b5 100644 --- a/Cargo.lock.example +++ b/Cargo.lock.example @@ -1585,6 +1585,7 @@ dependencies = [ "derive_more", "either", "enum-map", + "env_logger", "failure", "fehler", "flexi_logger", diff --git a/Cargo.toml b/Cargo.toml index a34d1fde..650f2b46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ delegate = "0.5" derive_more = "0.99" either = "1" enum-map = { version = "0.6", features = [ "serde" ] } +env_logger = "0.8" failure = "0.1.8" # for pwd fehler = "1" flexi_logger = { version = "0.16", features = [ "specfile" ] } diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index bdefbd61..277fe4b6 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -4,6 +4,8 @@ pub use otter::imports::*; +pub use shapelib::*; + use structopt::StructOpt; #[derive(Debug,Clone)] @@ -19,9 +21,29 @@ pub struct Opts { #[throws(anyhow::Error)] fn main() { let opts = Opts::from_args(); - let libs = shapelib::Config1::PathGlob(opts.libs.clone()); - shapelib::load(&vec![libs])?; -/* + + env_logger::Builder::new() +// .format_timestamp_micros() +// .format_level(true) +// .filter_module(exe_module_path, log::LevelFilter::Debug) + .filter_level(log::LevelFilter::Info) + .parse_env("OTTERLIB_LOG") + .init(); + + let libs = Config1::PathGlob(opts.libs.clone()); + load(&vec![libs.clone()])?; + let libnames = libs_list(); + for lib in libnames { + let contents = libs_lookup(&lib)?; + let items = contents.list_glob(&opts.items)?; + dbg!(&items); + for item in items { + dbg!(&item); + } + } +} + +/* let name = a.next().unwrap(); let dirname = a.next().unwrap(); let catalogue = format!("{}.toml", &dirname); @@ -30,4 +52,4 @@ fn main() { }; shapelib::load1(&e).unwrap(); */ -} + diff --git a/src/shapelib.rs b/src/shapelib.rs index 3760e7ae..f93b1cda 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -207,6 +207,13 @@ impl Piece for Item { static SHAPELIBS: RwLock> = const_rwlock(None); +pub fn libs_list() -> Vec { + let libs = SHAPELIBS.read(); + libs.as_ref().map( + |l| l.keys().cloned().collect() + ).unwrap_or_default() +} + #[throws(SpecError)] pub fn libs_lookup(libname: &str) -> MappedRwLockReadGuard<'static, Contents> { -- 2.30.2