bzcsv2mw/bzcsv2mw.pl
changeset 52 71aa27e18688
child 100 24273662fe97
equal deleted inserted replaced
51:b6b0d741e326 52:71aa27e18688
       
     1 #!perl -w
       
     2 
       
     3 # Copyright (c) 2009 Symbian Foundation Ltd
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Symbian Foundation Ltd - initial contribution.
       
    11 # 
       
    12 # Contributors:
       
    13 #
       
    14 # Description: bzcsv2mw.pl - simple script for converting CSV report files from Bugzilla to MediaWiKi text files
       
    15 #
       
    16 
       
    17 use strict;
       
    18 use warnings;
       
    19 use Text::CSV;
       
    20 use Getopt::Long;
       
    21 
       
    22 sub Usage($)
       
    23   {
       
    24   my ($msg) = @_;
       
    25   
       
    26   print "$msg\n\n" if ($msg ne "");
       
    27   
       
    28 	print <<'EOF';
       
    29     
       
    30   bzcsv2mw.pl - simple script for converting CSV report files from Bugzilla to MediaWiki text files
       
    31 
       
    32   Options:
       
    33 
       
    34   -csv 			CSV file generated by Bugzilla
       
    35   -h|-help		print this help information
       
    36 
       
    37 EOF
       
    38   exit (1);  
       
    39   }
       
    40 
       
    41 my $file = "";
       
    42 my $help = 0;
       
    43 
       
    44 if (!GetOptions(
       
    45     "csv=s" => \$file,
       
    46    	"h|help" => \$help,
       
    47     ))
       
    48   {
       
    49   Usage("Invalid argument");
       
    50   }
       
    51 
       
    52 Usage("Too few arguments....use -csv") if ($file eq "");
       
    53 Usage("") if ($help); 
       
    54 
       
    55 #my $file = $ARGV[0];
       
    56 my $csv = Text::CSV->new();
       
    57 my $mwtxt = $file.".mw.txt";
       
    58 
       
    59 open (CSV, "<", $file) or die $!;
       
    60 open (MWTXT,">$mwtxt");
       
    61 print MWTXT "{|\n";
       
    62 
       
    63 my %headermap = ("bug_id"=>"ID","bug_severity"=>"Severity","reporter"=>"Reporter","bug_status"=>"Status","product"=>"Package",
       
    64 				"short_desc"=>"Title","priority"=>"Priority","assigned_to"=>"Assigned To","resolution"=>"Resolution","op_sys"=>"OS",);
       
    65 
       
    66 my $header=0;
       
    67 while (<CSV>) {
       
    68 	if ($csv->parse($_)) 
       
    69 	{
       
    70 		my @columns = $csv->fields();
       
    71 		
       
    72 		if(!$header)
       
    73 		{	
       
    74 			$header=1;
       
    75 			foreach (@columns) 
       
    76 			{
       
    77 				#my $val = $_; 
       
    78 				#if(defined $headermap{$val}){$val = $headermap{$val};}
       
    79 				print MWTXT "!".$headermap{$_}."\n";
       
    80 			}			
       
    81 		}
       
    82 		else
       
    83 		{
       
    84 			if ($columns[0] =~ m/(\d+)/)
       
    85 			{
       
    86 				$columns[0] = "[http://developer.symbian.org/bugs/show_bug.cgi?id=$columns[0] Bug$columns[0]]";
       
    87 			}		
       
    88 			foreach (@columns) 
       
    89 			{
       
    90 				print MWTXT "|$_\n";
       
    91 			}		
       
    92 		}
       
    93 	} 
       
    94 	else 
       
    95 	{
       
    96 		my $err = $csv->error_input;
       
    97 		print "Failed to parse line: $err";
       
    98 	}
       
    99 	
       
   100 	print MWTXT "|----\n";
       
   101 }
       
   102 
       
   103 close CSV;
       
   104 print MWTXT "|}\n";
       
   105 close MWTXT;