File Coverage

blib/lib/TaskForest/Mark.pm
Criterion Covered Total %
statement 19 48 39.5
branch 0 22 0.0
condition 0 3 0.0
subroutine 7 9 77.7
pod 1 2 50.0
total 27 84 32.1


line stmt bran cond sub pod time code
1             ################################################################################
2             #
3             # $Id: Mark.pm 219 2009-06-09 03:30:29Z aijaz $
4             #
5             ################################################################################
6              
7             =head1 NAME
8              
9             TaskForest::Mark - Functions related to marking a job as Success or Failure
10              
11             =head1 SYNOPSIS
12              
13             use TaskForest::Mark;
14              
15             &TaskForest::Mark::mark($family_name, $job_name, $log_dir, $status, $cascade, $dependents_only, $family_dir)
16              
17             =head1 DOCUMENTATION
18              
19             If you're just looking to use the taskforest application, the only
20             documentation you need to read is that for TaskForest. You can do this
21             either of the two ways:
22              
23             perldoc TaskForest
24              
25             OR
26              
27             man TaskForest
28              
29             =head1 DESCRIPTION
30              
31             This is a simple package that provides a location for the mark
32             function, so that it can be used in the test scripts as well.
33              
34             =head1 METHODS
35              
36             =cut
37              
38             package TaskForest::Mark;
39 2     2   93962 use strict;
  2         7  
  2         134  
40 2     2   13 use warnings;
  2         5  
  2         61  
41 2     2   14 use Carp;
  2         3  
  2         129  
42 2     2   12 use File::Copy;
  2         38  
  2         90  
43 2     2   1758 use TaskForest::Family;
  2         8  
  2         122  
44              
45             BEGIN {
46 2     2   30 use vars qw($VERSION);
  2         4  
  2         127  
47 2     2   1110 $VERSION = '1.30';
48             }
49              
50              
51             # ------------------------------------------------------------------------------
52             =pod
53              
54             =over 4
55              
56             =item mark()
57              
58             Usage : mark($family_name, $job_name, $log_dir, $status)
59             Purpose : Mark the specified job as success or failure. This job
60             only changes the name of the status file:
61             $family_name.$job_name.[01]. The actual contents of the
62             file, the original return code is not changed. The file
63             name is what is used to determine job dependencies.
64             Returns : Nothing
65             Arguments : $family_name - the family name
66             $job_name - the job name
67             $log_dir - the root log directory
68             $status - "Success" or "Failure". Case does not matter.
69             Throws : Nothing
70              
71             =back
72              
73             =cut
74              
75             # ------------------------------------------------------------------------------
76             sub mark {
77 0     0 1   my ($family_name, $job_name, $log_dir, $status, $cascade, $dependents_only, $family_dir, $quiet) = @_;
78              
79 0           my $jobs;
80            
81 0 0 0       if ($cascade or $dependents_only) {
82              
83 0 0         $ENV{TF_JOB_DIR} = 'unnecessary' unless $ENV{TF_JOB_DIR};
84 0 0         $ENV{TF_RUN_WRAPPER} = 'unnecessary' unless $ENV{TF_RUN_WRAPPER};
85 0 0         $ENV{TF_LOG_DIR} = $log_dir unless $ENV{TF_LOG_DIR};
86 0 0         $ENV{TF_FAMILY_DIR} = $family_dir unless $ENV{TF_FAMILY_DIR};
87              
88 0           my $family = TaskForest::Family->new(name => $family_name);
89              
90 0           $jobs = $family->findDependentJobs($job_name);
91              
92 0 0         if ($cascade) {
93 0           push (@$jobs, $job_name);
94             }
95              
96             }
97             else {
98 0           $jobs = [$job_name];
99             }
100              
101 0 0         unless (@$jobs) {
102 0           print STDERR "There are no jobs to rerun. Did you misspell the job name?\n";
103 0           exit 1;
104             }
105              
106            
107 0           foreach my $job (@$jobs) {
108 0           markHelp($family_name, $job, $log_dir, $status, $quiet);
109             }
110             }
111              
112              
113             sub markHelp {
114 0     0 0   my ($family_name, $job_name, $log_dir, $status, $quiet) = @_;
115              
116 0 0         print "Marking job $family_name","::","$job_name as $status.\n" unless $quiet;
117            
118 0           my $rc_file = "$log_dir/$family_name.$job_name.";
119 0           my $new_rc_file;
120            
121 0 0         if ($status =~ /success/i) {
122 0           $new_rc_file = $rc_file . "0";
123 0           $rc_file .= '1';
124             }
125             else {
126 0           $new_rc_file = $rc_file . "1";
127 0           $rc_file .= '0';
128             }
129            
130 0 0         if (-e $new_rc_file) {
131 0           carp("$family_name.$job_name is already marked $status. Not doing anything.");
132             }
133             else {
134 0 0         move($rc_file, $new_rc_file) || confess ("couldn't move $rc_file to $new_rc_file: $!");
135             }
136            
137             }
138              
139             1;