From: Ian Jackson Date: Sun, 10 Jan 2021 15:59:50 +0000 (+0000) Subject: otterlib: load shapes X-Git-Tag: otter-0.3.0~111 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=fefd8bf02748d4b47cb467acb1be7d557401f8e4;p=otter.git otterlib: load shapes Signed-off-by: Ian Jackson --- 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> {