line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package urpm::msg; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
8
|
|
|
8
|
|
40
|
use strict; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
386
|
|
5
|
8
|
|
|
8
|
|
62
|
no warnings; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
466
|
|
6
|
8
|
|
|
8
|
|
58
|
use Exporter; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
518
|
|
7
|
8
|
|
|
8
|
|
5111
|
use URPM; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use urpm::util 'append_to_file'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $encoding; |
11
|
|
|
|
|
|
|
BEGIN { |
12
|
|
|
|
|
|
|
eval { require encoding; $encoding = encoding::_get_locale_encoding() }; |
13
|
|
|
|
|
|
|
eval "use open ':locale'" if $encoding && $encoding ne 'ANSI_X3.4-1968'; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = 'Exporter'; |
17
|
|
|
|
|
|
|
our @EXPORT = qw(N N_ P translate bug_log message_input toMb formatXiB sys_log); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#- I18N. |
20
|
|
|
|
|
|
|
use Locale::gettext; |
21
|
|
|
|
|
|
|
use POSIX (); |
22
|
|
|
|
|
|
|
POSIX::setlocale(POSIX::LC_ALL(), ""); |
23
|
|
|
|
|
|
|
my @textdomains = qw(urpmi rpm-summary-main rpm-summary-contrib rpm-summary-devel); |
24
|
|
|
|
|
|
|
foreach my $domain (@textdomains) { |
25
|
|
|
|
|
|
|
Locale::gettext::bind_textdomain_codeset($domain, 'UTF-8'); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
URPM::bind_rpm_textdomain_codeset(); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $no_translation; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub from_locale_encoding { |
32
|
|
|
|
|
|
|
my ($s) = @_; |
33
|
|
|
|
|
|
|
$encoding && eval { |
34
|
|
|
|
|
|
|
require Encode; |
35
|
|
|
|
|
|
|
Encode::decode($encoding, $s); |
36
|
|
|
|
|
|
|
} || do { |
37
|
|
|
|
|
|
|
require utf8; |
38
|
|
|
|
|
|
|
utf8::decode($s); |
39
|
|
|
|
|
|
|
$s; |
40
|
|
|
|
|
|
|
} || $s; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub translate { |
44
|
|
|
|
|
|
|
my ($s, $o_plural, $o_nb) = @_; |
45
|
|
|
|
|
|
|
my $res; |
46
|
|
|
|
|
|
|
if ($no_translation) { |
47
|
|
|
|
|
|
|
$s; |
48
|
|
|
|
|
|
|
} elsif ($o_nb) { |
49
|
|
|
|
|
|
|
foreach my $domain (@textdomains) { |
50
|
|
|
|
|
|
|
eval { $res = Locale::gettext::dngettext($domain, $s || '', $o_plural, $o_nb) || $s }; |
51
|
|
|
|
|
|
|
return $res if $s ne $res; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
return $s; |
54
|
|
|
|
|
|
|
} else { |
55
|
|
|
|
|
|
|
foreach my $domain (@textdomains) { |
56
|
|
|
|
|
|
|
eval { $res = Locale::gettext::dgettext($domain, $s || '') || $s }; |
57
|
|
|
|
|
|
|
return $res if $s ne $res; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
return $s; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub P { |
64
|
|
|
|
|
|
|
my ($s_singular, $s_plural, $nb, @para) = @_; |
65
|
|
|
|
|
|
|
sprintf(translate($s_singular, $s_plural, $nb), @para); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub N { |
69
|
|
|
|
|
|
|
my ($format, @params) = @_; |
70
|
|
|
|
|
|
|
sprintf(translate($format), @params); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
sub N_ { $_[0] } |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $noexpr = N("Nn"); |
75
|
|
|
|
|
|
|
my $yesexpr = N("Yy"); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
eval { |
78
|
|
|
|
|
|
|
require Sys::Syslog; |
79
|
|
|
|
|
|
|
Sys::Syslog->import; |
80
|
|
|
|
|
|
|
(my $tool = $0) =~ s!.*/!!; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#- what we really want is "unix" (?) |
83
|
|
|
|
|
|
|
#- we really don't want "console" which forks/exit and thus |
84
|
|
|
|
|
|
|
# run callbacks registered through atexit() : x11, gtk+, rpm, ... |
85
|
|
|
|
|
|
|
Sys::Syslog::setlogsock([ 'tcp', 'unix', 'stream' ]); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
openlog($tool, '', 'user'); |
88
|
|
|
|
|
|
|
END { defined &closelog and closelog() } |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub sys_log { defined &syslog and eval { syslog("info", @_) } } |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#- writes only to logfile, not to screen |
94
|
|
|
|
|
|
|
sub bug_log { |
95
|
|
|
|
|
|
|
append_to_file($::logfile, @_) if $::logfile; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub ask_yes_or_no { |
99
|
|
|
|
|
|
|
my ($msg) = @_; |
100
|
|
|
|
|
|
|
message_input($msg . N(" (y/N) "), boolean => 1) =~ /[$yesexpr]/; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub message_input { |
104
|
|
|
|
|
|
|
my ($msg, %o_opts) = @_; |
105
|
|
|
|
|
|
|
_message_input($msg, undef, %o_opts); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
sub _message_input { |
108
|
|
|
|
|
|
|
my ($msg, $o_default_input, %o_opts) = @_; |
109
|
|
|
|
|
|
|
my $input; |
110
|
|
|
|
|
|
|
while (1) { |
111
|
|
|
|
|
|
|
print $msg; |
112
|
|
|
|
|
|
|
if ($o_default_input) { |
113
|
|
|
|
|
|
|
#- deprecated argument. don't you want to use $o_opts{default} instead? |
114
|
|
|
|
|
|
|
$urpm::args::options{bug} and bug_log($o_default_input); |
115
|
|
|
|
|
|
|
return $o_default_input; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
$input = ; |
118
|
|
|
|
|
|
|
defined $input or return undef; |
119
|
|
|
|
|
|
|
chomp $input; |
120
|
|
|
|
|
|
|
$urpm::args::options{bug} and bug_log($input); |
121
|
|
|
|
|
|
|
if ($o_opts{boolean}) { |
122
|
|
|
|
|
|
|
$input =~ /^[$noexpr$yesexpr]?$/ and last; |
123
|
|
|
|
|
|
|
} elsif ($o_opts{range}) { |
124
|
|
|
|
|
|
|
$input eq "" and $input = $o_opts{default} || 1; #- defaults to first choice |
125
|
|
|
|
|
|
|
(defined $o_opts{range_min} ? $o_opts{range_min} : 1) <= $input && $input <= $o_opts{range} and last; |
126
|
|
|
|
|
|
|
} else { |
127
|
|
|
|
|
|
|
last; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
print N("Sorry, bad choice, try again\n"); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
return $input; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub toMb { |
135
|
|
|
|
|
|
|
my $nb = $_[0] / 1024 / 1024; |
136
|
|
|
|
|
|
|
int $nb + 0.5; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my @format_line_field_sizes = (30, 12, 13, 7, 0); |
140
|
|
|
|
|
|
|
my $format_line_format = ' ' . join(' ', map { '%-' . $_ . 's' } @format_line_field_sizes); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub format_line_selected_packages { |
143
|
|
|
|
|
|
|
my ($urpm, $state, $pkgs) = @_; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my (@pkgs, @lines, $prev_medium); |
146
|
|
|
|
|
|
|
my $flush = sub { |
147
|
|
|
|
|
|
|
push @lines, _format_line_selected_packages($state, $prev_medium, \@pkgs); |
148
|
|
|
|
|
|
|
@pkgs = (); |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
foreach my $pkg (@$pkgs) { |
151
|
|
|
|
|
|
|
my $medium = URPM::pkg2media($urpm->{media}, $pkg); |
152
|
|
|
|
|
|
|
if ($prev_medium && $prev_medium ne $medium) { |
153
|
|
|
|
|
|
|
$flush->(); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
push @pkgs, $pkg; |
156
|
|
|
|
|
|
|
$prev_medium = $medium; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
$flush->(); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
(sprintf($format_line_format, N("Package"), N("Version"), N("Release"), N("Arch")), |
161
|
|
|
|
|
|
|
@lines); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
sub _format_line_selected_packages { |
164
|
|
|
|
|
|
|
my ($state, $medium, $pkgs) = @_; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my @l = map { |
167
|
|
|
|
|
|
|
my @name_and_evr = $_->fullname; |
168
|
|
|
|
|
|
|
if ($state->{selected}{$_->id}{recommended}) { |
169
|
|
|
|
|
|
|
push @name_and_evr, N("(recommended)"); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
\@name_and_evr; |
172
|
|
|
|
|
|
|
} sort { $a->name cmp $b->name } @$pkgs; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $i; |
175
|
|
|
|
|
|
|
foreach my $max (@format_line_field_sizes) { |
176
|
|
|
|
|
|
|
foreach (@l) { |
177
|
|
|
|
|
|
|
if ($max && length($_->[$i]) > $max) { |
178
|
|
|
|
|
|
|
$_->[$i] = substr($_->[$i], 0, $max-1) . '>'; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
$i++; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
('(' . ($medium ? N("medium \"%s\"", $medium->{name}) : N("command line")) . ')', |
185
|
|
|
|
|
|
|
map { sprintf($format_line_format, @$_) } @l); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# duplicated from svn+ssh://svn.mandriva.com/svn/soft/drakx/trunk/perl-install/common.pm |
189
|
|
|
|
|
|
|
sub formatXiB { |
190
|
|
|
|
|
|
|
my ($newnb, $o_newbase) = @_; |
191
|
|
|
|
|
|
|
my $newbase = $o_newbase || 1; |
192
|
|
|
|
|
|
|
my ($nb, $base); |
193
|
|
|
|
|
|
|
my $decr = sub { |
194
|
|
|
|
|
|
|
($nb, $base) = ($newnb, $newbase); |
195
|
|
|
|
|
|
|
$base >= 1024 ? ($newbase = $base / 1024) : ($newnb = $nb / 1024); |
196
|
|
|
|
|
|
|
}; |
197
|
|
|
|
|
|
|
my $suffix; |
198
|
|
|
|
|
|
|
foreach (N("B"), N("KB"), N("MB"), N("GB"), N("TB")) { |
199
|
|
|
|
|
|
|
$decr->(); |
200
|
|
|
|
|
|
|
if ($newnb < 1 && $newnb * $newbase < 1) { |
201
|
|
|
|
|
|
|
$suffix = $_; |
202
|
|
|
|
|
|
|
last; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
my $v = $nb * $base; |
206
|
|
|
|
|
|
|
my $s = $v < 10 && int(10 * $v - 10 * int($v)); |
207
|
|
|
|
|
|
|
int($v) . ($s ? ".$s" : '') . ($suffix || N("TB")); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub localtime2changelog { scalar(localtime($_[0])) =~ /(.*) \S+ (\d{4})$/ && "$1 $2" } |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 NAME |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
urpm::msg - routines to prompt messages from the urpm* tools |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 SYNOPSIS |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 DESCRIPTION |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 COPYRIGHT |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 MandrakeSoft SA |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Copyright (C) 2005-2010 Mandriva SA |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=cut |