Continuing work
This commit is contained in:
@@ -80,10 +80,6 @@ fn main() {
|
||||
chosen_act.print_action_and_flags();
|
||||
|
||||
let cmt_mgr = managers::commit_manager::CommitManager {
|
||||
// action: String::from(""),
|
||||
// flags: Vec::new(),
|
||||
// params: Vec::new(),
|
||||
// param_count: 1,
|
||||
ica_action: chosen_act,
|
||||
};
|
||||
|
||||
|
||||
@@ -39,10 +39,6 @@ impl ActionManager {
|
||||
];
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
/**
|
||||
fn supported_actions(&self) {}
|
||||
*/
|
||||
|
||||
pub fn initialize(&mut self) {
|
||||
self.validate_flags();
|
||||
@@ -57,7 +53,7 @@ impl ActionManager {
|
||||
|
||||
let mut i = 0;
|
||||
println!("Flag count: {}", flag_vals.len());
|
||||
// for mut i in 0..flag_vals.len() {
|
||||
|
||||
while i < flag_vals.len() {
|
||||
let flag = &flag_vals[i];
|
||||
println!("Index: {} | Value: {}", i, flag);
|
||||
@@ -68,9 +64,8 @@ impl ActionManager {
|
||||
println!("Flag has value");
|
||||
flg.flag = String::from(flag);
|
||||
flg.value = String::from(&flag_vals[i + 1]);
|
||||
// println!("Before change {}", i);
|
||||
|
||||
i = i + 1;
|
||||
// println!("After change {}", i);
|
||||
} else if self.is_valid_flag(flag) {
|
||||
println!("Flag does not have a value");
|
||||
flg.flag = String::from(flag);
|
||||
@@ -85,10 +80,10 @@ impl ActionManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_action(&self) {
|
||||
fn validate_action(&mut self) {
|
||||
if self.params.len() >= 2 {
|
||||
let act = &self.params[1];
|
||||
println!("The action {}", act);
|
||||
self.action = String::from(act);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+168
-24
@@ -1,22 +1,22 @@
|
||||
use std::collections::HashMap;
|
||||
use std::default::Default;
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Error};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::managers;
|
||||
use crate::{exit_program, managers};
|
||||
use crate::models;
|
||||
use crate::parsers;
|
||||
use crate::syncers;
|
||||
use crate::utilities;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CommitManager {
|
||||
// pub action: String,
|
||||
// pub flags: Vec<models::flags::Flags>,
|
||||
// pub params: Vec<String>,
|
||||
// pub param_count: i32,
|
||||
pub ica_action: models::icarus_action::IcarusAction,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Album {
|
||||
pub title: String,
|
||||
pub album_artist: String,
|
||||
@@ -62,7 +62,7 @@ impl Album {
|
||||
println!("Genre: {}", self.genre);
|
||||
println!("Year: {}", self.year);
|
||||
println!("Track Count: {}", self.track_count);
|
||||
println!("Disc Count: {}", self.disc_count);
|
||||
println!("Disc Count: {}\n", self.disc_count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,17 @@ impl CommitManager {
|
||||
let mapped_action = self.find_mapped_action(&mapped_actions, action);
|
||||
|
||||
println!("{:?}", mapped_action);
|
||||
|
||||
match mapped_action {
|
||||
ActionValues::DeleteAct => self.delete_song(),
|
||||
ActionValues::DownloadAct => self.download_song(),
|
||||
ActionValues::RetrieveAct => self.retrieve_object(),
|
||||
ActionValues::UploadAct => self.upload_song(),
|
||||
ActionValues::UploadSongWithMetadata => self.upload_song_with_metadata(),
|
||||
_ => {
|
||||
println!("Nothing good here");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn find_mapped_action(
|
||||
@@ -94,7 +105,7 @@ impl CommitManager {
|
||||
fn map_actions(&self) -> HashMap<String, ActionValues> {
|
||||
let mut actions: HashMap<String, ActionValues> = HashMap::new();
|
||||
actions.insert("download".to_string(), ActionValues::DownloadAct);
|
||||
// actions.insert("upload".to_string(), ActionValues::UploadAct);
|
||||
actions.insert("upload".to_string(), ActionValues::UploadAct);
|
||||
actions.insert(
|
||||
"upload-meta".to_string(),
|
||||
ActionValues::UploadSongWithMetadata,
|
||||
@@ -111,14 +122,31 @@ impl CommitManager {
|
||||
ica_act: self.ica_action.clone(),
|
||||
api: models::api::API::default(),
|
||||
};
|
||||
prsr.parse_api();
|
||||
let api = prsr.retrieve_api();
|
||||
|
||||
let token = self.parse_token(&api);
|
||||
|
||||
println!("Deleting song");
|
||||
|
||||
let api = prsr.retrieve_api();
|
||||
let mut song = models::song::Song::default();
|
||||
|
||||
let song = models::song::Song::default();
|
||||
for arg in &self.ica_action.flags {
|
||||
let flag = &arg.flag;
|
||||
let value = &arg.value;
|
||||
|
||||
for arg in &self.ica_action.flags {}
|
||||
if flag == "-D" {
|
||||
song.id = Some(value.parse::<i32>().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
let del = syncers::delete::Delete {
|
||||
api: api,
|
||||
};
|
||||
|
||||
println!("Deleting song..");
|
||||
|
||||
del.delete_song(&token, &song);
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
@@ -148,6 +176,7 @@ impl CommitManager {
|
||||
},
|
||||
ica_action: self.ica_action.clone(),
|
||||
};
|
||||
usr_mgr.parse_user_from_actions();
|
||||
|
||||
let usr = usr_mgr.retrieve_user();
|
||||
let tok_mgr = managers::token_manager::TokenManager {
|
||||
@@ -171,14 +200,31 @@ impl CommitManager {
|
||||
) {
|
||||
}
|
||||
// TODO: Implement
|
||||
fn multi_target_upload(&self, sourcepath: &String) {}
|
||||
// TODO: Implement
|
||||
fn multi_target_upload(&self, sourcepath: &String) {
|
||||
let mut prsr = parsers::api_parser::APIParser {
|
||||
api: models::api::API::default(),
|
||||
ica_act: self.ica_action.clone(),
|
||||
};
|
||||
prsr.parse_api();
|
||||
let api = prsr.retrieve_api();
|
||||
let token = self.parse_token(&api);
|
||||
|
||||
let directory_path = std::path::Path::new(&sourcepath);
|
||||
|
||||
if !directory_path.exists() {
|
||||
println!("Directory does not exist");
|
||||
std::process::exit(-1);
|
||||
}
|
||||
|
||||
// let mut cover_art = models::
|
||||
}
|
||||
|
||||
// Standards
|
||||
// * track01.cdda.wav - Disc 1, Track 1
|
||||
// * track02d02.cdda.wav - Disc 2, Track 2
|
||||
fn initialize_disc_and_track(&mut self, song: &mut models::song::Song) {
|
||||
let disc = 1;
|
||||
let track = 1;
|
||||
let mut disc = 1;
|
||||
let mut track = 1;
|
||||
let mut mode = 0;
|
||||
let songpath = song.song_path();
|
||||
let filename =
|
||||
@@ -220,25 +266,102 @@ impl CommitManager {
|
||||
|
||||
index += 1;
|
||||
}
|
||||
// let t = &filename[1..5];
|
||||
|
||||
if utilities::checks::Checks::is_numeric(&t) {
|
||||
track = t.parse::<i32>().unwrap();
|
||||
}
|
||||
disc = 1
|
||||
}
|
||||
}
|
||||
2 => {
|
||||
if k != end && dot != end && d != end {
|
||||
let st = k + 1;
|
||||
let ed = dot - 1;
|
||||
let mut t: String = String::new();
|
||||
let mut index = 0;
|
||||
for a in filename.chars() {
|
||||
if index <= ed {
|
||||
t.push(a);
|
||||
} else if index >= st {
|
||||
t.push(a);
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
||||
if utilities::checks::Checks::is_numeric(&t) {
|
||||
track = t.parse::<i32>().unwrap();
|
||||
}
|
||||
|
||||
let sst = d + 1;
|
||||
let eed = dot;
|
||||
let mut d_s = String::new();
|
||||
index = 0;
|
||||
for a in filename.chars() {
|
||||
if index <= eed {
|
||||
d_s.push(a);
|
||||
} else if index >= sst {
|
||||
d_s.push(a);
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
||||
if utilities::checks::Checks::is_numeric(&d_s) {
|
||||
track = d_s.parse::<i32>().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
2 => {}
|
||||
_ => println!(""),
|
||||
}
|
||||
|
||||
song.disc = Some(disc);
|
||||
song.track = Some(track);
|
||||
}
|
||||
// TODO: Implement
|
||||
fn parse_disc_and_track(&self, song: &models::song::Song, track_id: &String) {}
|
||||
// TODO: Implement
|
||||
|
||||
fn parse_disc_and_track(&self, song: &mut models::song::Song, track_id: &String) {
|
||||
let sep = |a: &char, b: &char| -> bool {
|
||||
return false;
|
||||
};
|
||||
|
||||
let index = utilities::checks::Checks::index_of_item_in_container(track_id, &':', sep);
|
||||
|
||||
if index == -1 {
|
||||
let mut d_str: String = String::new();
|
||||
let mut t_str = String::new();
|
||||
|
||||
for c in track_id.chars().skip(0).take(index as usize) {
|
||||
d_str.push(c);
|
||||
}
|
||||
|
||||
let start = index + 1;
|
||||
let end = track_id.len() - 1;
|
||||
|
||||
for c in track_id.chars().skip(start as usize).take(end as usize) {
|
||||
d_str.push(c);
|
||||
}
|
||||
|
||||
song.disc = Some(d_str.parse::<i32>().unwrap());
|
||||
song.track = Some(t_str.parse::<i32>().unwrap());
|
||||
} else {
|
||||
if utilities::checks::Checks::is_numeric(track_id) {
|
||||
song.track = Some(track_id.parse::<i32>().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_for_no_confirm(&self) -> bool {
|
||||
for flag in self.ica_action.flags.iter() {
|
||||
if flag.flag == "-nc" {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// TODO: Implement
|
||||
|
||||
fn retrieve_metadata(&self, path: &String) -> Album {
|
||||
return Album {
|
||||
/*
|
||||
let mut alb = Album {
|
||||
title: String::from(""),
|
||||
album_artist: String::from(""),
|
||||
genre: String::from(""),
|
||||
@@ -247,9 +370,30 @@ impl CommitManager {
|
||||
disc_count: 0,
|
||||
songs: Vec::new(),
|
||||
};
|
||||
*/
|
||||
|
||||
let content = self.retrieve_file_content(&path);
|
||||
// let alb = serde_json::from_str(&content.unwrap());
|
||||
|
||||
/*
|
||||
let mut file: std::fs::File = std::fs::File::open(filepath).unwrap();
|
||||
let mut data = String::new();
|
||||
file.read_to_string(&mut data).unwrap();
|
||||
|
||||
return serde_json::from_str(&data).unwrap();
|
||||
*/
|
||||
|
||||
// return alb.unwrap();
|
||||
return serde_json::from_str(&content.unwrap()).unwrap();
|
||||
}
|
||||
// TODO: Implement
|
||||
fn retrieve_file_content(&self, path: &String) -> String {
|
||||
return String::from("");
|
||||
|
||||
fn retrieve_file_content(&self, path: &String) -> Result<String, Error> {
|
||||
/*
|
||||
let mut file = File::open(path)?;
|
||||
let mut buffer = Vec::new();
|
||||
file.read_to_end(&mut buffer)?;
|
||||
*/
|
||||
|
||||
return std::fs::read_to_string(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use crate::models;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Delete {}
|
||||
pub struct Delete {
|
||||
pub api: models::api::API,
|
||||
}
|
||||
|
||||
impl Delete {
|
||||
pub fn delete_song(&self, token: &models::token::Token, song: &models::song::Song) {}
|
||||
|
||||
@@ -27,11 +27,13 @@ impl Checks {
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
pub fn index_of_item_in_container(
|
||||
pub fn index_of_item_in_container<F>(
|
||||
container: &String,
|
||||
item: &char,
|
||||
func: fn(a: &char, b: &char) -> bool,
|
||||
) -> i32 {
|
||||
func: F,
|
||||
) -> i32
|
||||
where F: Fn(&char, &char) -> bool,
|
||||
{
|
||||
let mut index = -1;
|
||||
|
||||
for c in container.chars() {
|
||||
|
||||
Reference in New Issue
Block a user