From a79b7e76b2d10ea962ffde4a26b21dd8bf0ed3d5 Mon Sep 17 00:00:00 2001 From: Shaz hemani Date: Mon, 31 Aug 2020 15:25:12 +0500 Subject: [PATCH] toml configs and sheet reading --- .gitignore | 28 +++++ Cargo.lock | 179 +++++++++++++++++++++++++++ Cargo.toml | 21 ++++ Makefile.toml | 3 + assets/2020-6_BKM_Rapor.xlsx | Bin 0 -> 6586 bytes src/cli_manager.rs | 75 +++++++++++ src/configs/configs_input_sheet.toml | 7 ++ src/configuration_manager.rs | 28 +++++ src/herlpers.rs | 14 +++ src/lib.rs | 2 + src/main.rs | 17 +++ 11 files changed, 374 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 Makefile.toml create mode 100644 assets/2020-6_BKM_Rapor.xlsx create mode 100644 src/cli_manager.rs create mode 100644 src/configs/configs_input_sheet.toml create mode 100644 src/configuration_manager.rs create mode 100644 src/herlpers.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d577d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# will have compiled files and executables # +debug/ +target/ + +# These are backup files generated by rustfmt # +**/*.rs.bk + +# IDE files # +.vscode +.idea +.iml +*.sublime-workspace + +# OS generated files # +.DS_Store +.DS_Store? +._* +.Trashes + +# Logs # +*.log + +# Temporary files # +*.bak +*.swp +*.swo +*~ +*# diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..11b051a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,179 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hermit-abi 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.76 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.76 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "proc-macro2" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde_derive" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "syn" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "toml" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "xlsx_parser_extractor" +version = "0.1.0" +dependencies = [ + "clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)" = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +"checksum hermit-abi 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +"checksum libc 0.2.76 (registry+https://github.com/rust-lang/crates.io-index)" = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3" +"checksum proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" +"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +"checksum serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)" = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" +"checksum serde_derive 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)" = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" +"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +"checksum syn 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9" +"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +"checksum toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" +"checksum unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +"checksum vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..93dbfd1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "xlsx_parser_extractor" +version = "0.1.0" +authors = ["Shahzad "] +edition = "2018" + +[lib] +name = "xlsx_parser_extractor" +path = "src/lib.rs" + +[[bin]] +name = "xlsx_parser_extractor" +path = "src/main.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +clap = "2.33.3" +toml = "0.5" +serde = "1.0.97" +serde_derive = "1.0" + diff --git a/Makefile.toml b/Makefile.toml new file mode 100644 index 0000000..4ead859 --- /dev/null +++ b/Makefile.toml @@ -0,0 +1,3 @@ +# create new flow to avoid format task +[tasks.rust-flow] +dependencies = ["clean", "build", "test"] diff --git a/assets/2020-6_BKM_Rapor.xlsx b/assets/2020-6_BKM_Rapor.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..7db329cfc4047c68c3c4d902a85e0891b7114381 GIT binary patch literal 6586 zcmaKw1z1$=w#SK~LsG_}Q=~gYx;q7xX6R->1nFh~k#>*)X%IoWyM~bNZlpwX2&FH4 z-#JIG_nvRf^Umyf_FnJa`@h%PYrQ`$RdfIu3N|)2N`n)zHp*{?ce8B@v2t|h=DPhZ zNf@^8*+~P?`-fG&?j(9 z8Y>ajKhou9+$Hu&m~Uu_-w{Kf!^;-|VeHrn(G9u8`*#u=+Xzwz`+IJj_D9k}We^jj z?6CW%ps}B19Z$$vd-u5JTN_{)6pAsJ_wop#Q@rF#7OJP8iag$_hz2mFG2;FUbyz2EAdNwQ`%36nlO!f_~R~!g%vNj^{|fJP5o&# z%D(|<+vM4a0R?X$*sS|zRM`4+Htn<)RSL=+(8%;twQtDAU{Ce=1>t>rn~SCx+CAql zUyD8jl{bCEz_t6N|GKig!CAC9-0h{Zx-a^zP9!a(_jhkpc!~N?IuZY_6W9e}bt{xp z{GdiB4^imBBl!)VH2_m+HdC^QYc`3_`>x5E`HAj;idyya6A>Ii`HdR>b8p83p%0b% zvpBwSQ&qWaDhWZW`by)qmgiRqlJOjL{J{?#GMOo`EhiTR7bX{8dL2#$DdNyaOS4QY zR9n8@wpT%44zbRP422G+AHOwEYAJ~Q&OL?R%>7BR2sPELcN++6Oj7b^z|f5Ux;;ro zCxU?i!pD3@PJU@c+(a0Sl|MxAp4o(oBYWC9dsv#q6&P;e1snN!73E)SDm-rBZimoz zqcdjo8WiWLYH`>uiL4H6YxV#tN(f&Awb`xDz;I10mStxarl;#0!NSGG;a2ItlQv%6;U+G_4=%|Sesn8ifn!9PW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XI0Uv8U)TeD0N{(dTS3wy(fX2AF6{Mqfh(s z_ESf0$Frvfdx6Q_3GG8KVzH|eHw;FF-2lytH8%A|WI>#bz0(HVzyYifu2 zT=*ou1=y^7L0?dab)bbLQ@!9)jSp^8s_k@EwayKFxl~;r%k!!>LL7ggl*52^hNN8` zeMm)IOKI%d-fikfC-SfLBeCoU*L-vol&l-r_TQUk(wjUtly!0TuyXb=)$?|>ayR~~ zUrv&|ftEzwKm4P5*`pTu=t2`bSB9~ZS^4=+n0b{QKY6O2?~4{-Jbr8&9SP$&|JuB~ zNC_XDa!M?2^S1KPVDV5R8R<~U`vh;|pc!-EON*`OMg(h?8JxrQ=w~PqO@*1886Z3m zdzc&N9k1uil|~ay08ddGQ(kiq6zVY|@m_((kYMh#xP{X1-k;<}m7Qz-h?7a3opJzo zo>-UnzkE&z3XrQCLz*>s2;Y;pnqFtOy6heXeE5VOXuod#z1j4;bC&5Cxz=H*n;0{F zsyhXZcQnBlLFbO`w)3O-Tw-^dVjEkv*IP>={PJ0V%$^E)oUpnYKt{Fk&H&@~(V(J{ zq5Q(^zk}vm%>KXaH|YMSFh6)x>m4D9id&=Dw&|kK8qv`Dh{8>)_oZ Self { + // New instance of application + let matches = App::new("XLSX Parser Extractor") + .version("0.1.0") + .about("Transofrm data in Excel files into the JSON format") + .arg( + Arg::with_name("PATH") + .long("path") + .short("p") + .required(true) + .takes_value(true) + .help("Sets the excel file to use"), + ) + .arg( + Arg::with_name("COMMAND") + // .help("sheet_parsing | sheet_gen_row | sheet_gen_curated") + .help(TYPE_HELP) + .next_line_help(true) + .required(true), + ) + .get_matches(); + // Calling .unwrap() is safe here because "FIELD" is required (if "FIELD" wasn't + // required we could have used an 'if let' to conditionally get the value) + let file = matches.value_of("PATH").unwrap(); + let command_args = matches.value_of("COMMAND").unwrap().into(); + let command = match command_args { + "sheet-parsing" => Commands::SheetParsing, + "sheet-gen-row" => Commands::SheetGenRow, + "sheet-gen-curated" => Commands::SheetGenCurated, + _ => panic!( + "Unknown command '{}'. For more information try --help", + command_args + ), + }; + + // helper methods to check file extension and path + // TODO: replace panic with humanize error message + let excel_type = herlpers::check_if_excel(file); + let path_exist = herlpers::path_exists(file); + + if !excel_type { + panic!("Expecting an excel file"); + } + if !path_exist { + panic!("File doesn't exist"); + } + + // returning Args struct + Self { + file: file.into(), + command: command, + } + } +} diff --git a/src/configs/configs_input_sheet.toml b/src/configs/configs_input_sheet.toml new file mode 100644 index 0000000..68c8af1 --- /dev/null +++ b/src/configs/configs_input_sheet.toml @@ -0,0 +1,7 @@ +[[input_file]] +file_name = "assets/2020-6_BKM_Rapor.xlsx" +sheet_name = "Sheet1" + +[[input_file]] +file_name = "assets/2020-6_BKM_Rapor.xlsx" +sheet_name = "Sheet1" diff --git a/src/configuration_manager.rs b/src/configuration_manager.rs new file mode 100644 index 0000000..3850d8d --- /dev/null +++ b/src/configuration_manager.rs @@ -0,0 +1,28 @@ +use serde_derive::Deserialize; +use std::fs; +use std::path::Path; + + +#[derive(Debug, Deserialize)] +struct InputFile { + file_name: Option, + sheet_name: Option, +} + +#[derive(Debug, Deserialize)] +pub struct Config { + input_file: Option>, +} + +impl Config { + pub fn get_configs(file_name: &str) -> Self { + + let string_path : String = format!("{}{}", "./src/configs/", file_name).into(); + let path = Path::new(string_path.as_str() ); + + let contents = fs::read_to_string(path) + .expect("Something went wrong reading the file"); + + toml::from_str(contents.as_str()).unwrap() + } +} \ No newline at end of file diff --git a/src/herlpers.rs b/src/herlpers.rs new file mode 100644 index 0000000..8de8d00 --- /dev/null +++ b/src/herlpers.rs @@ -0,0 +1,14 @@ +use std::path::Path; +use std::path::PathBuf; + +pub fn check_if_excel(file: &str) -> bool { + let sce = PathBuf::from(file); + match sce.extension().and_then(|s| s.to_str()) { + Some("xlsx") | Some("xlsm") | Some("xlsb") | Some("xls") => true, + _ => false, + } +} + +pub fn path_exists(file: &str) -> bool { + Path::new(file).exists() +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b86e153 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +pub mod cli_manager; +pub mod configuration_manager; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..48e0bbe --- /dev/null +++ b/src/main.rs @@ -0,0 +1,17 @@ +// using libarary. defined in lib.rs +use xlsx_parser_extractor::{cli_manager::Args, cli_manager::Commands, configuration_manager::Config}; + +fn main() { + let args = Args::parse(); + let Args { file, command } = args; + match command { + Commands::SheetParsing => { + println!("File Path: {} and command: {:?}", file, command); + println!("{:?}", Config::get_configs("configs_input_sheet.toml")); + } + _ => println!("Command: '{:?}'", command), + } + + thre + +}