diff --git a/Cargo.toml b/Cargo.toml index 3c20e19..d2bb646 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,5 +2,5 @@ members = [ "hammond-data", "hammond-cli", - "other" + "hammond-downloader" ] diff --git a/hammond-cli/Cargo.toml b/hammond-cli/Cargo.toml index 691c422..fa8503d 100644 --- a/hammond-cli/Cargo.toml +++ b/hammond-cli/Cargo.toml @@ -10,7 +10,7 @@ structopt = "0.1.0" structopt-derive = "0.1.0" error-chain = "0.11.0" hammond-data = {path = "../hammond-data"} -other = {path = "../other"} +hammond-downloader = {path = "../hammond-downloader"} [dev-dependencies] assert_cli = "0.5" \ No newline at end of file diff --git a/hammond-cli/src/main.rs b/hammond-cli/src/main.rs index 2e94ba5..5a3646b 100644 --- a/hammond-cli/src/main.rs +++ b/hammond-cli/src/main.rs @@ -1,21 +1,21 @@ extern crate log; extern crate loggerv; +#[macro_use] +extern crate error_chain; extern crate structopt; #[macro_use] extern crate structopt_derive; -#[macro_use] -extern crate error_chain; -extern crate other; extern crate hammond_data; +extern crate hammond_downloader; use structopt::StructOpt; use hammond_data::dbqueries; -use other::errors::*; -use other::downloader; -use other::index_feed; - +use hammond_data::errors::*; +use hammond_data::index_feed; +use hammond_downloader::downloader; + // Should probably had made an Enum instead. #[derive(StructOpt, Debug)] #[structopt(name = "example", about = "An example of StructOpt usage.")] @@ -36,7 +36,7 @@ struct Opt { fn run() -> Result<()> { let args = Opt::from_args(); - loggerv::init_with_verbosity(args.verbosity)?; + loggerv::init_with_verbosity(args.verbosity).unwrap(); hammond_data::init()?; @@ -54,7 +54,7 @@ fn run() -> Result<()> { if args.dl >= 0 { let db = hammond_data::establish_connection(); - downloader::latest_dl(&db, args.dl as u32)?; + downloader::latest_dl(&db, args.dl as u32).unwrap(); } if args.latest { diff --git a/hammond-cli/tests/test_cli.rs b/hammond-cli/tests/test_cli.rs index 4ef076e..8f19d3f 100644 --- a/hammond-cli/tests/test_cli.rs +++ b/hammond-cli/tests/test_cli.rs @@ -34,4 +34,4 @@ fn test_latest() { assert_cli::Assert::main_binary() .with_args(&["--latest"]) .unwrap(); -} \ No newline at end of file +} diff --git a/hammond-data/Cargo.toml b/hammond-data/Cargo.toml index 8d97eef..c01bd38 100644 --- a/hammond-data/Cargo.toml +++ b/hammond-data/Cargo.toml @@ -4,13 +4,19 @@ version = "0.1.0" authors = ["Jordan Petridis "] [dependencies] +rfc822_sanitizer = "0.3.0" rayon = "0.8.2" +hyper = "0.11.2" +reqwest = "0.7.3" error-chain = "0.11.0" log = "0.3.8" loggerv = "0.3.0" -reqwest = "0.7.3" diesel = { version = "0.16.0", features = ["sqlite", "deprecated-time", "chrono"] } diesel_codegen = { version = "0.16.0", features = ["sqlite"] } xdg = "2.1.0" lazy_static = "0.2.8" +rss = { version = "1.1.0", features = ["from_url"]} +dotenv = "*" +[dev-dependencies] +tempdir = "0.3.5" \ No newline at end of file diff --git a/other/src/feedparser.rs b/hammond-data/src/feedparser.rs similarity index 99% rename from other/src/feedparser.rs rename to hammond-data/src/feedparser.rs index 29c7944..ed080ee 100644 --- a/other/src/feedparser.rs +++ b/hammond-data/src/feedparser.rs @@ -1,7 +1,7 @@ use rss::{Channel, Item}; use rfc822_sanitizer::parse_from_rfc2822_with_fallback; -use hammond_data::models; +use models; use errors::*; pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result { diff --git a/other/src/index_feed.rs b/hammond-data/src/index_feed.rs similarity index 97% rename from other/src/index_feed.rs rename to hammond-data/src/index_feed.rs index 7beb575..b6b918c 100644 --- a/other/src/index_feed.rs +++ b/hammond-data/src/index_feed.rs @@ -7,10 +7,9 @@ use reqwest; use rayon::prelude::*; use std::sync::{Arc, Mutex}; -use hammond_data::schema; -use hammond_data::dbqueries; -use hammond_data::models::*; - +use schema; +use dbqueries; +use models::*; use errors::*; use feedparser; @@ -211,13 +210,11 @@ fn refresh_source( #[cfg(test)] mod tests { - extern crate hammond_data; extern crate tempdir; use diesel::prelude::*; - // use diesel::embed_migrations; use rss; - use std::io::{stdout, BufReader}; + use std::io::BufReader; use std::path::PathBuf; use std::fs; @@ -239,7 +236,7 @@ mod tests { let db_path = tmp_dir.path().join("foo_tests.db"); let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap(); - hammond_data::run_migration_on(&db).unwrap(); + ::run_migration_on(&db).unwrap(); // TempDB { // tmp_dir, diff --git a/hammond-data/src/lib.rs b/hammond-data/src/lib.rs index 46ca47a..9729ccd 100644 --- a/hammond-data/src/lib.rs +++ b/hammond-data/src/lib.rs @@ -17,21 +17,35 @@ extern crate diesel_codegen; extern crate rayon; extern crate reqwest; +extern crate hyper; extern crate xdg; +extern crate rss; +extern crate rfc822_sanitizer; pub mod dbqueries; pub mod models; pub mod schema; +pub mod index_feed; +pub mod feedparser; + pub mod errors { use diesel::migrations::RunMigrationsError; use diesel::result; + use rss; + use hyper; + use reqwest; + use std::io; error_chain! { foreign_links { MigrationError(RunMigrationsError); DieselResultError(result::Error); + RSSError(rss::Error); + HyperError(hyper::error::Error); + ReqError(reqwest::Error); + IoError(io::Error); } } } diff --git a/other/tests/feeds/Intercepted.xml b/hammond-data/tests/feeds/Intercepted.xml similarity index 100% rename from other/tests/feeds/Intercepted.xml rename to hammond-data/tests/feeds/Intercepted.xml diff --git a/other/tests/feeds/LinuxUnplugged.xml b/hammond-data/tests/feeds/LinuxUnplugged.xml similarity index 100% rename from other/tests/feeds/LinuxUnplugged.xml rename to hammond-data/tests/feeds/LinuxUnplugged.xml diff --git a/other/tests/feeds/R4Explanation.xml b/hammond-data/tests/feeds/R4Explanation.xml similarity index 100% rename from other/tests/feeds/R4Explanation.xml rename to hammond-data/tests/feeds/R4Explanation.xml diff --git a/other/tests/feeds/TheBreakthrough.xml b/hammond-data/tests/feeds/TheBreakthrough.xml similarity index 100% rename from other/tests/feeds/TheBreakthrough.xml rename to hammond-data/tests/feeds/TheBreakthrough.xml diff --git a/other/Cargo.toml b/hammond-downloader/Cargo.toml similarity index 81% rename from other/Cargo.toml rename to hammond-downloader/Cargo.toml index 04874ea..c63d5d4 100644 --- a/other/Cargo.toml +++ b/hammond-downloader/Cargo.toml @@ -1,21 +1,16 @@ [package] -name = "other" +name = "hammond-downloader" version = "0.1.0" authors = ["Jordan Petridis "] [dependencies] hammond-data = {path = "../hammond-data"} -rayon = "0.8.2" error-chain = "0.11.0" log = "0.3.8" loggerv = "0.3.0" -rfc822_sanitizer = "0.3.0" reqwest = "0.7.3" hyper = "0.11.2" diesel = { version = "0.16.0", features = ["sqlite"] } diesel_codegen = { version = "0.16.0", features = ["sqlite"] } rss = { version = "1.1.0", features = ["from_url"]} dotenv = "*" - -[dev-dependencies] -tempdir = "0.3.5" diff --git a/other/src/downloader.rs b/hammond-downloader/src/downloader.rs similarity index 98% rename from other/src/downloader.rs rename to hammond-downloader/src/downloader.rs index 08281a5..5b02e64 100644 --- a/other/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -8,6 +8,8 @@ use std::path::Path; use errors::*; use hammond_data::dbqueries; +use hammond_data::models::Episode; +use hammond_data::DL_DIR; // Adapted from https://github.com/mattgathu/rget . // I never wanted to write a custom downloader. @@ -54,9 +56,6 @@ pub fn download_to(target: &str, url: &str) -> Result<()> { // Initial messy prototype, queries load alot of not needed stuff. pub fn latest_dl(connection: &SqliteConnection, limit: u32) -> Result<()> { - use hammond_data::models::Episode; - use hammond_data::DL_DIR; - let pds = dbqueries::get_podcasts(connection)?; pds.iter() diff --git a/other/src/errors.rs b/hammond-downloader/src/errors.rs similarity index 77% rename from other/src/errors.rs rename to hammond-downloader/src/errors.rs index 295795e..40c99e4 100644 --- a/other/src/errors.rs +++ b/hammond-downloader/src/errors.rs @@ -1,6 +1,5 @@ use reqwest; use rss; -use hyper; use diesel::result; use hammond_data; @@ -10,10 +9,8 @@ error_chain! { foreign_links { ReqError(reqwest::Error); IoError(io::Error); - Log(::log::SetLoggerError); RSSError(rss::Error); DieselResultError(result::Error); - HyperError(hyper::error::Error); HamDBError(hammond_data::errors::Error); } } diff --git a/other/src/lib.rs b/hammond-downloader/src/lib.rs similarity index 72% rename from other/src/lib.rs rename to hammond-downloader/src/lib.rs index 8a5760f..2e5de1f 100644 --- a/other/src/lib.rs +++ b/hammond-downloader/src/lib.rs @@ -7,12 +7,8 @@ extern crate hammond_data; extern crate hyper; #[macro_use] extern crate log; -extern crate rayon; extern crate reqwest; -extern crate rfc822_sanitizer; extern crate rss; -pub mod feedparser; pub mod downloader; -pub mod index_feed; pub mod errors;