Check python can be called correctly from rust, and add missing check

This commit is contained in:
drojf
2023-12-06 20:24:54 +11:00
parent ee813ef952
commit 835b96b78b

View File

@@ -1,14 +1,14 @@
extern crate inflector; extern crate inflector;
use std::env; use std::env;
use std::process::Command; use std::process::{Command, ExitCode};
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use std::collections::HashMap; use std::collections::HashMap;
use std::process; use std::process;
use inflector::Inflector; use inflector::Inflector;
fn main() { fn main() -> ExitCode {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let chapter = &args[1]; let chapter = &args[1];
let unity = &args[2]; let unity = &args[2];
@@ -19,6 +19,19 @@ fn main() {
None None
}; };
// Check if python is correctly installed
println!("Running 'python --version' to check if python is correctly installed...");
let result = Command::new("python")
.arg("--version")
.status()
.expect("Failed to run python");
if !result.success()
{
println!("Failed to run python: {:?}", result);
return ExitCode::FAILURE;
}
let mut chapters = HashMap::new(); let mut chapters = HashMap::new();
chapters.insert("onikakushi", 1); chapters.insert("onikakushi", 1);
chapters.insert("watanagashi", 2); chapters.insert("watanagashi", 2);
@@ -32,7 +45,6 @@ fn main() {
if !chapters.contains_key(&chapter[..]) { if !chapters.contains_key(&chapter[..]) {
println!("Unknown chapter, should be one of {:?}", chapters.keys()); println!("Unknown chapter, should be one of {:?}", chapters.keys());
process::exit(1);
} }
let arc_number = chapters.get(&chapter[..]).unwrap().clone(); let arc_number = chapters.get(&chapter[..]).unwrap().clone();
@@ -68,6 +80,8 @@ fn main() {
.output() .output()
.expect("failed to execute UnityTextModifier.py"); .expect("failed to execute UnityTextModifier.py");
assert!(output.status.success());
let version = String::from_utf8_lossy(&output.stdout).into_owned(); let version = String::from_utf8_lossy(&output.stdout).into_owned();
if unity != &version.trim() { if unity != &version.trim() {
@@ -220,6 +234,8 @@ fn main() {
let exit_status = status.expect("failed to execute 7za or 7z"); let exit_status = status.expect("failed to execute 7za or 7z");
assert!(exit_status.success()); assert!(exit_status.success());
return ExitCode::SUCCESS;
} }
fn format_checksum(checksum: Option<&String>, sep: &str) -> String fn format_checksum(checksum: Option<&String>, sep: &str) -> String