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