Skip to content

Commit 671d79e

Browse files
committed
fix: make import files relative to plan file
1 parent 3af5934 commit 671d79e

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

sample/kvm_control_flow_plan.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import:
22
profiles:
3-
- filename: "sample/kvm_control_flow/nodes.csv"
3+
- filename: "kvm_control_flow/nodes.csv"
44
filetype: "Nodes"
5-
- filename: "sample/kvm_control_flow/links.csv"
5+
- filename: "kvm_control_flow/links.csv"
66
filetype: "Edges"
7-
- filename: "sample/kvm_control_flow/layers.csv"
7+
- filename: "kvm_control_flow/layers.csv"
88
filetype: "Layers"
99

1010
export:

src/generate_commands.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn generate_sample(dir: String) -> () {
3939

4040
fn write_dir_contents(dir: &Dir, target_path: &Path) {
4141
for file in dir.files() {
42-
let relative_path = file.path();
42+
let relative_path = file.path().strip_prefix(dir.path()).unwrap();
4343
let target_file_path = target_path.join(relative_path);
4444

4545
if let Some(parent) = target_file_path.parent() {
@@ -56,7 +56,8 @@ pub fn generate_sample(dir: String) -> () {
5656
}
5757

5858
for sub_dir in dir.dirs() {
59-
let sub_dir_path = target_path.join(sub_dir.path());
59+
let relative_path = sub_dir.path().strip_prefix(dir.path()).unwrap();
60+
let sub_dir_path = target_path.join(relative_path);
6061
if let Err(e) = fs::create_dir_all(&sub_dir_path) {
6162
error!("Failed to create subdirectory: {:?}", e);
6263
return;

src/main.rs

-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ fn main() -> Result<()> {
7070
match args.command {
7171
Commands::Run { plan } => {
7272
info!("Running plan: {}", plan);
73-
let plan_file_path = plan;
74-
let path_content = fs::read_to_string(&plan_file_path)?;
75-
let plan: plan::Plan = serde_yaml::from_str(&path_content)?;
7673
plan_execution::execute_plan(plan)?;
7774
}
7875
Commands::Init { plan } => {

src/plan_execution.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ fn load_file(file_path: &str) -> Result<DataFrame, anyhow::Error> {
2525
Ok(df)
2626
}
2727

28-
pub fn execute_plan(plan: Plan) -> Result<()> {
28+
pub fn execute_plan(plan: String) -> Result<()> {
2929
info!("Executing plan");
30+
31+
let plan_file_path = std::path::Path::new(&plan);
32+
let path_content = std::fs::read_to_string(&plan_file_path)?;
33+
let plan: Plan = serde_yaml::from_str(&path_content)?;
34+
3035
debug!("Executing plan: {:?}", plan);
3136

3237
let mut graph = Graph::default();
@@ -35,11 +40,13 @@ pub fn execute_plan(plan: Plan) -> Result<()> {
3540
.profiles
3641
.iter()
3742
.try_for_each(|profile| -> Result<(), Box<dyn std::error::Error>> {
43+
let import_file_path = plan_file_path.parent().unwrap().join(&profile.filename);
3844
info!(
3945
"Importing file: {} as {:?}",
40-
profile.filename, profile.filetype
46+
import_file_path.display(),
47+
profile.filetype
4148
);
42-
let df = load_file(&profile.filename)?;
49+
let df = load_file(import_file_path.to_str().unwrap())?;
4350
match profile.filetype {
4451
ImportFileType::Nodes => {
4552
data_loader::verify_nodes_df(&df)?;

0 commit comments

Comments
 (0)