/[soft]/rpm/urpmi/trunk/gurpmi.pm
ViewVC logotype

Contents of /rpm/urpmi/trunk/gurpmi.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (show annotations) (download)
Wed Feb 1 19:19:21 2012 UTC (12 years, 1 month ago) by tv
File size: 4920 byte(s)
perl_checker cleanups
1 package gurpmi;
2
3 #- Copyright (C) 2005 MandrakeSoft SA
4 #- Copyright (C) 2005-2010 Mandriva SA
5 #- $Id: gurpmi.pm 271299 2010-11-21 15:54:30Z peroyvind $
6
7 #- This is needed because text printed by Gtk2 will always be encoded
8 #- in UTF-8; we first check if LC_ALL is defined, because if it is,
9 #- changing only LC_COLLATE will have no effect.
10 use POSIX ();
11 use locale;
12 my $collation_locale = $ENV{LC_ALL};
13 if ($collation_locale) {
14 $collation_locale =~ /UTF-8/ or POSIX::setlocale(POSIX::LC_ALL(), "$collation_locale.UTF-8");
15 } else {
16 $collation_locale = POSIX::setlocale(POSIX::LC_COLLATE());
17 $collation_locale =~ /UTF-8/ or POSIX::setlocale(POSIX::LC_COLLATE(), "$collation_locale.UTF-8");
18 }
19
20 use urpm;
21 use strict;
22 use Gtk2;
23 use urpm::util;
24 use urpm::msg;
25 use urpm::args;
26 use urpm::select;
27 use Locale::gettext;
28
29 Locale::gettext::bind_textdomain_codeset('urpmi', 'UTF8');
30 URPM::bind_rpm_textdomain_codeset();
31
32 use Exporter;
33 our @ISA = qw(Exporter);
34 our @EXPORT = qw(create_scrolled_window fatal but cancel_n_quit quit add_button_box new_label N);
35
36 urpm::select::add_packages_to_priority_upgrade_list('gurpmi');
37
38 sub usage () {
39 print N("urpmi version %s
40 Copyright (C) 1999-2010 Mandriva.
41 This is free software and may be redistributed under the terms of the GNU GPL.
42
43 usage:
44 ", $urpm::VERSION) . " gurpmi <rpm> [ <rpm>... ]
45 " . N("Options:") . "\n"
46 . N(" --help - print this help message.
47 ") . N(" --auto - non-interactive mode, assume default answers to questions.
48 ") . N(" --auto-select - automatically select packages to upgrade the system.
49 ") . N(" --force - force invocation even if some packages do not exist.
50 ") . N(" --verify-rpm - verify rpm signature before installation
51 (--no-verify-rpm disables it, default is enabled).
52 ") . N(" --media - use only the given media, separated by comma.
53 ") . N(" -p - allow search in provides to find package.
54 ") . N(" -P - do not search in provides to find package.
55 ") . N(" --root - use another root for rpm installation.
56 ") . N(" --test - only verify if the installation can be achieved correctly.
57 ") . N(" --searchmedia - use only the given media to search requested packages.
58 ");
59 exit 0;
60 }
61
62 #- fatal gurpmi initialisation error (*not* fatal urpmi errors)
63 sub fatal { my $s = $_[0]; print STDERR "$s\n"; exit 1 }
64
65 #- Parse command line
66 #- puts options in %gurpmi::options
67 #- puts bare names (not rpm filenames) in @gurpmi::names
68 sub parse_command_line() {
69 my @all_rpms;
70 our %options;
71 our @names;
72
73 # keep a copy for gurpmi2
74 {
75 local @ARGV = @ARGV;
76 urpm::args::parse_cmdline(urpm => { options => \%options });
77 }
78
79 # Expand *.urpmi arguments
80 my @ARGV_expanded;
81 foreach my $a (@ARGV) {
82 if ($a =~ /\.urpmi$/) {
83 open my $fh, '<', $a or do { warn "Can't open $a: $!\n"; next };
84 push @ARGV_expanded, map { chomp; $_ } <$fh>;
85 close $fh;
86 } else {
87 push @ARGV_expanded, $a;
88 }
89 }
90 foreach (@ARGV_expanded) {
91 next if /^-/;
92 if (-f $_) {
93 push @all_rpms, $_;
94 } else {
95 push @names, $_;
96 }
97
98 }
99 $::auto_select || @all_rpms + @names
100 or fatal(N("No packages specified"));
101 return @all_rpms;
102 }
103
104 sub but($) { " $_[0] " }
105
106 sub quit() {
107 if (Gtk2->main_level) {
108 Gtk2->main_quit;
109 } else {
110 # just exit if not in main loop (eg: while starting the GUI)
111 exit 1;
112 }
113 }
114
115 sub cancel_n_quit() {
116 Gtk2->main_quit;
117 exit(1);
118 }
119
120 sub add_button_box {
121 my ($vbox, @buttons) = @_;
122 my $hbox = Gtk2::HButtonBox->new;
123 $vbox->pack_start($hbox, 0, 0, 0);
124 $hbox->set_layout('edge');
125 $_->set_alignment(0.5, 0.5), $hbox->add($_) foreach @buttons;
126 }
127
128 sub new_label {
129 my ($msg) = @_;
130 my $label = Gtk2::Label->new($msg);
131 $label->set_line_wrap(1);
132 $label->set_alignment(0.5, 0.5);
133 if (($msg =~ tr/\n/\n/) > 5) {
134 my $sw = create_scrolled_window($label, [ 'never', 'automatic' ]);
135 $sw->set_size_request(-1,200);
136 return $sw;
137 } else {
138 return $label;
139 }
140 }
141
142 # copied from ugtk2:
143 sub create_scrolled_window {
144 my ($W, $o_policy, $o_viewport_shadow) = @_;
145 my $w = Gtk2::ScrolledWindow->new(undef, undef);
146 $w->set_policy($o_policy ? @$o_policy : ('automatic', 'automatic'));
147 if (member(ref($W), qw(Gtk2::Layout Gtk2::Html2::View Gtk2::Text Gtk2::TextView Gtk2::TreeView))) {
148 $w->add($W);
149 } else {
150 $w->add_with_viewport($W);
151 }
152 $o_viewport_shadow and $w->child->set_shadow_type($o_viewport_shadow);
153 $W->can('set_focus_vadjustment') and $W->set_focus_vadjustment($w->get_vadjustment);
154 $W->set_left_margin(6) if ref($W) =~ /Gtk2::TextView/;
155 $W->show;
156 if (ref($W) =~ /Gtk2::TextView|Gtk2::TreeView/) {
157 my $f = Gtk2::Frame->new;
158 $w->show; # unlike ugtk2, we'd to do this explicitely...
159 $f->set_shadow_type('in');
160 $f->add($w);
161 $f;
162 } else {
163 $w;
164 }
165 }
166
167 1;

  ViewVC Help
Powered by ViewVC 1.1.30