summaryrefslogtreecommitdiffstats
path: root/mgaapplet-add-media-helper
diff options
context:
space:
mode:
authorMageia SVN-Git Migration <svn-git-migration@mageia.org>2011-05-14 01:22:07 +0100
committerMageia SVN-Git Migration <svn-git-migration@mageia.org>2011-05-14 01:22:07 +0100
commite0ada251ac68dc91192c7ec7d10f3a1d7784916a (patch)
tree225ed465e93c82ad37c2794144850635b395d594 /mgaapplet-add-media-helper
parent5d4a18c95ac1ef5a657b5dcefd8a47e429d74058 (diff)
downloadmgaonline-e0ada251ac68dc91192c7ec7d10f3a1d7784916a.tar
mgaonline-e0ada251ac68dc91192c7ec7d10f3a1d7784916a.tar.gz
mgaonline-e0ada251ac68dc91192c7ec7d10f3a1d7784916a.tar.bz2
mgaonline-e0ada251ac68dc91192c7ec7d10f3a1d7784916a.tar.xz
mgaonline-e0ada251ac68dc91192c7ec7d10f3a1d7784916a.zip
Synthesized commit during git-svn import combining previous Mandriva history with Mageia.2.77.22
This commit consitsts of the following subversion commits: ------------------------------------------------------------------------ r1310 | dmorgan | 2011-05-14 01:22:07 +0100 (Sat, 14 May 2011) | 1 line Import cleaned mgaonline ------------------------------------------------------------------------
Diffstat (limited to 'mgaapplet-add-media-helper')
-rwxr-xr-xmgaapplet-add-media-helper255
1 files changed, 255 insertions, 0 deletions
diff --git a/mgaapplet-add-media-helper b/mgaapplet-add-media-helper
new file mode 100755
index 00000000..cd6e747b
--- /dev/null
+++ b/mgaapplet-add-media-helper
@@ -0,0 +1,255 @@
+#!/usr/bin/perl
+###########################################################################
+# Copyright (C) 2010 Mandriva
+#
+# Thierry Vignaud <tvignaud@mandriva.com>
+# João Victor Duarte Martins <jvictor@mandriva.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License Version 2 as
+# published by the Free Software Foundation.
+#
+# 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.
+###########################################################################
+
+BEGIN { unshift @::textdomains, 'mgaonline' }
+
+use strict;
+use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime);
+use standalone; # for explanations
+use common;
+use run_program;
+use interactive;
+use interactive::gtk;
+use mygtk2 qw(gtknew); # only gtknew, any other stuff would break ugtk2
+use ugtk2 qw(:all);
+use mgaonline qw($product_id);
+use mgaapplet_gui;
+use urpm::cfg;
+use utf8;
+
+# %product is keyed by product id and it contains the data to add
+# restricted media for each product.
+my %product = (
+ powerpack => {
+ info_url => 'https://my.mandriva.com/powerpack/',
+ has_rights => sub {
+ my $profile = shift @_;
+ $profile->{data}{'can-access-restricted-repositories'} eq 'YES';
+ },
+ media_name => 'Restricted',
+ add_medium => \&mgaonline::add_medium_powerpack
+
+ },
+ server => {
+ info_url => 'http://www2.mandriva.com/linux/server/',
+ has_rights => sub {
+ my $profile = shift @_;
+ $profile->{data}{groups}{'es5-prod'} or
+ $profile->{data}{groups}{'es5-demo'};
+ },
+ media_name => 'Update',
+ add_medium => \&mgaonline::add_medium_enterprise
+ },
+ extended => {
+ info_url => 'https://my.mandriva.com/',
+ has_rights => sub {
+ my ($profile, $version) = @_;
+ return ! ref $profile->{data}{groups}{'ext-maint-' . $version};
+ },
+ media_name => 'Extended Maintenance',
+ add_medium => \&mgaonline::add_medium_extended,
+ success_callback => sub {
+ mgaonline::read_sys_config();
+ $mgaonline::config{EXTENDED_SUPPORT} = bool2yesno(1);
+ mgaonline::setVarsInSh($mgaonline::config_file,
+ \%mgaonline::config);
+ }
+ }
+ );
+
+# Distribution upgrade version and product
+my $up_version;
+my $up_product;
+
+# Dialogs title and banner text
+my $title = N("Adding an additional package medium");
+
+my $current_apimdv_distro;
+
+# ######################################################################
+# Main Program
+
+{
+ # Parsing command line arguments.
+ my $usage =
+ "Usage: $0 [OPTION]... VERSION\n" .
+ "Add package medias for VERSION (of current product by default).\n" .
+ "\n" .
+ " --rpm-root=PATH Use PATH as root for rpm\n" .
+ " --urpmi-root=PATH Use PATH as root for rpm and urpmi\n" .
+ " --product=NAME Upgrade to VERSION of product named NAME\n";
+
+
+ foreach (@ARGV) {
+ if (/^--(rpm-root|urpmi-root)=(.+)/) {
+ $::rpmdrake_options{$1}[0] = $2;
+ }
+ elsif (/^--product=(.+)/) {
+ $up_product = lc $1;
+ }
+ elsif (/^([^-]{2}.+)/) {
+ $up_version = $1;
+ }
+ else {
+ die $usage;
+ }
+ }
+ $up_version or die $usage;
+
+ # FIXME Couldn't that be automatic called when mgaonline.pm is used?
+ $product_id or mgaonline::get_product_id();
+
+ # Product id data should be used in lowercase.
+ $up_product ||= lc $product_id->{product};
+
+ # Sanitizes product command line argument.
+ unless (exists $product{$up_product}) {
+ my $available = join ", ", map { "'$_'" } keys %product;
+ $available =~ s/(.+), ([^,]+)/$1 and $2/;
+ die N("Supported products are %s, '%s' is not on the list.\n",
+ $available,
+ $up_product);
+ }
+
+ run_authentication_dialog();
+ ugtk2::exit(0);
+}
+
+sub run_authentication_dialog {
+ my $description = N("Please fill in your account ID to add an additional package medium");
+ my $extra_info = undef; # extra widgets for the dialog
+
+ if ($up_product eq 'extended') {
+
+ # Setup extra_info widgets for extended product...
+ my ($url, $extmaint_end, $desktop_update_end, $basic_update_end)
+ = get_extended_maintenance_data();
+ if (my $err = $@) {
+ interactive->vnew->ask_warn(
+ N("Error"),
+ N("Failure while retrieving distributions list:") . "\n$err"
+ );
+ return;
+ }
+ $extra_info
+ = [ gtknew('Label_Left',
+ text_markup =>
+ join("\n\n",
+ #-PO: Here '%s' will be a localized date (eg:
+ # "2009/11/28" in english but "28/11/2009"
+ # for brazil or "28 Nov. "2009" for
+ # french:
+ N("Mageia provides 12 months of desktop updates (until %s) and 18 months of base updates (up to the %s) for distributions.",
+ mgaapplet_gui::iso8601_date_to_locale(
+ $desktop_update_end),
+ mgaapplet_gui::iso8601_date_to_locale(
+ $basic_update_end)
+ ),
+ N("Extended maintenance is now available to get 18 months of additional updates (until %s).",
+ mgaapplet_gui::iso8601_date_to_locale(
+ $extmaint_end)),
+ N("You can subscribe <b>right now</b> to get extended maintenance:"),
+ ),
+ @common),
+ new_link_button('http://www2.mandriva.com/support/lifecycle/',
+ N("Lifetime policy")),
+ new_link_button($url, N("Online subscription"))
+ ];
+ }
+
+ mgaapplet_gui::run_ask_credentials_dialog($title,
+ $description,
+ \&authenticate_callback,
+ top_extra => $extra_info);
+ return;
+}
+
+sub authenticate_callback {
+ my ($email, $passwd) = @_;
+ my $product = $product{$up_product};
+ my $profile = mgaonline::get_my_mdv_profile($email, $passwd);
+
+ if ($profile->{code} != 0) {
+ my $in = interactive->vnew;
+ $in->ask_warn(N("Error"),
+ N("An error occurred") . "\n" . $profile->{message});
+ goto &run_authentication_dialog;
+ }
+ elsif (!$product->{has_rights}->($profile)) {
+ mgaapplet_gui::run_no_rights_dialog(
+ $title,
+ N("Your Mageia account does not have %s download subscription enabled.",
+ mgaonline::translate_product($up_product)),
+ $product{$up_product}{info_url}
+ );
+ }
+ else {
+ add_medium_for_product($product, $email, $passwd);
+ }
+}
+
+sub add_medium_for_product {
+ my ($product, $email, $passwd) = @_;
+
+ my $error = 0;
+ my $current_arch = urpm::cfg::get_arch();
+ # FIXME: This is not enough if we ever support more 64 archs
+ # (sparc64, ppc64 and the like):
+ my @archs = ($current_arch, if_($current_arch eq 'x86_64', 'i586'));
+
+ foreach my $arch (@archs) {
+ unless ($product->{add_medium}->($email, $passwd, $up_version, $arch)) {
+ # FIXME: Backup original media setup so on error previous
+ # added media in this loop can be removed?
+ $error = 1;
+ interactive->vnew->ask_warn(
+ N("Error"),
+ N("An error occurred while adding medium")
+ );
+ goto &run_authentication_dialog;
+ }
+ }
+
+ unless ($error) {
+ $product->{success_callback} and $product->{success_callback}->();
+ my $w = ugtk2->new(N("Successfully added media!"),
+ grab => 1);
+ $w->_ask_okcancel(N("Successfully added media %s.",
+ $product->{media_name}),
+ N("Ok"),
+ undef);
+ ugtk2::main($w);
+ }
+}
+
+sub get_extended_maintenance_data() {
+ if (not $current_apimdv_distro) {
+ require Rpmdrake::open_db;
+ my @distros = mgaonline::get_distro_list();
+ return if !@distros;
+ $current_apimdv_distro = mgaonline::find_current_distro(@distros);
+ }
+ return @$current_apimdv_distro{ qw(extended-maintenance
+ extended-maintenance-end
+ desktop-update-end
+ basic-update-end) };
+}