From b1c7d97c84343398f39a1aa495e0516137227e2b Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Tue, 13 Nov 2018 20:34:00 +0000 Subject: Add option to suggest a downgrade command. --- qarepo.pl | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/qarepo.pl b/qarepo.pl index fd6df5e..bc49731 100644 --- a/qarepo.pl +++ b/qarepo.pl @@ -116,6 +116,7 @@ my $button1 = Gtk3::Button->new('Quit'); my $button2 = Gtk3::Button->new('Disable'); my $button3 = Gtk3::Button->new('Enable'); my $button4 = Gtk3::Button->new('Clear'); +my $button5 = Gtk3::Button->new('Downgrade'); my $check0 = Gtk3::CheckButton->new_with_label("core"); my $check1 = Gtk3::CheckButton->new_with_label("nonfree"); @@ -185,6 +186,8 @@ $button4->set_vexpand(TRUE); $button4->set_valign('GTK_ALIGN_END'); $button4->signal_connect(clicked => \&clear); +$button5->signal_connect(clicked => \&downgrade); + $check0->set_active(TRUE); $check0->set_sensitive(FALSE); @@ -213,9 +216,9 @@ $grid->attach($label3, 0, 2, 1, 1); $grid->attach($entry3, 1, 2, 4, 1); $grid->attach($entry4, 5, 2, 1, 1); $grid->attach($label5, 0, 3, 1, 1); -$grid->attach($scroll, 1, 3, 5, 4); -$grid->attach($label6, 0, 7, 1, 1); -$grid->attach($status, 1, 7, 5, 1); +$grid->attach($scroll, 1, 3, 5, 5); +$grid->attach($label6, 0, 8, 1, 1); +$grid->attach($status, 1, 8, 5, 1); $grid->attach($button1, 7, 0, 1, 1); $grid->attach($button2, 7, 2, 1, 1); @@ -223,6 +226,7 @@ $grid->attach($button3, 7, 3, 1, 1); $grid->attach($check3, 7, 4, 1, 1); $grid->attach($check4, 7, 5, 1, 1); $grid->attach($button4, 7, 6, 1, 1); +$grid->attach($button5, 7, 7, 1, 1); $window->add($grid); @@ -343,6 +347,17 @@ sub clear { $entry5->get_buffer()->set_text(''); } +sub downgrade { + check_no_testing_media("This may stop some packages from being downgraded.") + or return; + disable_buttons(); + if ($active_qa_repo) { + disable_repo(); + } + downgrade_packages(); + set_state('disabled'); +} + sub dialogue_dismiss { if ($fatal_error) { Gtk3->main_quit(); @@ -389,6 +404,7 @@ sub set_state { $button2->set_sensitive($active_qa_repo); $button3->set_sensitive($state ne 'enabled'); $button4->set_sensitive(TRUE); + $button5->set_sensitive($state ne 'changed'); if ($state eq 'changed' || $state eq 'failed') { $button3->set_label('Update'); } else { @@ -401,6 +417,7 @@ sub disable_buttons { $button2->set_sensitive(FALSE); $button3->set_sensitive(FALSE); $button4->set_sensitive(FALSE); + $button5->set_sensitive(FALSE); gtk_update(); } @@ -663,6 +680,34 @@ sub sync_error { 0; } +sub downgrade_packages { + my $synthesis = "$qa_repo/$arch/media_info/synthesis.hdlist.cz"; + if (! -e $synthesis) { + my $message = "no synthesis file found in local repository"; + show_error_dialogue($message); + print_error($message); + return 0; + } + + my @packages; + my $urpm = new URPM; + $urpm->parse_synthesis($synthesis); + $urpm->traverse(sub { + my ($pkg) = @_; + my $full_name = $pkg->fullname; + if (system("rpm --quiet -q $full_name") == 0) { + push @packages, $pkg->name(); + } + }); + + if (@packages) { + @packages = sort @packages; + show_downgrade_dialogue("urpmi --update --downgrade @packages"); + } else { + show_error_dialogue("none of the listed packages are installed"); + } +} + sub trim { my ($text) = @_; $text =~ s/^\s+//; @@ -679,6 +724,14 @@ sub wildcard_to_regexp { $pattern; } +sub show_downgrade_dialogue { + $dialogue_window->set_title('Downgrade'); + $dialogue_label->set_text('The following command may be used to downgrade the listed packages:'); + $dialogue_text->get_buffer()->set_text(join("\n", @_)); + $dialogue_text->set_wrap_mode('GTK_WRAP_WORD_CHAR'); + $dialogue_window->show_all(); +} + sub show_error_dialogue { $dialogue_window->set_title('Error'); $dialogue_label->set_text('The following error(s) occurred:'); -- cgit v1.2.1