Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
feat: implement quite argument to use print less information while …
Browse files Browse the repository at this point in the history
…upscaling and prepare to release.
  • Loading branch information
kostya-zero committed Aug 29, 2023
1 parent 05a539c commit f3e172d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords = ["realesrgan", "upscale"]
readme = "README.md"
repository = "https://github.com/kostya-zero/resup"
license = "MIT"
version = "0.2.0-dev"
version = "0.2.0"
edition = "2021"

[dependencies]
Expand Down
6 changes: 6 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub fn app() -> Command {
Arg::new("overwrite")
.help("Overwrite file content if file with same name exists.")
.long("overwrite")
.short('o')
.action(ArgAction::SetTrue),
Arg::new("quite")
.help("Run upscale without configuration info and Real-ESRGAN output.")
.short('q')
.long("quite")
.action(ArgAction::SetTrue),
]),
Command::new("list").about("List available models."),
Expand Down
7 changes: 3 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
fs,
mem::align_of_val,
path::{Path, PathBuf},
process::exit,
};
Expand All @@ -25,6 +24,7 @@ fn main() {
let input = sub.get_one::<String>("input").unwrap().to_string();
let mut output: String = sub.get_one::<String>("output").unwrap().to_string();
let overwrite: bool = sub.get_flag("overwrite");
let quite: bool = sub.get_flag("quite");
if output.is_empty() {
let file_name = Path::new(&input)
.file_stem()
Expand All @@ -47,15 +47,14 @@ fn main() {
}

let config = Manager::load();
let quite: bool = false;
Term::message("Preparing to upscale...");
if quite {
if !quite {
Term::display_data("Model", &config.get_model());
Term::display_data("Executable", &config.get_executable_path());
Term::display_data("Input file", &input);
Term::display_data("Output file", &output);
Term::message("Starting...");
}
Term::message("Starting...");
let upscale_result: Result<(), UpscaleError> =
run_upscale(config, &input, &output, quite);
match upscale_result {
Expand Down
17 changes: 13 additions & 4 deletions src/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ pub enum UpscaleError {
ModelsDirectoryNotFound,
ModelParamNotFound,
ModelBinNotFound,
UnknownError
UnknownError,
}

pub fn run_upscale(config: Config, input: &str, output: &str, quite: bool) -> Result<(), UpscaleError> {
pub fn run_upscale(
config: Config,
input: &str,
output: &str,
quite: bool,
) -> Result<(), UpscaleError> {
let mut proc: Command = Command::new(config.get_executable_path());
proc.args(vec![
"-i",
Expand All @@ -31,6 +36,10 @@ pub fn run_upscale(config: Config, input: &str, output: &str, quite: bool) -> Re
proc.stdout(Stdio::inherit());
proc.stdin(Stdio::inherit());
proc.stderr(Stdio::inherit());
} else {
proc.stdout(Stdio::piped());
proc.stdin(Stdio::piped());
proc.stderr(Stdio::piped());
}
if !config.check_executable_exists() {
return Err(UpscaleError::ExecutableNotFound);
Expand All @@ -50,7 +59,7 @@ pub fn run_upscale(config: Config, input: &str, output: &str, quite: bool) -> Re
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => Err(UpscaleError::ExecutableNotFound),
std::io::ErrorKind::Interrupted => Err(UpscaleError::ProcessInterrupted),
_ => Err(UpscaleError::UnknownError)
}
_ => Err(UpscaleError::UnknownError),
},
}
}

0 comments on commit f3e172d

Please sign in to comment.