Initial split into workspaces in order to be more flexible.

This commit is contained in:
Jordan Petridis 2017-10-04 22:41:17 +03:00
parent 98f7f6e37a
commit f25ce64e34
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
21 changed files with 113 additions and 1531 deletions

1462
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +1,5 @@
[package]
name = "hammond"
version = "0.1.0"
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
[dependencies]
rfc822_sanitizer = "0.3.0"
rayon = "0.8.2"
regex = "0.2"
error-chain = "0.11.0"
structopt = "0.1.0"
structopt-derive = "0.1.0"
log = "0.3.8"
loggerv = "0.3.0"
reqwest = "0.7.3"
hyper = "0.11.2"
diesel = { version = "0.16.0", features = ["sqlite", "deprecated-time", "chrono"] }
diesel_codegen = { version = "0.16.0", features = ["sqlite"] }
time = "0.1.38"
xdg = "2.1.0"
lazy_static = "0.2.8"
chrono = "0.4.0"
rss = { version = "1.1.0", features = ["from_url"]}
# overide diesel's dependancy that would otherwise turn a dotenv feature of
# that rss depends upon
dotenv = "*"
[dev-dependencies]
tempdir = "0.3.5"
assert_cli = "0.5"
[workspace]
members = [
"hammond-data",
"other"
]

6
hammond-cli/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "hammond-cli"
version = "0.1.0"
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
[dependencies]

27
hammond-data/Cargo.toml Normal file
View File

@ -0,0 +1,27 @@
[package]
name = "hammond-data"
version = "0.1.0"
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
[dependencies]
rfc822_sanitizer = "0.3.0"
rayon = "0.8.2"
regex = "0.2"
error-chain = "0.11.0"
structopt = "0.1.0"
structopt-derive = "0.1.0"
log = "0.3.8"
loggerv = "0.3.0"
reqwest = "0.7.3"
hyper = "0.11.2"
diesel = { version = "0.16.0", features = ["sqlite", "deprecated-time", "chrono"] }
diesel_codegen = { version = "0.16.0", features = ["sqlite"] }
time = "0.1.38"
xdg = "2.1.0"
lazy_static = "0.2.8"
chrono = "0.4.0"
rss = { version = "1.1.0", features = ["from_url"]}
# overide diesel's dependancy that would otherwise turn a dotenv feature of
# that rss depends upon
dotenv = "*"

View File

@ -25,12 +25,9 @@ extern crate rss;
extern crate time;
extern crate xdg;
pub mod schema;
pub mod models;
pub mod feedparser;
pub mod index_feed;
pub mod dbqueries;
pub mod downloader;
pub mod models;
pub mod schema;
pub mod errors {
@ -96,12 +93,13 @@ lazy_static!{
HAMMOND_XDG.place_data_file("hammond.db").unwrap()
};
static ref DL_DIR: PathBuf = {
pub static ref DL_DIR: PathBuf = {
&HAMMOND_DATA;
HAMMOND_XDG.create_data_directory("Downloads").unwrap()
};
}
// TODO: REFACTOR
pub fn init() -> Result<()> {
let conn = establish_connection();
// embedded_migrations::run(&conn)?;
@ -110,6 +108,11 @@ pub fn init() -> Result<()> {
Ok(())
}
pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {
embedded_migrations::run_with_output(connection, &mut std::io::stdout())?;
Ok(())
}
pub fn establish_connection() -> SqliteConnection {
let database_url = DB_PATH.to_str().unwrap();
// let database_url = &String::from(".random/foo.db");

View File

@ -247,13 +247,3 @@ pub struct NewPodcast {
pub image_uri: Option<String>,
pub source_id: i32,
}
impl NewPodcast {
// FIXME: This method seems to not be used anywhere atm.
// Drop dead code maybe?
pub fn from_url(uri: &str, parent: &Source) -> Result<NewPodcast> {
let chan = Channel::from_url(uri)?;
let foo = ::feedparser::parse_podcast(&chan, parent.id())?;
Ok(foo)
}
}

24
other/Cargo.toml Normal file
View File

@ -0,0 +1,24 @@
[package]
name = "other"
version = "0.1.0"
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
[dependencies]
hammond-data = {path = "../hammond-data"}
rayon = "0.8.2"
error-chain = "0.11.0"
structopt = "0.1.0"
structopt-derive = "0.1.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", "deprecated-time", "chrono"] }
diesel_codegen = { version = "0.16.0", features = ["sqlite"] }
rss = { version = "1.1.0", features = ["from_url"]}
dotenv = "*"
[dev-dependencies]
tempdir = "0.3.5"
assert_cli = "0.5"

View File

@ -6,8 +6,8 @@ use std::fs::{rename, DirBuilder, File};
use std::io::{BufWriter, Read, Write};
use std::path::Path;
use errors::*;
use dbqueries;
use hammond_data::errors::*;
use hammond_data::dbqueries;
// Adapted from https://github.com/mattgathu/rget .
// I never wanted to write a custom downloader.
@ -54,7 +54,8 @@ 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 models::Episode;
use hammond_data::models::Episode;
use hammond_data::DL_DIR;
let pds = dbqueries::get_podcasts(connection)?;
@ -70,7 +71,7 @@ pub fn latest_dl(connection: &SqliteConnection, limit: u32) -> Result<()> {
}
// It might be better to make it a hash of the title
let dl_fold = format!("{}/{}", ::DL_DIR.to_str().unwrap(), x.title());
let dl_fold = format!("{}/{}", DL_DIR.to_str().unwrap(), x.title());
// Create the folder
DirBuilder::new().recursive(true).create(&dl_fold).unwrap();

View File

@ -1,8 +1,8 @@
use rss::{Channel, Item};
use rfc822_sanitizer::parse_from_rfc2822_with_fallback;
use models;
use errors::*;
use hammond_data::models;
use hammond_data::errors::*;
pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcast> {
let title = chan.title().to_owned();

View File

@ -7,11 +7,11 @@ use reqwest;
use rayon::prelude::*;
use std::sync::{Arc, Mutex};
use schema;
use dbqueries;
use hammond_data::schema;
use hammond_data::dbqueries;
use hammond_data::errors::*;
use hammond_data::models::*;
use feedparser;
use errors::*;
use models::*;
fn index_source(con: &SqliteConnection, foo: &NewSource) -> Result<()> {
match dbqueries::load_source(con, foo.uri) {
@ -209,8 +209,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};
@ -219,7 +222,6 @@ mod tests {
use super::*;
embed_migrations!("migrations/");
// struct TempDB {
// tmp_dir: tempdir::TempDir,
// db_path: PathBuf,
@ -236,7 +238,7 @@ mod tests {
let db_path = tmp_dir.path().join("foo_tests.db");
let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap();
embedded_migrations::run_with_output(&db, &mut stdout()).unwrap();
hammond_data::run_migration_on(&db).unwrap();
// TempDB {
// tmp_dir,

15
other/src/lib.rs Normal file
View File

@ -0,0 +1,15 @@
#![feature(use_extern_macros)]
extern crate diesel;
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;

View File

@ -8,13 +8,14 @@ extern crate structopt_derive;
#[macro_use]
extern crate error_chain;
extern crate hammond;
extern crate hammond_data;
extern crate other;
use structopt::StructOpt;
use hammond::errors::*;
use hammond::downloader;
use hammond::index_feed;
use hammond::dbqueries;
use hammond_data::errors::*;
use hammond_data::dbqueries;
use other::downloader;
use other::index_feed;
// Should probably had made an Enum instead.
#[derive(StructOpt, Debug)]
@ -38,27 +39,27 @@ fn run() -> Result<()> {
loggerv::init_with_verbosity(args.verbosity)?;
hammond::init()?;
hammond_data::init()?;
// Initial prototype for testing.
// The plan is to write a Gtk+ gui later.
if args.add != "".to_string() {
let db = hammond::establish_connection();
let db = hammond_data::establish_connection();
let _ = index_feed::insert_return_source(&db, &args.add);
}
if args.up {
let db = hammond::establish_connection();
let db = hammond_data::establish_connection();
index_feed::index_loop(db)?;
}
if args.dl >= 0 {
let db = hammond::establish_connection();
let db = hammond_data::establish_connection();
downloader::latest_dl(&db, args.dl as u32)?;
}
if args.latest {
let db = hammond::establish_connection();
let db = hammond_data::establish_connection();
let foo = dbqueries::get_episodes_with_limit(&db, 10)?;
// This ends up horribly but works for now.
let _: Vec<_> = foo.iter().map(|x| println!("{:?}", x)).collect();

View File

@ -1,5 +1,5 @@
extern crate assert_cli;
extern crate hammond;
extern crate other;
// Notes:
// The following tests will use your systems local hammond db.