bzcsv2mw/bzcsv2mw.pl
author Arnaud Lenoir
Tue, 13 Oct 2009 16:41:19 +0100
changeset 91 bd0e6fdb18f4
parent 52 71aa27e18688
child 100 24273662fe97
permissions -rw-r--r--
Add Beagleaboard baseport to the list of packages to clone.
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;
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
    43
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
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
    45
    "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
    46
   	"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
    47
    ))
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
  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
    50
  }
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
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
    53
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
    54
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
#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
    56
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
    57
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
    58
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
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
    60
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
    61
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
    62
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
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
    64
				"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
    65
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
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
    67
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
    68
	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
    69
	{
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
		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
    71
		
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
		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
    73
		{	
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
			$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
    75
			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
    76
			{
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
				#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
    78
				#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
    79
				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
    80
			}			
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
		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
    83
		{
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
			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
    85
			{
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
				$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
    87
			}		
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
			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
    89
			{
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
				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
    91
			}		
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
    92
		}
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
    93
	} 
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
	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
    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
		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
    97
		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
    98
	}
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
	
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
	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
   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
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
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
   104
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
   105
close MWTXT;