/[soft]/mgaonline/trunk/mgaonline.pm
ViewVC logotype

Contents of /mgaonline/trunk/mgaonline.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1560 - (show annotations) (download)
Fri May 27 11:37:02 2011 UTC (12 years, 10 months ago) by tv
File size: 9971 byte(s)
(is_extmaint_supported,is_enterprise_media_supported,is_restricted_media_supported)
disable Enterprise media, Extended Maintenance, Restricted media as
those are not supported on Mageia but they do exist on mdv (mga#1153)

1 ################################################################################
2 # Mandriva Online functions #
3 # #
4 # Copyright (C) 2004-2005 Mandrakesoft #
5 # 2005-2006 Mandriva #
6 # #
7 # Daouda Lo #
8 # Thierry Vignaud <tvignaud at mandriva dot com> #
9 # #
10 # This program is free software; you can redistribute it and/or modify #
11 # it under the terms of the GNU General Public License Version 2 as #
12 # published by the Free Software Foundation. #
13 # #
14 # This program is distributed in the hope that it will be useful, #
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 # GNU General Public License for more details. #
18 # #
19 # You should have received a copy of the GNU General Public License #
20 # along with this program; if not, write to the Free Software #
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
22 ################################################################################
23
24 package mgaonline;
25
26 use strict;
27
28 use lib qw(/usr/lib/libDrakX);
29 use common;
30 use ugtk2;
31
32 use LWP::UserAgent;
33 use URI::Escape;
34 use XML::Simple;
35 use HTTP::Request::Common;
36 use HTTP::Request;
37
38 our @ISA = qw(Exporter);
39 our @EXPORT = qw(find_current_distro
40 fork_exec
41 get_banner
42 get_distro_list
43 get_from
44 get_product_id
45 get_release
46 get_stale_upgrade_filename
47 get_urpmi_options
48 is_it_2008_0
49 is_enterprise_media_supported
50 is_extmaint_supported
51 is_restricted_media_supported
52 read_sys_config
53 translate_product
54 xml2perl
55 %config
56 $config_file
57 $product_id
58 $root);
59 our @EXPORT_OK = qw(
60 get_product_info
61 get_my_mdv_profile
62 add_medium_powerpack
63 add_medium_enterprise
64 add_medium_extended
65 );
66
67 our (%config, $product_id, $root);
68 our $version = 1;
69
70 use log;
71
72 our $config_file = '/etc/sysconfig/mgaapplet';
73 my $release_file = find { -f $_ } map { "/etc/${_}release" } '', qw(mageia- mandriva- mandrakelinux- mandrake- redhat-);
74
75 sub read_sys_config() {
76 %config = getVarsFromSh($config_file);
77 }
78
79 sub get_stale_upgrade_filename() {
80 '/var/lib/urpmi/stale_upgrade_in_progress';
81 }
82
83 sub get_product_id() {
84 $product_id = common::parse_LDAP_namespace_structure(cat_("$root/etc/product.id"));
85 }
86
87 sub get_release() {
88 my ($r) = cat_($release_file) =~ /release\s+(\S+)/;
89 ($r);
90 }
91
92 sub is_it_2008_0() {
93 $product_id->{version} eq '2008.0';
94 }
95
96 sub is_extmaint_supported() {
97 return; # NOT SUPPORTED ON MAGEIA
98 $product_id->{support} eq 'extended';
99 }
100
101 sub is_enterprise_media_supported() {
102 return; # NOT SUPPORTED ON MAGEIA
103 return if is_it_2008_0();
104 to_bool($product_id->{type} eq 'Enterprise' && $product_id->{product} eq 'Server');
105 }
106
107 sub is_restricted_media_supported() {
108 return; # NOT SUPPORTED ON MAGEIA
109 return if is_it_2008_0();
110 to_bool($product_id->{product} =~ /powerpack/i);
111 }
112
113 sub find_current_distro {
114 find { $_->{version} eq $product_id->{version} } @_;
115 }
116
117 sub get_distro_list_() {
118 #- contact the following URL to retrieve the list of released distributions.
119 my $type = lc($product_id->{type}); $type =~ s/\s//g;
120 my $extra_path = $::testing || uc($config{TEST_DISTRO_UPGRADE}) eq 'YES' ? 'testing-' : '';
121 my $list =
122 join('&',
123 "https://releases.mageia.org/api/a/$extra_path$product_id->{arch}?product=$product_id->{product}",
124 "version=$product_id->{version}",
125 "mgaonline_version=$mgaonline::version",
126 );
127 log::explanations("trying distributions list from $list");
128
129 eval {
130 my $urpm = Rpmdrake::open_db::fast_open_urpmi_db();
131
132 # prevent SIGCHILD handler's waitpid to interfere with urpmi waiting
133 # for curl exit code, which broke downloads:
134 local $SIG{CHLD} = 'DEFAULT';
135
136 # old API:
137 if (member($product_id->{version}, qw(2007.1 2008.0 2008.1))) {
138 require mgaapplet_urpm;
139 mgaapplet_urpm::ensure_valid_cachedir($urpm);
140 mgaapplet_urpm::get_content($urpm, $list);
141 } else {
142 urpm::ensure_valid_cachedir($urpm);
143 urpm::download::get_content($urpm, $list);
144 }
145 };
146 }
147
148 sub get_distro_list() {
149 return if $product_id->{product} =~ /Flash/;
150
151 my @lines = get_distro_list_();
152
153 if (my $err = $@) {
154 log::explanations("failed to download distribution list:\n$err");
155 return; # not a fatal error
156 }
157
158 if (!@lines) {
159 log::explanations("empty distribution list");
160 return;
161 }
162
163 map { common::parse_LDAP_namespace_structure(chomp_($_)) } grep { /^[^#]/ } @lines;
164 }
165
166
167 sub clean_confdir() {
168 my $confdir = '/root/.MdkOnline';
169 system "/bin/rm", "-f", "$confdir/*log.bz2", "$confdir/*log.bz2.uue", "$confdir/*.dif $confdir/rpm_qa_installed_before", "$confdir/rpm_qa_installed_after";
170 }
171
172
173 sub fork_exec {
174 run_program::raw({ detach => 1 }, @_);
175 }
176
177 sub translate_product {
178 my ($product) = @_;
179 my %strings = (
180 flash => N("Mageia Flash"),
181 free => N("Mageia Free"),
182 mini => N("Mageia Mini"),
183 one => N("Mageia One"),
184 powerPack => N("Mageia PowerPack"),
185 server => N("Mageia Enterprise Server"),
186 );
187 $product ||= lc $product_id->{product};
188 $strings{$product} || $product;
189 }
190
191 # TODO Move all product.id handling to a separate module
192 # (MDV::ProductId?)
193 sub get_product_info {
194 my ($product) = @_;
195 my %info = (
196 powerpack => {
197 name => N("Mageia PowerPack"),
198 description => N("The Mageia Linux distribution with even more softwares and official support."),
199 },
200 free => {
201 name => N("Mageia Free"),
202 description => N("The 100%% Open Source distribution freely available."),
203 },
204 );
205 $product ||= lc $product_id->{product};
206 return $info{$product};
207 }
208
209 sub get_banner_icon() {
210 find { -e $_ }
211 qw(/usr/share/mcc/themes/default/rpmdrake-mga.png /usr/share/icons/large/mgaonline.png);
212 }
213
214 sub get_banner {
215 my ($o_title) = @_;
216 Gtk2::Banner->new(get_banner_icon(), $o_title || N("Distribution Upgrade"));
217 }
218
219 sub get_urpmi_options() {
220 ({ sensitive_arguments => 1 }, 'urpmi.addmedia', if_(!is_it_2008_0(), '--xml-info', 'always'));
221 }
222
223 sub add_medium_enterprise {
224 my ($email, $password, $version, $arch) = @_;
225 my $uri = sprintf('https://%s:%s@download.FIXME.com/%s/rpms/%s/',
226 uri_escape($email),
227 uri_escape($password),
228 $version,
229 $arch);
230 my @options = get_urpmi_options();
231 run_program::raw(@options, '--update', '--distrib', $uri);
232 }
233
234 sub add_medium_powerpack {
235 my ($email, $password, $version, $arch) = @_;
236 my $uri = sprintf('https://%s:%s@dl.FIXME.com/rpm/comm/%s/',
237 uri_escape($email),
238 uri_escape($password),
239 $version);
240 my @options = get_urpmi_options();
241
242 # add release and updates media...
243 run_program::raw(@options,
244 "Restricted $arch " . int(rand(100000)),
245 "$uri$arch")
246 or return 0;
247 run_program::raw(@options,
248 '--update',
249 "Restricted Updates $arch " . int(rand(100000)),
250 "${uri}updates/$arch");
251 }
252
253 sub add_medium_extended {
254 my ($email, $password, $version, $arch) = @_;
255 my $uri = sprintf("https://%s:%s\@dl.FIXME.com/extended/%s/%s",
256 uri_escape($email),
257 uri_escape($password),
258 $version,
259 $arch);
260 my @options = (get_urpmi_options(), '--update');
261 run_program::raw(@options,
262 "Extended Maintenance $arch " . int(rand(100000)),
263 ${uri});
264 }
265
266 sub is_running {
267 my ($name) = @_;
268 my $found;
269 foreach (`ps -o '%P %p %c' -u $ENV{USER}`) {
270 my ($ppid, $pid, $n) = /^\s*(\d+)\s+(\d+)\s+(.*)/;
271 if ($ppid != 1 && $pid != $$ && $n eq $name) {
272 $found = $pid;
273 last;
274 }
275 }
276 $found;
277 }
278
279
280 sub get_from {
281 my ($link, $header) = @_;
282
283 my $ua = LWP::UserAgent->new;
284 $ua->agent(sprintf('mgaapplet (mgaonline-%s; distribution: %s)',
285 $mgaonline::version, $version));
286 $ua->env_proxy;
287
288 my $response = $ua->post($link, $header);
289 $response;
290 }
291
292 sub get_my_mdv_profile {
293 my ($email, $password) = @_;
294 xml2perl(get_from('https://my.FIXME.com/rest/authenticate',
295 [ 'username', $email, 'password', $password,
296 'return', 'userdata' ]));
297 }
298
299 # callers need to require XML::Simple
300 sub xml2perl {
301 my ($res) = @_;
302 my $ref = eval { XML::Simple->new->XMLin($res->{_content}) };
303 if (my $err = $@) {
304 warn ">> XML error: $err\n";
305 $ref = {
306 code => 1,
307 message => $err,
308 };
309 }
310 $ref;
311 }
312
313
314 1;

  ViewVC Help
Powered by ViewVC 1.1.30