X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=blobdiff_plain;f=mig-bin%2Fmig-reporter;fp=mig-bin%2Fmig-reporter;h=9bea406092970bc00ddc7e4a081225dc58ce01e0;hp=e281580bee532103ddb87aaae19ea36803fc7686;hb=f94aa32f91e167e8aade712eafbe5fe552459f07;hpb=14c4d03a9ca2feb9990a7bd02eb9498cdf0f4b25 diff --git a/mig-bin/mig-reporter b/mig-bin/mig-reporter index e281580..9bea406 100755 --- a/mig-bin/mig-reporter +++ b/mig-bin/mig-reporter @@ -28,10 +28,6 @@ Gives more information about what is happening. Allows you to override the default evergreen_staged_report.xml in the mig-xml folder. ---excel_output or --excel - -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. @@ -52,7 +48,6 @@ use Env qw( HOME PGHOST PGPORT PGUSER PGDATABASE MIGSCHEMA MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR ); -use Excel::Writer::XLSX; use Pod::Usage; use Switch; use Cwd 'abs_path'; @@ -78,7 +73,6 @@ my $added_page_title; 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(); @@ -142,10 +136,6 @@ foreach my $arg (@ARGV) { $next_arg_is_added_page_file = 0; next; } - if ($arg eq '--excel_output' or $arg eq '--excel') { - $excel_output = 1; - next; - } if ($arg eq '--captions_off' or $arg eq '--captions') { $captions_off = 1; next; @@ -158,11 +148,11 @@ foreach my $arg (@ARGV) { if (!defined $tags) {$tags = 'circs.holds.actors.bibs.assets.money.notices'}; if (!defined $report_title) { abort('--report_title must be supplied'); } -if ($excel_output == 0 and !defined $analyst) { abort('--analyst must be supplied'); } +if (!defined $analyst) { abort('--analyst must be supplied'); } my $mig_path = abs_path($0); $mig_path =~ s|[^/]+$||; -$reports_xml = find_xml($reports_xml,$mig_path,$excel_output); +$reports_xml = find_xml($reports_xml,$mig_path); if (!defined $reports_xml) { abort("Can not find xml reports file."); } my $dom = $parser->parse_file($reports_xml); @@ -172,15 +162,11 @@ if (defined $added_page_file or defined $added_page_title) { if (defined $added_page_file) { $added_page_file = $MIGGITDIR . $added_page_file; } my $dbh = Mig::db_connect(); -my $report_file = create_report_name($report_title,$excel_output); +my $report_file = create_report_name($report_title); $report_file = $MIGGITDIR . $report_file; -if ($excel_output == 1) { - $workbook = Excel::Writer::XLSX->new( $report_file ); -} else { - open($fh, '>', $report_file) or abort("Could not open output file $report_file!"); - write_title_page($report_title,$fh,$analyst,$captions_off); -}; +open($fh, '>', $report_file) or abort("Could not open output file $report_file!"); +write_title_page($report_title,$fh,$analyst,$captions_off); if (defined $added_page_file and defined $added_page_title) { print $fh "<<<\n"; @@ -228,7 +214,7 @@ foreach my $t (@report_tags) { print $fh "<<<\n"; } - if ($excel_output == 0) { print_section_header(ucfirst($t),$fh); } + print_section_header(ucfirst($t),$fh); my $linecount = $lines_per_page; my $r; @@ -243,7 +229,6 @@ foreach my $t (@report_tags) { foreach my $report ($dom->findnodes('//report')) { if (index($report->findvalue('./tag'),$t) != -1 and $report->findvalue('./iteration') eq '0') { push @report_names, $report->findvalue('./name'); - if ($excel_output == 1) { print_query_to_excel($workbook,$report); } } } @@ -251,43 +236,35 @@ foreach my $t (@report_tags) { #but this keeps it simple and in practice I haven't needed more than two - if ($excel_output == 0) { - foreach my $rname (@report_names) { - my %report0; - my %report1; - my $check_tables0; - my $check_tables1; - - if ($debug_flag == 1) {print "\nchecking for $rname ... ";} - %report0 = find_report($dom,$t,$rname,'0',$debug_flag); - $check_tables0 = check_table($report0{query},$MIGSCHEMA,$debug_flag,$rname); - if ($check_tables0 == 1) { $r = print_query($fh,%report0); } else { - %report1 = find_report($dom,$t,$rname,'1',$debug_flag); - if (defined $report1{query}) { - $check_tables1 = check_table($report1{query},$MIGSCHEMA,$debug_flag,$rname); - if ($check_tables1 == 1) { $r = print_query($fh,%report1); } - } + foreach my $rname (@report_names) { + my %report0; + my %report1; + my $check_tables0; + my $check_tables1; + + if ($debug_flag == 1) {print "\nchecking for $rname ... ";} + %report0 = find_report($dom,$t,$rname,'0',$debug_flag); + $check_tables0 = check_table($report0{query},$MIGSCHEMA,$debug_flag,$rname); + if ($check_tables0 == 1) { $r = print_query($fh,%report0); } else { + %report1 = find_report($dom,$t,$rname,'1',$debug_flag); + if (defined $report1{query}) { + $check_tables1 = check_table($report1{query},$MIGSCHEMA,$debug_flag,$rname); + if ($check_tables1 == 1) { $r = print_query($fh,%report1); } } } } + } print "\n"; -if ($excel_output eq 1) { $workbook->close(); } - else { close $fh; } +close $fh; ############ 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; } @@ -344,15 +321,13 @@ sub print_section_header { sub create_report_name { my $rt = shift; - my $excel_output = shift; my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; my $date = $year . '_' . $abbr[$mon] . '_' . $mday; my $report_file; - if ($excel_output == 0) { $report_file = $rt . ' ' . $date . '.asciidoc'; } - else { $report_file = $rt . ' ' . $date . '.xlsx'; } + $report_file = $rt . ' ' . $date . '.asciidoc'; $report_file =~ s/ /_/g; return $report_file; } @@ -484,55 +459,6 @@ sub print_query { print "successfully wrote output for $report{name}.\n\n"; } -sub print_query_to_excel { - my $workbook = shift; - my $report = shift; - - my $header_format = $workbook->add_format( bold => 1, color => 'green', size => 16); - my $note_format = $workbook->add_format( bold => 1, color => 'red', size => 14); - - my $query = $report->findvalue('./query'); - my $title = $report->findvalue('./report_title'); - my $headings = $report->findnodes('./heading'); - - my $sth = $dbh->prepare($query); - $sth->execute(); - - my $worksheet = $workbook->add_worksheet( $title ); - my $cell = ""; - my $col = ""; - - my @h = split(/\./,$headings); - my $h_length = @h; - my $h_count = 1; - while ($h_count <= $h_length) { - $col = give_column($h_count-1); - $cell = $col . '1'; - $worksheet->write($cell,$h[$h_count-1],$header_format); - $h_count++; - } - my $cur_row = 1; - while (my @row = $sth->fetchrow_array) { - $cur_row++; - my $row_length = @row; - my $r = 1; - print Dumper(@row); - while ($r <= $row_length) { - if (! defined $row[$r-1] ) { - $row[$r-1] = 'none'; - } - $col = give_column($r-1); - $cell = $col . $cur_row; - $worksheet->write($cell,$row[$r-1]); - $r++; - } - } - $cur_row = $cur_row + 2; - $cell = "A" . "$cur_row"; - $worksheet->write($cell,$report->findvalue('./note'),$note_format); - print "Printed Query for $title.\n"; -} - sub give_column { my $i = shift; my $col = "";