From eefcae61d01874721862454deb8b60eac8b8a3a8 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Fri, 28 Oct 2016 13:23:32 -0700 Subject: rename tools to mt-prefix --- TODO | 1 + src/bin/modelthing-modelica.rs | 47 ---------------------------- src/bin/modelthing-webface.rs | 70 ------------------------------------------ src/bin/mt-tool.rs | 47 ++++++++++++++++++++++++++++ src/bin/mt-webface.rs | 70 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 117 deletions(-) delete mode 100644 src/bin/modelthing-modelica.rs delete mode 100644 src/bin/modelthing-webface.rs create mode 100644 src/bin/mt-tool.rs create mode 100644 src/bin/mt-webface.rs diff --git a/TODO b/TODO index 5ada1c6..7e0b257 100644 --- a/TODO +++ b/TODO @@ -8,6 +8,7 @@ - minimum viable wiki-editor web front end on top of API later: +- rename to "modell-dinge"? - basic generation of python/julia/javascript code from model - elm explorer? - latex rendering diff --git a/src/bin/modelthing-modelica.rs b/src/bin/modelthing-modelica.rs deleted file mode 100644 index d71a2eb..0000000 --- a/src/bin/modelthing-modelica.rs +++ /dev/null @@ -1,47 +0,0 @@ - -extern crate modelthing; -extern crate rustc_serialize; -extern crate docopt; - -use modelthing::modelica_parser; -use docopt::Docopt; -use std::env; -use std::io::Read; -use std::fs::File; -use std::time::Instant; - - -fn main() { - let args: Args = Docopt::new(USAGE) - .and_then(|d| d.argv(env::args()).decode()) - .unwrap_or_else(|e| e.exit()); - - for input in &args.arg_inputs { - let mut s = String::new(); - if let Err(err) = File::open(input).and_then(|mut f| f.read_to_string(&mut s)) { - println!("Input `{}`: I/O Error {}", - input, err); - continue; - } - - let time_stamp = Instant::now(); - let result = modelica_parser::parse_model(&s); - let elapsed = time_stamp.elapsed(); - let elapsed = elapsed.as_secs() as f64 + elapsed.subsec_nanos() as f64 / 1000_000_000.0; - - match result { - Ok(_) => println!("Input `{}` ({}s): OK", input, elapsed), - Err(err) => println!("Input `{}` ({}s): parse error {:?}", input, elapsed, err), - } - } -} - -const USAGE: &'static str = " -Usage: modelthing-modelica ... -Parses each input file. -"; - -#[derive(Debug, RustcDecodable)] -struct Args { - arg_inputs: Vec, -} diff --git a/src/bin/modelthing-webface.rs b/src/bin/modelthing-webface.rs deleted file mode 100644 index 0940ea0..0000000 --- a/src/bin/modelthing-webface.rs +++ /dev/null @@ -1,70 +0,0 @@ - -extern crate pencil; -#[macro_use] extern crate log; -extern crate env_logger; - -use std::collections::BTreeMap; -use pencil::Pencil; -use pencil::{Request, PencilResult, Response, HTTPError}; - - -fn home(r: &mut Request) -> PencilResult { - let context: BTreeMap = BTreeMap::new(); - return r.app.render_template("home.html", &context); -} - -fn readme(r: &mut Request) -> PencilResult { - let mut context = BTreeMap::new(); - let raw_text = include_str!("../../README.txt"); - context.insert("raw_text".to_string(), raw_text.to_string()); - return r.app.render_template("raw.html", &context); -} - -fn model_list(_: &mut Request) -> PencilResult { - Ok(Response::from("List of Models")) -} - -fn model_view(r: &mut Request) -> PencilResult { - let model_id = r.view_args.get("model_id").unwrap(); - let mut context = BTreeMap::new(); - context.insert("model_id".to_string(), model_id.to_string()); - return r.app.render_template("model_view.html", &context); -} - -fn page_not_found(_: HTTPError) -> PencilResult { - let mut response = Response::from("404: Not Found"); - response.status_code = 500; - Ok(response) -} - -fn server_error(_: HTTPError) -> PencilResult { - let mut response = Response::from("500: Server Error"); - response.status_code = 500; - Ok(response) -} - -fn main() { - - env_logger::init().unwrap(); - - let mut app = Pencil::new("webface"); - app.name = "modelthing-webface".to_string(); - app.set_debug(true); - app.set_log_level(); - app.httperrorhandler(404, page_not_found); - app.httperrorhandler(500, server_error); - app.enable_static_file_handling(); - debug!("root_path: {}", app.root_path); - - app.register_template("base.html"); - app.register_template("home.html"); - app.register_template("raw.html"); - app.get("/", "home", home); - app.get("/readme/", "readme", readme); - app.get("/model_list/", "model_list", model_list); - app.register_template("model_view.html"); - app.get("/model/", "model", model_view); - - info!("Running on http://localhost:5000/"); - app.run("127.0.0.1:5000"); -} diff --git a/src/bin/mt-tool.rs b/src/bin/mt-tool.rs new file mode 100644 index 0000000..d71a2eb --- /dev/null +++ b/src/bin/mt-tool.rs @@ -0,0 +1,47 @@ + +extern crate modelthing; +extern crate rustc_serialize; +extern crate docopt; + +use modelthing::modelica_parser; +use docopt::Docopt; +use std::env; +use std::io::Read; +use std::fs::File; +use std::time::Instant; + + +fn main() { + let args: Args = Docopt::new(USAGE) + .and_then(|d| d.argv(env::args()).decode()) + .unwrap_or_else(|e| e.exit()); + + for input in &args.arg_inputs { + let mut s = String::new(); + if let Err(err) = File::open(input).and_then(|mut f| f.read_to_string(&mut s)) { + println!("Input `{}`: I/O Error {}", + input, err); + continue; + } + + let time_stamp = Instant::now(); + let result = modelica_parser::parse_model(&s); + let elapsed = time_stamp.elapsed(); + let elapsed = elapsed.as_secs() as f64 + elapsed.subsec_nanos() as f64 / 1000_000_000.0; + + match result { + Ok(_) => println!("Input `{}` ({}s): OK", input, elapsed), + Err(err) => println!("Input `{}` ({}s): parse error {:?}", input, elapsed, err), + } + } +} + +const USAGE: &'static str = " +Usage: modelthing-modelica ... +Parses each input file. +"; + +#[derive(Debug, RustcDecodable)] +struct Args { + arg_inputs: Vec, +} diff --git a/src/bin/mt-webface.rs b/src/bin/mt-webface.rs new file mode 100644 index 0000000..0940ea0 --- /dev/null +++ b/src/bin/mt-webface.rs @@ -0,0 +1,70 @@ + +extern crate pencil; +#[macro_use] extern crate log; +extern crate env_logger; + +use std::collections::BTreeMap; +use pencil::Pencil; +use pencil::{Request, PencilResult, Response, HTTPError}; + + +fn home(r: &mut Request) -> PencilResult { + let context: BTreeMap = BTreeMap::new(); + return r.app.render_template("home.html", &context); +} + +fn readme(r: &mut Request) -> PencilResult { + let mut context = BTreeMap::new(); + let raw_text = include_str!("../../README.txt"); + context.insert("raw_text".to_string(), raw_text.to_string()); + return r.app.render_template("raw.html", &context); +} + +fn model_list(_: &mut Request) -> PencilResult { + Ok(Response::from("List of Models")) +} + +fn model_view(r: &mut Request) -> PencilResult { + let model_id = r.view_args.get("model_id").unwrap(); + let mut context = BTreeMap::new(); + context.insert("model_id".to_string(), model_id.to_string()); + return r.app.render_template("model_view.html", &context); +} + +fn page_not_found(_: HTTPError) -> PencilResult { + let mut response = Response::from("404: Not Found"); + response.status_code = 500; + Ok(response) +} + +fn server_error(_: HTTPError) -> PencilResult { + let mut response = Response::from("500: Server Error"); + response.status_code = 500; + Ok(response) +} + +fn main() { + + env_logger::init().unwrap(); + + let mut app = Pencil::new("webface"); + app.name = "modelthing-webface".to_string(); + app.set_debug(true); + app.set_log_level(); + app.httperrorhandler(404, page_not_found); + app.httperrorhandler(500, server_error); + app.enable_static_file_handling(); + debug!("root_path: {}", app.root_path); + + app.register_template("base.html"); + app.register_template("home.html"); + app.register_template("raw.html"); + app.get("/", "home", home); + app.get("/readme/", "readme", readme); + app.get("/model_list/", "model_list", model_list); + app.register_template("model_view.html"); + app.get("/model/", "model", model_view); + + info!("Running on http://localhost:5000/"); + app.run("127.0.0.1:5000"); +} -- cgit v1.2.3