summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakbug
blob: 7cce5ec9e1f0652bd77779ee82b1c26363cdc844 (plain)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/usr/bin/perl

# Drak Bug Report 
# Copyright (C) 2002-2004 MandrakeSoft (daouda@mandrakesoft.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

use strict;
use diagnostics;
use lib qw(/usr/lib/libDrakX);

use standalone;
use common;
use ugtk2 qw(:all);
use Config;

my $bugzilla_url = "http://drakbug.mandrakesoft.com";
my $help_url = "http://qa.mandrakesoft.com";
my $version = "0.9.1";
my $prog;
my $incident = 0;
my $stable_release = 0;
my $wizard_name = "Bugzilla wizard";
my $bugdesc;
my $bugwrite;
my $winwidth;
my $winht;
my $upload_info = N("To submit a bug report, click on the button report.\nThis will open  a web browser window on %s\n where you'll find a form to fill in.  The information displayed above will be \ntransferred to that server.", $bugzilla_url);

foreach (@ARGV) {
    next unless defined $_;
    /^--report$/ and $prog = shift @ARGV;
    /^--incident$/ and do { $incident = 1; $prog = shift @ARGV };
}

my $window = ugtk2->new(N("Mandrake Bug Report Tool"), center => 1);
$window->{rwindow}->set_border_width(5);
$window->{window}->signal_connect("delete_event", sub { ugtk2->exit(0) });

my $mdk_app = { 
	       N("Mandrake Control Center") => 'drakconf',
	       N("First Time Wizard") => 'drakfw',
	       N("Synchronization tool") => 'draksync',  
	       N("Standalone Tools") => ['adduserdrake', 'diskdrake', 'drakautoinst', 'drakbackup', 'drakboot', 'drakbug', 'drakfloppy', 'drakfont', 'drakgw', 'drakconnect', 'drakxservices', 'drakxtv', 'keyboardrake', 'logdrake', 'mousedrake', 'net_monitor', 'printerdrake', 'scannerdrake', 'drakfirewall', 'XFdrake'],
	       N("HardDrake") => 'harddrake2',
	       N("Mandrake Online") => 'mdkonline',
	       N("Menudrake") => 'menudrake',
	       N("Msec") => 'msec',
	       N("Remote Control") => 'rfbdrake',
	       N("Software Manager") => 'rpmdrake',
	       N("Urpmi") => 'urpmi',
	       N("Windows Migration tool") => 'transfugdrake',
	       N("Userdrake") => 'userdrake',
	       N("Configuration Wizards") => 'wizdrake',
	      };

my @generic_tool = keys %$mdk_app; 
my @all_drakxtools = @{ $mdk_app->{N("Standalone Tools")} };
push(@generic_tool,@all_drakxtools);

my $kernel_release = chomp_(`uname -r`);
my $mandrake_release = mandrake_release();
if ($mandrake_release !~ /Cooker/) {
	my @release_list = split(' ', $mandrake_release);
	$mandrake_release = join(" ", $release_list[0], $release_list[1], $release_list[3]);
	$bugzilla_url = "http://bugs.mandrakelinux.com/drakbug.php?request=1";
	$help_url = "http://bugs.mandrakelinux.com/faq.php";
	$stable_release = 1;
	$wizard_name = "Anthill";
	$winwidth = 600;
	$winht = 460;
	$upload_info = N("To submit a bug report, click the report button, which will open your default browser\nto Anthill where you will be able to upload the above information as a bug report.");
}

my $table;
my $app_box;
my $comb_app;
my $button_pkg;
my $package;
my $extra_data;
my $extra_text;
my $summary;
my $textview;
my $kversion;
my $cpuinfo;
my $lspci;

if ($stable_release == 0) {
	$table = create_packtable({ col_spacings => 5, row_spacings => 10 },
                             [ new Gtk2::Label(N("Application:")), $comb_app = Gtk2::ComboBox->new_text ],
                             [ new Gtk2::Label(N("Package: ")), $package = Gtk2::Entry->new_with_text("...") ], # complain on gtk-perl@ml
                             [ Gtk2::Label->new(N("Kernel:")), gtkset_editable(Gtk2::Entry->new_with_text($kernel_release), 0) ],
                             [ Gtk2::Label->new(N("Release: ")), gtkset_editable(Gtk2::Entry->new_with_text($mandrake_release), 0) ]
                             );
	$comb_app->set_popdown_strings("", sort(@generic_tool));
} else {
	$table = create_packtable({ col_spacings => 5, row_spacings => 5 },
		[Gtk2::Label->new(N("Application Name\nor Full Path:")), 
		gtkpack_(new Gtk2::HBox(0,5),
			1, $comb_app = gtkset_editable(Gtk2::Entry->new, 1), 
			0, $button_pkg = Gtk2::Button->new(N("Find Package")),
		)],
		[ Gtk2::Label->new(N("Package: ")), $package = gtkset_editable(Gtk2::Entry->new_with_text("..."), 0) ],
		[ Gtk2::Label->new(N("Release: ")), gtkset_editable(Gtk2::Entry->new_with_text($mandrake_release), 0) ],
		[ Gtk2::Label->new(N("Summary: ")), $summary = gtkset_editable(Gtk2::Entry->new_with_text(""), 1) ]
	);
	
	$textview = new Gtk2::TextView;
	$textview->set_wrap_mode("GTK_WRAP_WORD");
	my $scrolled_window = Gtk2::ScrolledWindow->new(undef, undef);
	$scrolled_window->set_policy('automatic', 'automatic');
	$scrolled_window->set_border_width(10);
 	$scrolled_window->add_with_viewport($textview);
	$scrolled_window->set_size_request($winwidth-50, 180);
	my $buffer = $textview->get_buffer;
	my $iter = $buffer->get_iter_at_offset(0);
    $buffer->insert($iter, N("YOUR TEXT HERE"));

	$extra_data = gtkpack_(new Gtk2::VBox(0,1),
		0, Gtk2::Label->new(N("Bug Description/System Information")),
		1, $scrolled_window,
		0, gtkpack_(new Gtk2::HBox(0,20),
			0, new Gtk2::HBox(0,0),
			1, $kversion = new Gtk2::CheckButton(N("Submit kernel version")),
			1, $cpuinfo = new Gtk2::CheckButton(N("Submit cpuinfo")),
			1, $lspci = new Gtk2::CheckButton(N("Submit lspci")),
		),
		0, new Gtk2::HSeparator,			
	);
	$kversion->set_active(1);
	$cpuinfo->set_active(1);
	$lspci->set_active(1);
}

gtkadd(
       $window->{window},
       gtkpack2__(my $vbx = new Gtk2::VBox(0,5),
                  gtkadd($table),
				  gtkadd($extra_data),
                  gtkpack(new Gtk2::HBox(0,0),
                          gtkpack(gtkset_justify(new Gtk2::Label($upload_info), "left")),
                         ),
                  gtkpack(new Gtk2::HSeparator),
                  gtkpack_(Gtk2::HBox->new(0,0),
                           0, gtksignal_connect(Gtk2::Button->new(N("Help")), clicked => sub { system("drakhelp --id drakbug &") }),
                           1, Gtk2::Label->new(""),
                           0, gtksignal_connect(Gtk2::Button->new(N("Report")), clicked => sub {
						   		if ($stable_release == 0) { 
                                                    my $options = "mdkbugreport=1";
                                                    $options .= "&incident=1" if $incident;
                                                    my $p = $package->get_text;
                                                    (my $r = parse_release()) =~ s/\s//;
                                                    $options .= "&package=$p" if $p =~ /mdk/;
                                                    $options .= "&kernel=$kernel_release";
                                                    $options .= "&version=$r";
                                                    print($bugzilla_url . "?" . $options . "\n");
                                                    connect_bugzilla($bugzilla_url."?".$options);
                           		} else {
									# anthill variant - we'll create a text file, then connect to upload
									my $check = write_anthill_file(); 
									connect_bugzilla($bugzilla_url) if !$check;
								}
							}
                           ),
                           0, gtksignal_connect(Gtk2::Button->new(N("Close")), clicked => sub { ugtk2->exit(0) }),
                          ),
                 ),
      );

if ($stable_release == 0) {
	if (defined $prog) {
    	update_app($prog); 
    	$comb_app->entry->set_text($prog);
	};
	$comb_app->entry->signal_connect('changed', sub { update_app($comb_app->entry->get_text) });
} else {
	$window->{window}->set_size_request($winwidth, $winht);
	$button_pkg->signal_connect('clicked', sub { 
		my $pkg_name = get_pkg_name($comb_app->get_text);
		$package->set_text($pkg_name);
	});
}

$window->{window}->show_all;
$window->main;
ugtk2->exit(0);

sub update_app {
    my ($text) = @_;
    my $app_choice;
    $ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}";
    if (member($text,@all_drakxtools) || $text eq N("Standalone Tools")) {
	$app_choice = chomp_(`rpm -q drakxtools`);
    } elsif (exists($mdk_app->{$text}) && $text ne N("Standalone Tools")) {	
	$app_choice = get_package($mdk_app->{$text});
    } else {
	LOOP: while (my ($key, $value) = each %$mdk_app) {
	    next if $key eq N("Standalone Tools");
	    if ($value eq $text) { 
		$app_choice = get_package($text);
		$prog = $key; 
		last LOOP;
	    }
	}
	
    }
    $app_choice ? $package->set_text($app_choice) : $package->set_text(N("Not installed"));
}

my %packages;

sub get_package {
    my ($executable) = @_;
    my ($rpm_package, $which_app);
    $rpm_package = $packages{$executable};
    if (!defined $rpm_package) {
        $which_app = chomp_(`which '$executable' 2> /dev/null`);
        # deush, rpm can takes some time aka it'll sleeps if something has opened rpm db !
        $rpm_package = $which_app eq "" ? N("Package not installed") : chomp_(`rpm -qf '$which_app' 2>&1`);
        $packages{$executable} = $rpm_package;
    }
    $rpm_package;
}

sub get_pkg_name {
	my ($executable) = @_;
	my $which_app = chomp_(`which '$executable' 2> /dev/null`);
	my $rpm_package;
	if ($which_app eq "") {
		$rpm_package = chomp_(`rpm -q '$executable' --qf '%{NAME}' 2>&1`);
	} else {
    		$rpm_package = chomp_(`rpm -qf '$which_app' --qf '%{NAME}' 2>&1`);
	}
     $rpm_package = chomp_(`rpm -qf '$executable' --qf '%{NAME}' 2>&1`) if $rpm_package =~ /not installed$/;
     $rpm_package = (split(/-2/, $rpm_package))[0] if $rpm_package =~ /^kernel/;
	$rpm_package ||= N("NOT FOUND");
	$rpm_package;
}

sub parse_release() {
    (mandrake_release() =~ /release\s(\S+\s\(.*\))/)[0];
}

sub connect_bugzilla {
    my ($url) = @_;
	if (!$stable_release) {
    	my $_w = create_dialog(N("Please wait"), N("connecting to %s ...", $wizard_name)); 
    	sleep(3);
	}
    exec $ENV{BROWSER},$url if exists $ENV{BROWSER};
    my @browser = qw(mozilla konqueror galeon);
    foreach (@browser) {
	if (-e "/usr/bin/$_") { log::explanations("Contacting $url with $_\n "); exec $_,$url } 
    }
    create_dialog(N("Error"), N("No browser available! Please install one"));
}

sub write_anthill_file() {
	my $buffer = $textview->get_buffer;
	my $siter = $buffer->get_start_iter;
	my $eiter = $buffer->get_end_iter; 
	$bugdesc = $buffer->get_text($siter, $eiter, 0);
	
	#- create anthill upload file in specified format
	local *F;
	open(F, "> /tmp/drakbug.report") or return 1;
	print F "--- BEGIN DRAKBUG REPORT ---\n";
	print F "%product: $mandrake_release\n";
	my $version = arch();
	$version = "x86" if $version =~ /^i.86/;
	print F "%version: $version\n";
	my $pkg_name = $package->get_text;
	if ($pkg_name eq "..." || $pkg_name eq "") {
		my $_w = create_dialog(N("Error"), N("Please enter a package name."));
		return 1;
	}
	print F "%component: $pkg_name\n";
	my $summary_text = $summary->get_text;
	if ($summary_text eq "") {
		my $_w = create_dialog(N("Error"), N("Please enter summary text."));
		return 1;
	}

	print F "%summary: $summary_text\n";
	print F "%description:\n";
	
	#- gave me fits wanted to wrap what was wrapped in the GUI
	#- plus include user's \n
	my @buglist = split("\n", $bugdesc);
	foreach my $bugdesc (@buglist) {
		if (length($bugdesc) > 77) {
			$bugwrite = $bugdesc;
			select(F);
			local $~ = "PFORMAT";
			write F;
			select(STDOUT);
			$bugwrite = '';
		} else {
			print F "   $bugdesc\n";
		}
	}
	
	print F "-" x 80 . "\n";
     print F "Kernel: $kernel_release\n" . "Uname: " . `uname -a` . "\n" if $kversion->get_active;
     print F "Cpuinfo: \n" . cat_("/proc/cpuinfo") if $cpuinfo->get_active;
     print F "Lspci Output:\n" . `lspci` if $lspci->get_active;
	print F "--- END DRAKBUG REPORT ---\n";
	close F or return 1;
	return 0
}

format PFORMAT =
~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$bugwrite
.