Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::graph::save_commodity_graphs_for_model;
use crate::input::{load_commodity_graphs, load_model};
use crate::log;
use crate::output::{create_output_directory, get_graphs_dir, get_output_dir};
use crate::output::{copy_input_files, create_output_directory, get_graphs_dir, get_output_dir};
use crate::settings::Settings;
use ::log::{info, warn};
use anyhow::{Context, Result};
Expand Down Expand Up @@ -152,13 +152,25 @@ pub fn handle_run_command(model_path: &Path, opts: &RunOpts) -> Result<()> {
)
})?;

let model_path = model_path
.canonicalize()
.context("Failed to resolve model path.")?;
let model_name = model_path
.file_name()
.context("Model cannot be the root directory.")?
.to_str()
.context("Invalid chars in model directory name")?;

copy_input_files(&model_path, output_path, model_name)
.context("Failed to copy input files to output directory.")?;

// Initialise program logger
log::init(&settings.log_level, Some(output_path)).context("Failed to initialise logging.")?;

info!("Starting MUSE2 v{}", env!("CARGO_PKG_VERSION"));

// Load the model to run
let model = load_model(model_path).context("Failed to load model.")?;
let model = load_model(&model_path).context("Failed to load model.")?;
info!("Loaded model from {}", model_path.display());
info!("Output folder: {}", output_path.display());

Expand Down
19 changes: 19 additions & 0 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ pub fn create_output_directory(output_dir: &Path, allow_overwrite: bool) -> Resu
Ok(overwrite)
}

/// Copy input files to output directory
pub fn copy_input_files(model_dir: &Path, output_dir: &Path, model_name: &str) -> Result<()> {
// Get the model name from the dir path.
let mut input_copy_dir = output_dir.to_path_buf();
input_copy_dir.extend(["input", model_name]);

fs::create_dir_all(&input_copy_dir).context("Could not create input copy directory")?;

for entry in fs::read_dir(model_dir)? {
let entry = entry?;
let path = entry.path();
if path.is_file() {
let file_name = path.file_name().unwrap();
fs::copy(&path, input_copy_dir.join(file_name))?;
}
}
Ok(())
}

/// Represents a row in the assets output CSV file.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct AssetRow {
Expand Down
1 change: 1 addition & 0 deletions tests/data/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Not part of regression test
metadata.toml
**/input/*
Loading