forked from bugzilla/extensions-Testopia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tr_importxml.pl
executable file
·169 lines (128 loc) · 4.32 KB
/
tr_importxml.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/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 <[email protected]>
# Gregary Hendricks <[email protected]>
# Vance Baarda <[email protected]>
# This script reads in xml bug data from standard input and inserts
# a new bug into bugzilla. Everything before the beginning <?xml line
# is removed so you can pipe in email messages.
use strict;
# figure out which path this script lives in. Set the current path to
# this and add it to @INC so this will work when run as part of mail
# alias by the mailer daemon
# since "use lib" is run at compile time, we need to enclose the
# $::path declaration in a BEGIN block so that it is executed before
# the rest of the file is compiled.
BEGIN {
$::path = $0;
$::path =~ m#(.*)/[^/]+#;
$::path = $1;
$::path ||= '.'; # $0 is empty at compile time. This line will
# have no effect on this script at runtime.
}
chdir $::path;
use lib ( $::path, "extensions/Testopia/lib" );
use Bugzilla;
use Bugzilla::Constants;
BEGIN { Bugzilla->extensions }
use Bugzilla::Extension::Testopia::Importer;
use XML::Twig;
use Getopt::Long;
use Pod::Usage;
# Keep the template from spitting out garbage
Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
Bugzilla->error_mode(ERROR_MODE_DIE);
my $debug = 0;
my $help = 0;
my $login = undef;
my $pass = undef;
my $product;
my $plans;
my $result = GetOptions(
"verbose|debug+" => \$debug,
"help|?" => \$help,
"login=s" => \$login,
"pass=s" => \$pass,
"product=s" => \$product,
"plans=s" => \$plans,
);
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 ) {
$xml = $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 = new Testopia::Importer;
$testopiaXml->debug($debug);
$testopiaXml->parse( $xml, $product, $plans );
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
--product Name of product to import plans into. (Overrides product value in XML)
--plans Comma separated list of plan numbers to import cases into. (Overrides values in XML)
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