#!/usr/bin/perl -w # -*- Mode: perl; indent-tabs-mode: nil -*- # # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Original Code is the Bugzilla Bug Tracking System. # # The Initial Developer of the Original Code is Netscape Communications # Corporation. Portions created by Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All # Rights Reserved. # # Contributor(s): Dawn Endico # Gregary Hendricks # Vance Baarda # This script reads in xml bug data from standard input and inserts # a new bug into bugzilla. Everything before the beginning usage_mode(Bugzilla::Constants::USAGE_MODE_CMDLINE); my $debug = 0; my $help = 0; my $login = undef; my $pass = undef; my $result = GetOptions("verbose|debug+" => \$debug, "help|?" => \$help, "login=s" => \$login, "pass=s" => \$pass); pod2usage(0) if $help; use constant DEBUG_LEVEL => 2; use constant ERR_LEVEL => 1; sub Debug { return unless ($debug); my ($message, $level) = (@_); print STDERR "ERR: ". $message ."\n" if ($level == ERR_LEVEL); print STDERR "$message\n" if (($debug == $level) && ($level == DEBUG_LEVEL)); } Debug("Reading xml", DEBUG_LEVEL); my $xml; my $filename; if ( $#ARGV == -1 ) { # Read STDIN in slurp mode. VERY dangerous, but we live on the wild side ;-) local($/); $xml = <>; } elsif ( $#ARGV == 0 ) { $filename = $ARGV[0]; } else { pod2usage(0); } # Log in if credentials are provided. if (defined $login) { Debug("Logging in as '$login'", DEBUG_LEVEL); # Make sure no user is logged in Bugzilla->logout(); my $cgi = Bugzilla->cgi(); $cgi->param("Bugzilla_login", $login); $cgi->param("Bugzilla_password", $pass); Bugzilla->login(); } Debug("Parsing tree", DEBUG_LEVEL); my $testopiaXml = Bugzilla::Testopia::Xml->new(); $testopiaXml->parse($xml,$filename); exit 0; __END__ =head1 NAME tr_importxml - Import Testopia data from xml. =head1 SYNOPSIS tr_importxml.pl [options] [file] Options: -? --help Brief help message. -v --verbose Print error and debug information. Multiple -v options increase verbosity. --login Login ID (email address) --pass Password With no file read standard input. =head1 OPTIONS =over 8 =item B<-?> Print a brief help message and exits. =item B<-v> Print error and debug information. Multiple -v increases verbosity =back =head1 DESCRIPTION This script is used import Test Plans and Test Cases into Testopia. =cut