Skip to content

Commit 835b96b

Browse files
committed
Check python can be called correctly from rust, and add missing check
1 parent ee813ef commit 835b96b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/main.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
extern crate inflector;
22

33
use std::env;
4-
use std::process::Command;
4+
use std::process::{Command, ExitCode};
55
use std::fs;
66
use std::path::Path;
77
use std::collections::HashMap;
88
use std::process;
99
use inflector::Inflector;
1010

11-
fn main() {
11+
fn main() -> ExitCode {
1212
let args: Vec<String> = env::args().collect();
1313
let chapter = &args[1];
1414
let unity = &args[2];
@@ -19,6 +19,19 @@ fn main() {
1919
None
2020
};
2121

22+
// Check if python is correctly installed
23+
println!("Running 'python --version' to check if python is correctly installed...");
24+
let result = Command::new("python")
25+
.arg("--version")
26+
.status()
27+
.expect("Failed to run python");
28+
29+
if !result.success()
30+
{
31+
println!("Failed to run python: {:?}", result);
32+
return ExitCode::FAILURE;
33+
}
34+
2235
let mut chapters = HashMap::new();
2336
chapters.insert("onikakushi", 1);
2437
chapters.insert("watanagashi", 2);
@@ -32,7 +45,6 @@ fn main() {
3245

3346
if !chapters.contains_key(&chapter[..]) {
3447
println!("Unknown chapter, should be one of {:?}", chapters.keys());
35-
process::exit(1);
3648
}
3749

3850
let arc_number = chapters.get(&chapter[..]).unwrap().clone();
@@ -68,6 +80,8 @@ fn main() {
6880
.output()
6981
.expect("failed to execute UnityTextModifier.py");
7082

83+
assert!(output.status.success());
84+
7185
let version = String::from_utf8_lossy(&output.stdout).into_owned();
7286

7387
if unity != &version.trim() {
@@ -220,6 +234,8 @@ fn main() {
220234
let exit_status = status.expect("failed to execute 7za or 7z");
221235

222236
assert!(exit_status.success());
237+
238+
return ExitCode::SUCCESS;
223239
}
224240

225241
fn format_checksum(checksum: Option<&String>, sep: &str) -> String

0 commit comments

Comments
 (0)