williamr/buglist_to_mediawiki.pl
author Simon Howkins <simonh@symbian.org>
Thu, 13 May 2010 16:27:37 +0100
changeset 244 2251fde91223
parent 239 d01a4084d621
child 245 478794dc0351
permissions -rw-r--r--
Changed script to use CSV formatted input, rather than TSV. This means that the script can directly process the CSV downloaded from Bugzilla, without any need to use Excel to convert it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
239
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
     1
#! perl -w
20
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
     2
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2009 Symbian Foundation Ltd
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
     8
#
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    11
# 
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    12
# Contributors:
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    13
#
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    14
# Description:
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    15
# Convert tab-separated buglist into Mediawiki table
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    16
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    17
use strict;
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    18
244
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    19
use FindBin;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    20
use lib "$FindBin::Bin\\..\\lib";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    21
use Text::CSV;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    22
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    23
my $csv = Text::CSV->new();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    24
239
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    25
print "{|\n";   # start of table
20
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    26
239
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    27
while (my $line = <>)
20
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    28
  {
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    29
  chomp $line;
244
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    30
  
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    31
  unless ($csv->parse($line))
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    32
  {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    33
    my $err = $csv->error_input();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    34
    warn "Failed to parse line '$line': $err\n";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    35
    next;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    36
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    37
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents: 239
diff changeset
    38
  my @columns = $csv->fields();
20
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    39
  
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    40
  next if scalar @columns < 2;    # skip dubious looking lines
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    41
  
239
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    42
  if ($. == 1)
20
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    43
    {
239
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    44
    # First line of file = table headings
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    45
    my %preferredHeadings =
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    46
      (
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    47
      bug_id => "ID",
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    48
      bug_severity => "Severity",
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    49
      reporter => "Reporter",
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    50
      bug_status => "Status",
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    51
      product => "Package",
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    52
      short_desc => "Title",
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    53
      );
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    54
    @columns = map { $preferredHeadings{$_} || $_ } @columns;
20
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    55
    print "! ", join(" !! ", @columns), "\n";
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    56
    next;
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    57
    }
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    58
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    59
  # row with a bug id
239
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    60
d01a4084d621 Extended to put the preferred column headings into the table.
Simon Howkins <simonh@symbian.org>
parents: 20
diff changeset
    61
  $columns[0] = "[http://developer.symbian.org/bugs/show_bug.cgi?id=$columns[0] Bug$columns[0]]";
20
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    62
  
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    63
  print "|-\n"; # row separator
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    64
  print "| ", join(" || ", @columns), "\n";
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    65
  }
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    66
36e05c0da8f7 Trivial script to convert a "copied" bugzilla bug listing into a Mediawiki table
William Roberts <williamr@symbian.org>
parents:
diff changeset
    67
print "|}\n";