Merge branch 'master' of git.esilibrary.com:migration-tools
[migration-tools.git] / mig-bin / mig-reporter
index 7f223f9..c3651a2 100755 (executable)
@@ -32,6 +32,10 @@ Allows you to override the default evergreen_staged_report.xml in the mig-xml fo
 
 Pushes output to an Excel file instead of asciidoc file. 
 
+--captions or --captions_off
+
+Adds the captions tag to asciidoc header to turn off captions in generated output.
+
 =back
 
 =cut
@@ -52,6 +56,7 @@ use Excel::Writer::XLSX;
 use Pod::Usage;
 use Switch;
 use Cwd 'abs_path';
+use Cwd qw(getcwd);
 use FindBin;
 my $mig_bin = "$FindBin::Bin/";
 use lib "$FindBin::Bin/";
@@ -74,6 +79,7 @@ my $next_arg_is_added_page_title;
 my $added_page_file;
 my $next_arg_is_added_page_file;
 my $excel_output = 0;
+my $captions_off = 0;
 my $i = 0;
 my $parser = XML::LibXML->new();
 my $lines_per_page = 42;
@@ -140,6 +146,10 @@ foreach my $arg (@ARGV) {
         $excel_output = 1;
         next;
     }
+    if ($arg eq '--captions_off' or $arg eq '--captions') {
+        $captions_off = 1;
+        next;
+    }
     if ($arg eq '--debug') {
         $debug_flag = 1;
         next;
@@ -152,10 +162,8 @@ if ($excel_output == 0 and !defined $analyst) { abort('--analyst must be supplie
 
 my $mig_path = abs_path($0);
 $mig_path =~ s|[^/]+$||;
-if (!defined $reports_xml) { 
-    if ($excel_output == 0) { $reports_xml = $mig_path . '../mig-xml/evergreen_staged_report.xml'; } 
-        else { $reports_xml = $mig_path . '../mig-xml/excel_mapping_reports.xml'; } 
-    } else { $reports_xml = $mig_path . '/../mig-xml/' . $reports_xml; }
+$reports_xml = find_xml($reports_xml,$mig_path,$excel_output);
+if (!defined $reports_xml) { abort("Can not find xml reports file."); }
 my $dom = $parser->parse_file($reports_xml);
 
 if (defined $added_page_file or defined $added_page_title) {
@@ -171,7 +179,7 @@ if ($excel_output == 1) {
     $workbook = Excel::Writer::XLSX->new( $report_file );
 } else {
     open($fh, '>', $report_file) or abort("Could not open output file!");
-    write_title_page($report_title,$fh,$analyst);
+    write_title_page($report_title,$fh,$analyst,$captions_off);
 };
 
 if (defined $added_page_file and defined $added_page_title) { 
@@ -271,6 +279,28 @@ if ($excel_output eq 1) { $workbook->close(); }
 
 ############ end of main logic
 
+sub find_xml {
+    my $reports_xml = shift;
+    my $mig_path = shift;
+    my $excel_output = shift;
+
+    if (!defined $reports_xml) {
+        if ($excel_output == 0) { $reports_xml = $mig_path . '../mig-xml/evergreen_staged_report.xml'; return $reports_xml; }
+            else { $reports_xml = $mig_path . '../mig-xml/excel_mapping_reports.xml'; return $reports_xml; }
+    };
+
+    if ($reports_xml =~ m/\//) { return $reports_xml; }
+
+    my $mig_test_file =  $mig_path . '/../mig-xml/' . $reports_xml;
+    my $working_test_dir = getcwd();
+    my $working_test_file = $working_test_dir . '/' . $reports_xml;
+
+    if (-e $mig_test_file) { return $mig_test_file; }
+    if (-e $working_test_file) { return $working_test_file; }
+
+    return undef;
+}
+
 sub find_report {
     my $dom = shift;
     my $tag = shift;
@@ -331,6 +361,7 @@ sub write_title_page {
     my $rt = shift;
     my $fh = shift;
     my $a = shift;
+    my $captions_off = shift;
 
     my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
     my $l = length($report_title);
@@ -339,8 +370,9 @@ sub write_title_page {
     print $fh "= $rt\n"; 
     print $fh "$mday $abbr[$mon] $year\n";
     print $fh "$a\n";
-    print $fh ":title-logo-image: image::eolilogosmall.png[pdfwidth=3in]\n";
+    #print $fh ":title-logo-image: image::eolilogosmall.png[pdfwidth=3in]\n";
     print $fh ":toc:\n";
+    if ($captions_off == 1) { print $fh ":caption:\n"; }
     print $fh "\n";
 }