fixed formatting
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
use colored::*;
|
|
||||||
use futures::future::join_all;
|
|
||||||
use crate::cli::Args;
|
use crate::cli::Args;
|
||||||
use crate::settings::Config;
|
use crate::files::{FileBatch, execute_move, is_text_file, read_file_sample};
|
||||||
use crate::files::{execute_move, FileBatch, is_text_file, read_file_sample};
|
|
||||||
use crate::gemini::GeminiClient;
|
use crate::gemini::GeminiClient;
|
||||||
use crate::models::OrganizationPlan;
|
use crate::models::OrganizationPlan;
|
||||||
|
use crate::settings::Config;
|
||||||
use crate::storage::{Cache, UndoLog};
|
use crate::storage::{Cache, UndoLog};
|
||||||
|
use colored::*;
|
||||||
|
use futures::future::join_all;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -137,35 +137,38 @@ pub async fn handle_organization(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let client_arc: Arc<GeminiClient> = Arc::new(client);
|
let client_arc: Arc<GeminiClient> = Arc::new(client);
|
||||||
let semaphore: Arc<tokio::sync::Semaphore> = Arc::new(tokio::sync::Semaphore::new(args.max_concurrent));
|
let semaphore: Arc<tokio::sync::Semaphore> =
|
||||||
|
Arc::new(tokio::sync::Semaphore::new(args.max_concurrent));
|
||||||
|
|
||||||
let tasks: Vec<_> = plan
|
let tasks: Vec<_> = plan
|
||||||
.files
|
.files
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.zip(batch.paths.iter())
|
.zip(batch.paths.iter())
|
||||||
.map(|(file_category, path): (&mut crate::models::FileCategory, &PathBuf)| {
|
.map(
|
||||||
let client: Arc<GeminiClient> = Arc::clone(&client_arc);
|
|(file_category, path): (&mut crate::models::FileCategory, &PathBuf)| {
|
||||||
let filename: String = file_category.filename.clone();
|
let client: Arc<GeminiClient> = Arc::clone(&client_arc);
|
||||||
let category: String = file_category.category.clone();
|
let filename: String = file_category.filename.clone();
|
||||||
let path: PathBuf = path.clone();
|
let category: String = file_category.category.clone();
|
||||||
let semaphore: Arc<tokio::sync::Semaphore> = Arc::clone(&semaphore);
|
let path: PathBuf = path.clone();
|
||||||
|
let semaphore: Arc<tokio::sync::Semaphore> = Arc::clone(&semaphore);
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
if is_text_file(&path) {
|
if is_text_file(&path) {
|
||||||
let _permit = semaphore.acquire().await.unwrap();
|
let _permit = semaphore.acquire().await.unwrap();
|
||||||
if let Some(content) = read_file_sample(&path, 5000) {
|
if let Some(content) = read_file_sample(&path, 5000) {
|
||||||
println!("Reading content of {}...", filename.green());
|
println!("Reading content of {}...", filename.green());
|
||||||
client
|
client
|
||||||
.get_ai_sub_category(&filename, &category, &content)
|
.get_ai_sub_category(&filename, &category, &content)
|
||||||
.await
|
.await
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
})
|
)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let sub_categories: Vec<String> = join_all(tasks).await;
|
let sub_categories: Vec<String> = join_all(tasks).await;
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
use colored::*;
|
|
||||||
use crate::models::OrganizationPlan;
|
use crate::models::OrganizationPlan;
|
||||||
use crate::storage::UndoLog;
|
use crate::storage::UndoLog;
|
||||||
|
use colored::*;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::{ffi::OsStr, fs, path::Path};
|
use std::{ffi::OsStr, fs, path::Path};
|
||||||
|
|
||||||
pub fn execute_move(
|
pub fn execute_move(base_path: &Path, plan: OrganizationPlan, mut undo_log: Option<&mut UndoLog>) {
|
||||||
base_path: &Path,
|
|
||||||
plan: OrganizationPlan,
|
|
||||||
mut undo_log: Option<&mut UndoLog>,
|
|
||||||
) {
|
|
||||||
println!("\n{}", "--- EXECUTION PLAN ---".bold().underline());
|
println!("\n{}", "--- EXECUTION PLAN ---".bold().underline());
|
||||||
|
|
||||||
if plan.files.is_empty() {
|
if plan.files.is_empty() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use colored::*;
|
|
||||||
use crate::storage::UndoLog;
|
use crate::storage::UndoLog;
|
||||||
|
use colored::*;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::models::OrganizationPlan;
|
|
||||||
use crate::storage::Cache;
|
|
||||||
use crate::gemini::errors::GeminiError;
|
use crate::gemini::errors::GeminiError;
|
||||||
use crate::gemini::prompt::PromptBuilder;
|
use crate::gemini::prompt::PromptBuilder;
|
||||||
use crate::gemini::types::{GeminiResponse, OrganizationPlanResponse};
|
use crate::gemini::types::{GeminiResponse, OrganizationPlanResponse};
|
||||||
|
use crate::models::OrganizationPlan;
|
||||||
|
use crate::storage::Cache;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|||||||
@@ -5,4 +5,6 @@ pub mod types;
|
|||||||
|
|
||||||
pub use client::GeminiClient;
|
pub use client::GeminiClient;
|
||||||
pub use errors::GeminiError;
|
pub use errors::GeminiError;
|
||||||
pub use types::{Candidate, Content, FileCategoryResponse, GeminiResponse, OrganizationPlanResponse, Part};
|
pub use types::{
|
||||||
|
Candidate, Content, FileCategoryResponse, GeminiResponse, OrganizationPlanResponse, Part,
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::models::{FileCategory, OrganizationPlan};
|
|
||||||
use crate::gemini::types::OrganizationPlanResponse;
|
use crate::gemini::types::OrganizationPlanResponse;
|
||||||
|
use crate::models::{FileCategory, OrganizationPlan};
|
||||||
|
|
||||||
impl OrganizationPlanResponse {
|
impl OrganizationPlanResponse {
|
||||||
pub fn to_organization_plan(self) -> OrganizationPlan {
|
pub fn to_organization_plan(self) -> OrganizationPlan {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod settings;
|
|
||||||
pub mod files;
|
pub mod files;
|
||||||
pub mod gemini;
|
pub mod gemini;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
|
pub mod settings;
|
||||||
pub mod storage;
|
pub mod storage;
|
||||||
|
|
||||||
pub use cli::Args;
|
pub use cli::Args;
|
||||||
pub use settings::Config;
|
|
||||||
pub use files::{FileBatch, execute_move, is_text_file, read_file_sample, undo_moves};
|
pub use files::{FileBatch, execute_move, is_text_file, read_file_sample, undo_moves};
|
||||||
pub use gemini::GeminiClient;
|
pub use gemini::GeminiClient;
|
||||||
pub use gemini::GeminiError;
|
pub use gemini::GeminiError;
|
||||||
pub use models::{FileCategory, FileMoveRecord, MoveStatus, OrganizationPlan};
|
pub use models::{FileCategory, FileMoveRecord, MoveStatus, OrganizationPlan};
|
||||||
|
pub use settings::Config;
|
||||||
pub use storage::{Cache, UndoLog};
|
pub use storage::{Cache, UndoLog};
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
use noentropy::cli::{Args, orchestrator::{handle_organization, handle_undo}};
|
|
||||||
use noentropy::settings::{get_or_prompt_api_key, get_or_prompt_download_folder};
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use noentropy::cli::{
|
||||||
|
Args,
|
||||||
|
orchestrator::{handle_organization, handle_undo},
|
||||||
|
};
|
||||||
|
use noentropy::settings::{get_or_prompt_api_key, get_or_prompt_download_folder};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
pub mod organization;
|
|
||||||
pub mod metadata;
|
pub mod metadata;
|
||||||
pub mod move_record;
|
pub mod move_record;
|
||||||
|
pub mod organization;
|
||||||
|
|
||||||
pub use organization::{FileCategory, OrganizationPlan};
|
|
||||||
pub use metadata::{CacheEntry, FileMetadata};
|
pub use metadata::{CacheEntry, FileMetadata};
|
||||||
pub use move_record::{FileMoveRecord, MoveStatus};
|
pub use move_record::{FileMoveRecord, MoveStatus};
|
||||||
|
pub use organization::{FileCategory, OrganizationPlan};
|
||||||
|
|||||||
@@ -136,4 +136,3 @@ impl Default for Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ fn test_validate_api_key_invalid() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_validate_folder_path_valid() {
|
fn test_validate_folder_path_valid() {
|
||||||
let temp_dir = tempfile::tempdir().unwrap();
|
let temp_dir = tempfile::tempdir().unwrap();
|
||||||
assert!(Prompter::validate_folder_path(
|
assert!(Prompter::validate_folder_path(temp_dir.path()));
|
||||||
temp_dir.path()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -52,9 +50,7 @@ fn test_validate_folder_path_invalid() {
|
|||||||
)));
|
)));
|
||||||
|
|
||||||
let temp_file = tempfile::NamedTempFile::new().unwrap();
|
let temp_file = tempfile::NamedTempFile::new().unwrap();
|
||||||
assert!(!Prompter::validate_folder_path(
|
assert!(!Prompter::validate_folder_path(temp_file.path()));
|
||||||
temp_file.path()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -199,4 +199,3 @@ impl Cache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ pub use undo_log::UndoLog;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::storage::{Cache, UndoLog};
|
|
||||||
use crate::models::{FileMoveRecord, MoveStatus};
|
use crate::models::{FileMoveRecord, MoveStatus};
|
||||||
|
use crate::storage::{Cache, UndoLog};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -42,9 +42,9 @@ mod tests {
|
|||||||
let mut log = UndoLog::new();
|
let mut log = UndoLog::new();
|
||||||
let source = PathBuf::from("/from/file.txt");
|
let source = PathBuf::from("/from/file.txt");
|
||||||
let dest = PathBuf::from("/to/file.txt");
|
let dest = PathBuf::from("/to/file.txt");
|
||||||
|
|
||||||
log.record_move(source.clone(), dest.clone());
|
log.record_move(source.clone(), dest.clone());
|
||||||
|
|
||||||
assert!(log.has_completed_moves());
|
assert!(log.has_completed_moves());
|
||||||
assert_eq!(log.get_completed_count(), 1);
|
assert_eq!(log.get_completed_count(), 1);
|
||||||
}
|
}
|
||||||
@@ -54,9 +54,9 @@ mod tests {
|
|||||||
let mut log = UndoLog::new();
|
let mut log = UndoLog::new();
|
||||||
let source = PathBuf::from("/from/file.txt");
|
let source = PathBuf::from("/from/file.txt");
|
||||||
let dest = PathBuf::from("/to/file.txt");
|
let dest = PathBuf::from("/to/file.txt");
|
||||||
|
|
||||||
log.record_failed_move(source.clone(), dest.clone());
|
log.record_failed_move(source.clone(), dest.clone());
|
||||||
|
|
||||||
assert!(!log.has_completed_moves());
|
assert!(!log.has_completed_moves());
|
||||||
assert_eq!(log.get_completed_count(), 0);
|
assert_eq!(log.get_completed_count(), 0);
|
||||||
}
|
}
|
||||||
@@ -66,10 +66,10 @@ mod tests {
|
|||||||
let mut log = UndoLog::new();
|
let mut log = UndoLog::new();
|
||||||
let source = PathBuf::from("/from/file.txt");
|
let source = PathBuf::from("/from/file.txt");
|
||||||
let dest = PathBuf::from("/to/file.txt");
|
let dest = PathBuf::from("/to/file.txt");
|
||||||
|
|
||||||
log.record_move(source.clone(), dest.clone());
|
log.record_move(source.clone(), dest.clone());
|
||||||
assert_eq!(log.get_completed_count(), 1);
|
assert_eq!(log.get_completed_count(), 1);
|
||||||
|
|
||||||
log.mark_as_undone(&dest);
|
log.mark_as_undone(&dest);
|
||||||
assert_eq!(log.get_completed_count(), 0);
|
assert_eq!(log.get_completed_count(), 0);
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ mod tests {
|
|||||||
let record = FileMoveRecord::new(
|
let record = FileMoveRecord::new(
|
||||||
PathBuf::from("/from"),
|
PathBuf::from("/from"),
|
||||||
PathBuf::from("/to"),
|
PathBuf::from("/to"),
|
||||||
MoveStatus::Completed
|
MoveStatus::Completed,
|
||||||
);
|
);
|
||||||
assert_eq!(record.status, MoveStatus::Completed);
|
assert_eq!(record.status, MoveStatus::Completed);
|
||||||
}
|
}
|
||||||
@@ -97,4 +97,4 @@ mod tests {
|
|||||||
let usage = log.get_directory_usage(PathBuf::from("/").as_path());
|
let usage = log.get_directory_usage(PathBuf::from("/").as_path());
|
||||||
assert!(usage.is_empty());
|
assert!(usage.is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,4 +179,3 @@ impl UndoLog {
|
|||||||
usage
|
usage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user