App-FQStat

 view release on metacpan or  search on metacpan

lib/App/FQStat/Actions.pm  view on Meta::CPAN

    print $output;
    print "\n(Hit any key to continue)";
    my $tmp = get_input_key(1e9);

    # FIXME! We could do better than just puke to STDOUT.
  } # end if selection okay
  return 1; # doesn't happen
}




sub show_job_log {
  warnenter if ::DEBUG;
  # print instructions
  locate(1,1);
  clline();
  print get_color("user_instructions");
  print "Show job log: Select with Space/Enter or 'l', 'q' to cancel.";
  print RESET;
  print "\n";

  my ($selected, $key) = select_job(['q','l']);

  if ($key eq 'q' or @$selected == 0) {
    # cancel
    return 1; # redraw
  }
  else {
    my $jobs = $::Records;
    my $id = $jobs->[ $selected->[0] ][::F_id]; # get job id
    my $qstat = get_config("qstatcmd");
    my $output = App::FQStat::System::run_capture($qstat, '-j', $id); # perhaps IPC::Cmd or IPC::Run or even just Open3 would be better here?
    if ($output =~ /^\s*$/ms) {
      print get_color("warning"), "WARNING: Something went wrong. Return value: $!", RESET;
      print "\n(Hit Enter to continue)";
      my $tmp = <STDIN>;
      return 1;
    }
    cls();

    my @o = split /\n/, $output;
    my $err;
    my $out;
    my $cwd;
    foreach my $line (@o) {
      if ( $line =~ /^std(err|out)_path_list:/ ) {
        my $match = $1;
        $line =~ s/^std(?:err|out)_path_list:\s*//;
        chomp $line;
        if ($match eq 'err') { $err = $line }
        else { $out = $line }
        last if defined $out and defined $err;
      }
      elsif ( $line =~ /^cwd:/ ) {
        $cwd = $line;
        $cwd =~ s/^cwd:\s*//;
        chomp $cwd;
      }
    }
    $err =~ s/^stderr_path_list:\s*// if defined $err;
    $out =~ s/^stdout_path_list:\s*// if defined $out;

    if ( not defined $cwd ) {
      print "Could not determine current working directory for locating the logs.\n";
      my $tmp = get_input_key(300);
      return 1;
    }
    elsif ( not defined $out and not defined $err ) {
      # couldn't find log
      print "No log could be found for this job. Owner didn't set stdout nor stderr redirection?\n";
      my $tmp = get_input_key(300);
      return 1;
    }
    elsif ( defined $out and defined $err and $out eq $err ) {
      undef $err; # only show once
    }

    my $cmd;
    if (defined $out) {
      if ($out !~ /^\//) {
        $out = File::Spec->catdir($cwd, $out);
      }
      $cmd .= " $out";
    }
    if (defined $err) {
      if ($err !~ /^\//) {
        $err = File::Spec->catdir($cwd, $err);
      }
      $cmd .= " $err";
    }
    App::FQStat::System::run("sh", '-c', qq(cat $cmd | less));

  } # end if selection okay
  return 1; # doesn't happen
}


sub delete_color_scheme {
  warnenter if ::DEBUG;
  my $name = poll_user("Delete which color scheme? ");
  if ($name =~ /^\s*(\w+)\s*$/i) {
    my $schemeName = lc($1);
    return 1 if $schemeName eq 'default';
    my $schemes = get_config("color_schemes");
    if (exists($schemes->{$schemeName})) {
      delete $schemes->{$schemeName};
    }
  }
  return 1;
}

sub save_color_scheme {
  warnenter if ::DEBUG;
  my $name = poll_user("Save as which color scheme? ");
  if ($name =~ /^\s*(\w+)\s*$/i) {
    my $schemeName = lc($1);
    return 1 if $schemeName eq 'default';
    my $schemes = get_config("color_schemes");
    $schemes->{$schemeName} = {%{ get_config('colors') }};
  }
  return 1;
}

sub toggle_summary_mode {
  warnenter if ::DEBUG;
  {
    lock($::SummaryMode);
    $::SummaryMode = ($::SummaryMode+1) % 2;
    set_config("summary_mode", $::SummaryMode);
  }



( run in 1.880 second using v1.01-cache-2.11-cpan-39bf76dae61 )