2016-11-20 23:33:16 +03:00
|
|
|
//! Just fooling around with different ways to count images per year.
|
|
|
|
extern crate rphotos;
|
2017-01-29 22:03:35 +04:00
|
|
|
extern crate brotli2;
|
2016-11-20 23:33:16 +03:00
|
|
|
extern crate clap;
|
2016-11-26 13:31:21 +03:00
|
|
|
extern crate chrono;
|
2016-11-20 23:33:16 +03:00
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
2016-11-21 10:45:54 +03:00
|
|
|
extern crate djangohashers;
|
2016-11-20 23:33:16 +03:00
|
|
|
extern crate dotenv;
|
|
|
|
extern crate env_logger;
|
2017-01-29 22:03:35 +04:00
|
|
|
extern crate flate2;
|
2016-11-21 10:45:54 +03:00
|
|
|
extern crate rand;
|
2016-11-26 13:31:21 +03:00
|
|
|
extern crate rexif;
|
2016-11-25 00:42:57 +03:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
extern crate image;
|
2016-11-27 02:54:08 +03:00
|
|
|
extern crate xml;
|
2016-11-20 23:33:16 +03:00
|
|
|
|
|
|
|
mod adm;
|
|
|
|
mod env;
|
2016-11-25 00:42:57 +03:00
|
|
|
mod photosdir;
|
2016-11-20 23:33:16 +03:00
|
|
|
|
2017-01-29 22:03:35 +04:00
|
|
|
use adm::{findphotos, makepublic, readkpa, users, storestatics};
|
2016-11-21 10:45:54 +03:00
|
|
|
use adm::result::Error;
|
2016-11-20 23:33:16 +03:00
|
|
|
use adm::stats::show_stats;
|
2016-11-21 10:45:54 +03:00
|
|
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
2016-11-20 23:33:16 +03:00
|
|
|
use diesel::pg::PgConnection;
|
|
|
|
use diesel::prelude::*;
|
|
|
|
use dotenv::dotenv;
|
2016-11-25 00:42:57 +03:00
|
|
|
use env::{dburl, photos_dir};
|
|
|
|
use photosdir::PhotosDir;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{self, BufReader};
|
2016-11-26 13:31:21 +03:00
|
|
|
use std::path::Path;
|
2016-11-20 23:33:16 +03:00
|
|
|
use std::process::exit;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
dotenv().ok();
|
|
|
|
env_logger::init().unwrap();
|
2017-08-31 21:32:24 +04:00
|
|
|
let args = App::new("rphotosadm")
|
2017-08-01 03:40:42 +04:00
|
|
|
.version(env!("CARGO_PKG_VERSION"))
|
2016-11-20 23:33:16 +03:00
|
|
|
.about("Command line interface for rphotos")
|
2016-11-26 13:31:21 +03:00
|
|
|
.subcommand(SubCommand::with_name("findphotos")
|
|
|
|
.about("Find new photos in the photo directory")
|
|
|
|
.arg(Arg::with_name("BASE")
|
|
|
|
.multiple(true)
|
|
|
|
.help("Base directory to search in (relative to the \
|
|
|
|
image root).")))
|
2016-11-27 02:54:08 +03:00
|
|
|
.subcommand(SubCommand::with_name("readkpa")
|
|
|
|
.about("Read metadata from my kphotoalbum"))
|
2016-11-20 23:33:16 +03:00
|
|
|
.subcommand(SubCommand::with_name("stats")
|
|
|
|
.about("Show some statistics from the database"))
|
2016-11-21 10:45:54 +03:00
|
|
|
.subcommand(SubCommand::with_name("userlist")
|
2017-02-04 21:12:13 +04:00
|
|
|
.about("List existing users"))
|
2016-11-21 10:45:54 +03:00
|
|
|
.subcommand(SubCommand::with_name("userpass")
|
|
|
|
.about("Set password for a (new or existing) user")
|
2016-11-25 00:42:57 +03:00
|
|
|
.arg(Arg::with_name("USER")
|
2016-11-26 13:31:21 +03:00
|
|
|
.required(true)
|
|
|
|
.help("Username to set password for")))
|
2016-11-25 00:42:57 +03:00
|
|
|
.subcommand(SubCommand::with_name("makepublic")
|
|
|
|
.about("make specific image(s) public")
|
|
|
|
.arg(Arg::with_name("LIST")
|
2016-11-26 13:31:21 +03:00
|
|
|
.long("list")
|
|
|
|
.short("l")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("File listing image paths to make public"))
|
2016-11-25 00:42:57 +03:00
|
|
|
.arg(Arg::with_name("IMAGE")
|
2016-11-26 13:31:21 +03:00
|
|
|
.required_unless("LIST")
|
|
|
|
.help("Image path to make public"))
|
2016-11-25 00:42:57 +03:00
|
|
|
.after_help("The image path(s) are relative to the \
|
|
|
|
image root."))
|
2017-01-29 22:03:35 +04:00
|
|
|
.subcommand(SubCommand::with_name("storestatics")
|
|
|
|
.about("Store statics as files for a web server")
|
|
|
|
.arg(Arg::with_name("DIR")
|
|
|
|
.required(true)
|
|
|
|
.help("Directory to store the files in")))
|
2016-11-20 23:33:16 +03:00
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
match run(args) {
|
|
|
|
Ok(()) => (),
|
|
|
|
Err(err) => {
|
|
|
|
println!("{}", err);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 10:45:54 +03:00
|
|
|
fn run(args: ArgMatches) -> Result<(), Error> {
|
2016-11-20 23:33:16 +03:00
|
|
|
match args.subcommand() {
|
2016-11-26 13:31:21 +03:00
|
|
|
("findphotos", Some(args)) => {
|
|
|
|
let pd = PhotosDir::new(photos_dir());
|
2017-05-09 00:01:59 +04:00
|
|
|
let db = get_db()?;
|
2016-11-26 13:31:21 +03:00
|
|
|
if let Some(bases) = args.values_of("BASE") {
|
|
|
|
for base in bases {
|
2017-05-09 00:01:59 +04:00
|
|
|
findphotos::crawl(&db, &pd, Path::new(&base))
|
2017-02-04 21:12:13 +04:00
|
|
|
.map_err(|e| {
|
|
|
|
Error::Other(format!("Failed to crawl {}: {}",
|
|
|
|
base,
|
|
|
|
e))
|
2017-05-09 00:01:59 +04:00
|
|
|
})?;
|
2016-11-26 13:31:21 +03:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-09 00:01:59 +04:00
|
|
|
findphotos::crawl(&db, &pd, Path::new(""))
|
2016-11-26 13:31:21 +03:00
|
|
|
.map_err(|e| Error::Other(
|
2017-05-09 00:01:59 +04:00
|
|
|
format!("Failed to crawl: {}", e)))?;
|
2016-11-26 13:31:21 +03:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2016-11-25 00:42:57 +03:00
|
|
|
("makepublic", Some(args)) => {
|
|
|
|
let pd = PhotosDir::new(photos_dir());
|
2017-05-09 00:01:59 +04:00
|
|
|
let db = get_db()?;
|
2016-11-26 14:32:16 +03:00
|
|
|
match args.value_of("LIST") {
|
|
|
|
Some("-") => {
|
2016-11-25 00:42:57 +03:00
|
|
|
let list = io::stdin();
|
2017-05-09 00:01:59 +04:00
|
|
|
makepublic::by_file_list(&db, &pd, list.lock())?;
|
2016-11-26 14:32:16 +03:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
Some(f) => {
|
2017-05-09 00:01:59 +04:00
|
|
|
let list = File::open(f)?;
|
2016-11-25 00:42:57 +03:00
|
|
|
let list = BufReader::new(list);
|
2016-11-26 14:32:16 +03:00
|
|
|
makepublic::by_file_list(&db, &pd, list)
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
makepublic::one(&db, &pd, args.value_of("IMAGE").unwrap())
|
2016-11-25 00:42:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-27 02:54:08 +03:00
|
|
|
("readkpa", Some(_args)) => {
|
2017-05-09 00:01:59 +04:00
|
|
|
readkpa::readkpa(&get_db()?, &photos_dir())
|
2016-11-27 02:54:08 +03:00
|
|
|
}
|
2017-05-09 00:01:59 +04:00
|
|
|
("stats", Some(_args)) => show_stats(&get_db()?),
|
|
|
|
("userlist", Some(_args)) => users::list(&get_db()?),
|
2016-11-26 13:31:21 +03:00
|
|
|
("userpass", Some(args)) => {
|
2017-05-09 00:01:59 +04:00
|
|
|
users::passwd(&get_db()?, args.value_of("USER").unwrap())
|
2016-11-26 13:31:21 +03:00
|
|
|
}
|
2017-01-29 22:03:35 +04:00
|
|
|
("storestatics", Some(args)) => {
|
|
|
|
storestatics::to_dir(args.value_of("DIR").unwrap())
|
|
|
|
}
|
2016-11-20 23:33:16 +03:00
|
|
|
_ => Ok(println!("No subcommand given.\n\n{}", args.usage())),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_db() -> Result<PgConnection, ConnectionError> {
|
|
|
|
PgConnection::establish(&dburl())
|
|
|
|
}
|