diff --git a/scripts/menu.pl b/scripts/menu.pl index 48f3221..a58af4a 100644 --- a/scripts/menu.pl +++ b/scripts/menu.pl @@ -13,6 +13,9 @@ use TUI; use feature 'say'; +my $local_obsidian = '/home/christoph/Notes/Obsidian/Chriphost'; +my $local_obsidian_attach = "$local_obsidian/attach"; + my $local_wamr = '/home/christoph/Notes/TU/MastersThesis/05 WAMR'; my $local_newlib = '/home/christoph/Notes/TU/MastersThesis/07 NewLib'; my $local_root = '/home/christoph/Notes/TU/MastersThesis/FailNix'; @@ -41,7 +44,8 @@ my %handlers = ( # Download ran experiments from mars my @dirs = Mars::find_remote_subdirs($remote_builds_dir); my @selected_dirs = - TUI::select_from_list( "Select Experiments to Download", 1, @dirs ); + TUI::select_from_list( "Select Experiments to Download from Mars", + 1, @dirs ); die "No experiment selected" unless @selected_dirs; Mars::download_dir( "$remote_builds_dir/$_", "$local_archive_dir/" . $_ =~ s/:/-/gr ) @@ -92,7 +96,8 @@ my %handlers = ( grep { !$is_old->($_) } Util::find_subdirs($local_archive_dir); my @selected_dirs = - TUI::select_from_list( "Select Experiments to Import", 1, @dirs ); + TUI::select_from_list( "Select Experiments to Import into Ghidra", + 1, @dirs ); foreach (@selected_dirs) { say "Creating Ghidra project for $_..."; system( @@ -109,6 +114,72 @@ my %handlers = ( } }, + '06. Import Experiments Into Obsidian' => sub { + + my @experiments = Util::find_subdirs($local_archive_dir); + + # Filter experiments that already have notes + my @new_experiments; + my @existing_notes = split "\n", qx{obsidian files}; + foreach my $experiment (@experiments) { + push @new_experiments, $experiment + unless ( grep { /zettel\/$experiment/ } @existing_notes ); + } + + my @selected_experiments = + TUI::select_from_list( "Select Experiments to Import into Obsidian", + 1, @new_experiments ); + die "No experiment selected" unless @selected_experiments; + + foreach my $experiment (@selected_experiments) { + + # Create note + system( + 'obsidian', 'create', + "name=$experiment", 'path=zettel', + 'template=FailExperiment', 'open', + 'newtab' + ); + + # Insert results + if ( -f "$local_archive_dir/$experiment/results.txt" ) { + open( my $fhandle, '<', + "$local_archive_dir/$experiment/results.txt" ) + or return; + my $results = join "", <$fhandle>; + close($fhandle); + + say "$local_archive_dir/$experiment/results.txt does not exist"; + + system( 'obsidian', 'append', "file=zettel/$experiment", + "content=## Results\n\n```\n$results```\n" ); + } + + # Insert charts + my $attach_image = sub { + my ($name) = @_; + + return unless ( -f "$local_archive_dir/$experiment/$name.svg" ); + + system( + 'cp', '-i', + "$local_archive_dir/$experiment/$name.svg", + "$local_obsidian_attach/${experiment}_$name.svg" + ); + + system( 'obsidian', 'append', "file=zettel/$experiment", + "content=![[${experiment}_$name.svg]]\n" ); + }; + + system( + 'obsidian', 'append', + "file=zettel/$experiment", "content=## Charts\n\n" + ); + $attach_image->("single_result"); + $attach_image->("scatter"); + } + }, + '10. Open Experiment In Explorer' => sub { do "$local_scripts_dir/explore.pl" }, @@ -133,8 +204,8 @@ my %handlers = ( '12. Open Experiment in Binsider' => sub { my @experiments = Util::find_subdirs($local_archive_dir); my @selected_experiments = - TUI::select_from_list( "Select Experiments to Plot", 0, - @experiments ); + TUI::select_from_list( "Select Experiments to Open in Binsider", + 0, @experiments ); die "No experiment selected" unless @selected_experiments; my $selected_experiment = $selected_experiments[0]; @@ -161,7 +232,7 @@ my %handlers = ( '14. Run Build in GDB' => sub { my @builds = grep { /linux/ } Util::find_subdirs($local_builds_dir); my @selected_builds = - TUI::select_from_list( "Select Build to Run", 0, @builds ); + TUI::select_from_list( "Select Build to Run in GDB", 0, @builds ); die "No experiment selected" unless @selected_builds; my $selected_build = $selected_builds[0]; @@ -247,7 +318,8 @@ my %handlers = ( # Delete ran experiments from mars my @builds = Mars::find_remote_subdirs($remote_builds_dir); my @selected_builds = - TUI::select_from_list( "Select Experiments to Delete", 1, @builds ); + TUI::select_from_list( "Select Builds to Delete from Mars", + 1, @builds ); die "No experiment selected" unless @selected_builds; Mars::ssh_system( 'rm', '-rf', "$remote_builds_dir/$_" ) for @selected_builds; @@ -259,7 +331,8 @@ my %handlers = ( my @projects = map { s/\.gpr//r } Util::find_files($local_ghidra_projects); my @selected_projects = - TUI::select_from_list( "Select Projects to Delete", 1, @projects ); + TUI::select_from_list( "Select Ghidra Projects to Delete", + 1, @projects ); die "No project selected" unless @selected_projects; system( 'rm', '-rf', "$local_ghidra_projects/$_.gpr" ) for @selected_projects; @@ -284,7 +357,8 @@ my %handlers = ( # Drop databases on mars my @db_names = Mars::db_list(); my @selected_dbs = - TUI::select_from_list( "Select Databases to Drop", 1, @db_names ); + TUI::select_from_list( "Select Databases to Drop from Mars", + 1, @db_names ); die "No database selected" unless @selected_dbs; Mars::db_drop($_) for @selected_dbs; },