Initial split into workspaces in order to be more flexible.
This commit is contained in:
parent
98f7f6e37a
commit
f25ce64e34
1462
Cargo.lock
generated
1462
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
35
Cargo.toml
35
Cargo.toml
@ -1,30 +1,5 @@
|
|||||||
[package]
|
[workspace]
|
||||||
name = "hammond"
|
members = [
|
||||||
version = "0.1.0"
|
"hammond-data",
|
||||||
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
"other"
|
||||||
|
]
|
||||||
[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"
|
|
||||||
|
|||||||
6
hammond-cli/Cargo.toml
Normal file
6
hammond-cli/Cargo.toml
Normal 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
27
hammond-data/Cargo.toml
Normal 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 = "*"
|
||||||
|
|
||||||
@ -25,12 +25,9 @@ extern crate rss;
|
|||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate xdg;
|
extern crate xdg;
|
||||||
|
|
||||||
pub mod schema;
|
|
||||||
pub mod models;
|
|
||||||
pub mod feedparser;
|
|
||||||
pub mod index_feed;
|
|
||||||
pub mod dbqueries;
|
pub mod dbqueries;
|
||||||
pub mod downloader;
|
pub mod models;
|
||||||
|
pub mod schema;
|
||||||
|
|
||||||
pub mod errors {
|
pub mod errors {
|
||||||
|
|
||||||
@ -96,12 +93,13 @@ lazy_static!{
|
|||||||
HAMMOND_XDG.place_data_file("hammond.db").unwrap()
|
HAMMOND_XDG.place_data_file("hammond.db").unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
static ref DL_DIR: PathBuf = {
|
pub static ref DL_DIR: PathBuf = {
|
||||||
&HAMMOND_DATA;
|
&HAMMOND_DATA;
|
||||||
HAMMOND_XDG.create_data_directory("Downloads").unwrap()
|
HAMMOND_XDG.create_data_directory("Downloads").unwrap()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: REFACTOR
|
||||||
pub fn init() -> Result<()> {
|
pub fn init() -> Result<()> {
|
||||||
let conn = establish_connection();
|
let conn = establish_connection();
|
||||||
// embedded_migrations::run(&conn)?;
|
// embedded_migrations::run(&conn)?;
|
||||||
@ -110,6 +108,11 @@ pub fn init() -> Result<()> {
|
|||||||
Ok(())
|
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 {
|
pub fn establish_connection() -> SqliteConnection {
|
||||||
let database_url = DB_PATH.to_str().unwrap();
|
let database_url = DB_PATH.to_str().unwrap();
|
||||||
// let database_url = &String::from(".random/foo.db");
|
// let database_url = &String::from(".random/foo.db");
|
||||||
@ -247,13 +247,3 @@ pub struct NewPodcast {
|
|||||||
pub image_uri: Option<String>,
|
pub image_uri: Option<String>,
|
||||||
pub source_id: i32,
|
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
24
other/Cargo.toml
Normal 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"
|
||||||
@ -6,8 +6,8 @@ use std::fs::{rename, DirBuilder, File};
|
|||||||
use std::io::{BufWriter, Read, Write};
|
use std::io::{BufWriter, Read, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use errors::*;
|
use hammond_data::errors::*;
|
||||||
use dbqueries;
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
// Adapted from https://github.com/mattgathu/rget .
|
// Adapted from https://github.com/mattgathu/rget .
|
||||||
// I never wanted to write a custom downloader.
|
// 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.
|
// Initial messy prototype, queries load alot of not needed stuff.
|
||||||
pub fn latest_dl(connection: &SqliteConnection, limit: u32) -> Result<()> {
|
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)?;
|
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
|
// 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
|
// Create the folder
|
||||||
DirBuilder::new().recursive(true).create(&dl_fold).unwrap();
|
DirBuilder::new().recursive(true).create(&dl_fold).unwrap();
|
||||||
@ -1,8 +1,8 @@
|
|||||||
use rss::{Channel, Item};
|
use rss::{Channel, Item};
|
||||||
use rfc822_sanitizer::parse_from_rfc2822_with_fallback;
|
use rfc822_sanitizer::parse_from_rfc2822_with_fallback;
|
||||||
|
|
||||||
use models;
|
use hammond_data::models;
|
||||||
use errors::*;
|
use hammond_data::errors::*;
|
||||||
|
|
||||||
pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcast> {
|
pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcast> {
|
||||||
let title = chan.title().to_owned();
|
let title = chan.title().to_owned();
|
||||||
@ -7,11 +7,11 @@ use reqwest;
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use schema;
|
use hammond_data::schema;
|
||||||
use dbqueries;
|
use hammond_data::dbqueries;
|
||||||
|
use hammond_data::errors::*;
|
||||||
|
use hammond_data::models::*;
|
||||||
use feedparser;
|
use feedparser;
|
||||||
use errors::*;
|
|
||||||
use models::*;
|
|
||||||
|
|
||||||
fn index_source(con: &SqliteConnection, foo: &NewSource) -> Result<()> {
|
fn index_source(con: &SqliteConnection, foo: &NewSource) -> Result<()> {
|
||||||
match dbqueries::load_source(con, foo.uri) {
|
match dbqueries::load_source(con, foo.uri) {
|
||||||
@ -209,8 +209,11 @@ fn refresh_source(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
|
extern crate hammond_data;
|
||||||
extern crate tempdir;
|
extern crate tempdir;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
// use diesel::embed_migrations;
|
||||||
use rss;
|
use rss;
|
||||||
|
|
||||||
use std::io::{stdout, BufReader};
|
use std::io::{stdout, BufReader};
|
||||||
@ -219,7 +222,6 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
embed_migrations!("migrations/");
|
|
||||||
// struct TempDB {
|
// struct TempDB {
|
||||||
// tmp_dir: tempdir::TempDir,
|
// tmp_dir: tempdir::TempDir,
|
||||||
// db_path: PathBuf,
|
// db_path: PathBuf,
|
||||||
@ -236,7 +238,7 @@ mod tests {
|
|||||||
let db_path = tmp_dir.path().join("foo_tests.db");
|
let db_path = tmp_dir.path().join("foo_tests.db");
|
||||||
|
|
||||||
let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap();
|
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 {
|
// TempDB {
|
||||||
// tmp_dir,
|
// tmp_dir,
|
||||||
15
other/src/lib.rs
Normal file
15
other/src/lib.rs
Normal 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;
|
||||||
@ -8,13 +8,14 @@ extern crate structopt_derive;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate error_chain;
|
||||||
|
|
||||||
extern crate hammond;
|
extern crate hammond_data;
|
||||||
|
extern crate other;
|
||||||
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use hammond::errors::*;
|
use hammond_data::errors::*;
|
||||||
use hammond::downloader;
|
use hammond_data::dbqueries;
|
||||||
use hammond::index_feed;
|
use other::downloader;
|
||||||
use hammond::dbqueries;
|
use other::index_feed;
|
||||||
|
|
||||||
// Should probably had made an Enum instead.
|
// Should probably had made an Enum instead.
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
@ -38,27 +39,27 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
loggerv::init_with_verbosity(args.verbosity)?;
|
loggerv::init_with_verbosity(args.verbosity)?;
|
||||||
|
|
||||||
hammond::init()?;
|
hammond_data::init()?;
|
||||||
|
|
||||||
// Initial prototype for testing.
|
// Initial prototype for testing.
|
||||||
// The plan is to write a Gtk+ gui later.
|
// The plan is to write a Gtk+ gui later.
|
||||||
if args.add != "".to_string() {
|
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);
|
let _ = index_feed::insert_return_source(&db, &args.add);
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.up {
|
if args.up {
|
||||||
let db = hammond::establish_connection();
|
let db = hammond_data::establish_connection();
|
||||||
index_feed::index_loop(db)?;
|
index_feed::index_loop(db)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.dl >= 0 {
|
if args.dl >= 0 {
|
||||||
let db = hammond::establish_connection();
|
let db = hammond_data::establish_connection();
|
||||||
downloader::latest_dl(&db, args.dl as u32)?;
|
downloader::latest_dl(&db, args.dl as u32)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.latest {
|
if args.latest {
|
||||||
let db = hammond::establish_connection();
|
let db = hammond_data::establish_connection();
|
||||||
let foo = dbqueries::get_episodes_with_limit(&db, 10)?;
|
let foo = dbqueries::get_episodes_with_limit(&db, 10)?;
|
||||||
// This ends up horribly but works for now.
|
// This ends up horribly but works for now.
|
||||||
let _: Vec<_> = foo.iter().map(|x| println!("{:?}", x)).collect();
|
let _: Vec<_> = foo.iter().map(|x| println!("{:?}", x)).collect();
|
||||||
@ -1,5 +1,5 @@
|
|||||||
extern crate assert_cli;
|
extern crate assert_cli;
|
||||||
extern crate hammond;
|
extern crate other;
|
||||||
|
|
||||||
// Notes:
|
// Notes:
|
||||||
// The following tests will use your systems local hammond db.
|
// The following tests will use your systems local hammond db.
|
||||||
Loading…
Reference in New Issue
Block a user