/[gentoo-perl]/genlop/trunk/genlop
Gentoo

Diff of /genlop/trunk/genlop

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 206 Revision 207
15# You should have received a copy of the GNU General Public License 15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software 16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18# 18#
19 19
20# TODO: dberkholz recommended changing --date <string> [--date <string>]
21# to --start-date and --end-date to alleviate confusion like
22# http://bugs.gentoo.org/show_bug.cgi?id=128194#c0
23
20use strict; 24use strict;
21use warnings; 25use warnings;
22use POSIX; 26use POSIX;
23use Term::ANSIColor; 27use Term::ANSIColor;
24use Date::Manip; 28use Date::Manip;
26use File::Basename; 30use File::Basename;
27 31
28my $version = "0.30.7"; 32my $version = "0.30.7";
29my @logfiles = ("/var/log/emerge.log"); 33my @logfiles = ("/var/log/emerge.log");
30my %COLORS = ( 34my %COLORS = (
31 'blue' => 'bold blue', 35 'blue' => 'bold blue',
32 'green' => 'bold green', 36 'green' => 'bold green',
33 'red' => 'bold red', 37 'red' => 'bold red',
34); 38);
35my ($e_count, $w_count, $tm_secondi, $m_secondi) = (0, 0, 0, 0); 39my ($e_count, $w_count, $tm_secondi, $m_secondi) = (0, 0, 0, 0);
36 40
37# variabili per la funzione parse 41# variabili per la funzione parse
38my ( 42my (
39 $date_found, 43 $date_found,
40 $search_found, 44 $search_found,
41 $unmerge_found, 45 $unmerge_found,
42 $list_found, 46 $list_found,
43 $file_found, 47 $file_found,
44 $time_found, 48 $time_found,
45 $help_found, 49 $help_found,
46 $current_found, 50 $current_found,
47 $pretend_found, 51 $pretend_found,
48 $version_found, 52 $version_found,
49 $info_found, 53 $info_found,
50 $gmt_found, 54 $gmt_found,
51 $rsync_found, 55 $rsync_found,
52 $info_ok, 56 $info_ok,
53 $info_target, 57 $info_target,
54 $ssearch_found, 58 $ssearch_found,
55 $online_query, 59 $online_query,
56 $secs, 60 $secs,
57 $mins, 61 $mins,
58 $hours, 62 $hours,
59 $days, 63 $days,
60 $lhtomsg, 64 $lhtomsg,
61 $last_skipped 65 $last_skipped
62); 66);
63 67
64# variabili globali del programma 68# variabili globali del programma
65my ($e_start, $e_end, $search_string, $m_count, $ebuild_found); 69my ($e_start, $e_end, $search_string, $m_count, $ebuild_found);
69my @targets; 73my @targets;
70my $progname = basename($0); 74my $progname = basename($0);
71 75
72my ($userdate1, $userdate2, $searchdate1, $searchdate2); 76my ($userdate1, $userdate2, $searchdate1, $searchdate2);
73 77
74sub datecompare ($) 78sub datecompare ($)
75{ 79{
76
77 # datecompare( epoch ) 80 # datecompare( epoch )
78 # returns -1 if epoch is outside searchdates 1 and 2 81 # returns -1 if epoch is outside searchdates 1 and 2
79 # returns 1 if inside 82 # returns 1 if inside
80 # returns undefined for errors 83 # returns undefined for errors
81 # expects searchdate1 to be before searchdate2 and neither should be in 84 # expects searchdate1 to be before searchdate2 and neither should be in
82 # the future (but it's probably ok if searchdate2 is) 85 # the future (but it's probably ok if searchdate2 is)
83 die if (!$searchdate1); 86 die if (!$searchdate1);
84 die if (!$searchdate2); 87 die if (!$searchdate2);
85 my $epochdate = $_[0]; 88 my $epochdate = $_[0];
86 if (($epochdate <=> $searchdate1) < 0) 89 if (($epochdate <=> $searchdate1) < 0)
87 { 90 {
88
89 # epoch is outside period 91 # epoch is outside period
90 return -1; 92 return -1;
91 } 93 }
92 elsif (($epochdate <=> $searchdate2) > 0) 94 elsif (($epochdate <=> $searchdate2) > 0)
93 { 95 {
94
95 # epoch is outside period 96 # epoch is outside period
96 return -1; 97 return -1;
97 } 98 }
98 else 99 else
99 { 100 {
100 return 1; 101 return 1;
101 } 102 }
102
103 #TODO check that it's actually the case 103 #TODO check that it's actually the case
104} 104}
105 105
106# test a file, before opening it for reading 106# test a file, before opening it for reading
107# second argument is a reference to a variable thet gets populated with 107# second argument is a reference to a variable thet gets populated with
108# a filehandle to the first argument 108# a filehandle to the first argument
109sub open_file 109sub open_file
110{ 110{
111 my ($file, $fh) = @_; 111 my ($file, $fh) = @_;
112 if ($file eq "/var/log/emerge.log" && !-r $file) 112 if ($file eq "/var/log/emerge.log" && !-r $file)
113 { 113 {
114 print "$progname: cannot open " . $file . " for reading\n" . "maybe you are not a member of the portage group ?\n" . "try genlop -h for help\n"; 114 print "$progname: cannot open " . $file . " for reading\n"
115 exit 1; 115 . "maybe you are not a member of the portage group ?\n"
116 } 116 . "try genlop -h for help\n";
117 exit 1;
118 }
117 if (-T $file) 119 if (-T $file)
118 { 120 {
119 open $$fh, '<', "$file" 121 open $$fh, '<', "$file"
120 or die "could not open $file"; 122 or die "could not open $file";
121 return 0; 123 return 0;
122 } 124 }
123 125
124 # if we got here file is unreadable, might simply be compressed... 126 # if we got here file is unreadable, might simply be compressed...
125 # let's try this 127 # let's try this
126 my $nature = qx{file $file} 128 my $nature = qx{file $file}
127 or die "could not determine nature of (nonASCII) $file"; 129 or die "could not determine nature of (nonASCII) $file";
128 if ($nature =~ /gzip/) 130 if ($nature =~ /gzip/)
129 { 131 {
130 open $$fh, "gzip -d -c $file |" 132 open $$fh, "gzip -d -c $file |"
131 or die "could not open (gzipped) $file"; 133 or die "could not open (gzipped) $file";
132 return 0; 134 return 0;
133 } 135 }
134 elsif ($nature =~ /bzip/) 136 elsif ($nature =~ /bzip/)
135 { 137 {
136 open $$fh, "bzip2 -d -c $file |" 138 open $$fh, "bzip2 -d -c $file |"
137 or die "could not open (bzipped) $file"; 139 or die "could not open (bzipped) $file";
138 return 0; 140 return 0;
139 } 141 }
140 else 142 else
141 { 143 {
142 144 # giving up...
143 # giving up...
144 print "could not determine file type of $file\n"; 145 print "could not determine file type of $file\n";
145 exit 1; 146 exit 1;
146 } 147 }
147} 148}
148 149
149# orderes logfiles by date 150# orderes logfiles by date
150sub order_logs (@) 151sub order_logs (@)
151{ 152{
152 my @files = @_; 153 my @files = @_;
153 my %ordered; 154 my %ordered;
154 foreach my $logfile (@files) 155 foreach my $logfile (@files)
155 { 156 {
156 my $handle; 157 my $handle;
157 open_file("$logfile", \$handle); 158 open_file("$logfile", \$handle);
158 my $fline = <$handle>; # first line 159 my $fline = <$handle>; # first line
159 $ordered{$logfile} = (split /:/, $fline)[0]; 160 $ordered{$logfile} = (split /:/, $fline)[0];
160 } 161 }
161 return sort { $ordered{$a} <=> $ordered{$b} } keys %ordered; 162 return sort { $ordered{$a} <=> $ordered{$b} } keys %ordered;
162} 163}
163 164
164# parse(arg), a hacked-up version of getopts 165# parse(arg), a hacked-up version of getopts
165# sets (global) variables for options and returns. 166# sets (global) variables for options and returns.
166# non option arguments are pushed into a (global) array 167# non option arguments are pushed into a (global) array
167# 168#
168# FIXME Getopt::Long would be much better 169# FIXME Getopt::Long would be much better
169sub parse ($) 170sub parse ($)
170{ 171{
171 my $arg = $_[0]; 172 my $arg = $_[0];
172 my $nexist = 0; 173 my $nexist = 0;
173 chomp $arg; 174 chomp $arg;
174 175
175 # long (--foo) options 176 # long (--foo) options
176 if ($arg =~ /^--/) 177 if ($arg =~ /^--/)
177 { 178 {
178 LSWITCH: 179 LSWITCH:
179 { 180 {
180 $current_found = 1, last LSWITCH if ($arg eq "--current"); 181 $current_found = 1, last LSWITCH if ($arg eq "--current");
181 $pretend_found = 1, last LSWITCH if ($arg eq "--pretend"); 182 $pretend_found = 1, last LSWITCH if ($arg eq "--pretend");
182 $help_found = 1, last LSWITCH if ($arg eq "--help"); 183 $help_found = 1, last LSWITCH if ($arg eq "--help");
183 $time_found = 1, last LSWITCH if ($arg eq "--time"); 184 $time_found = 1, last LSWITCH if ($arg eq "--time");
184 $unmerge_found = 1, last LSWITCH if ($arg eq "--unmerge"); 185 $unmerge_found = 1, last LSWITCH if ($arg eq "--unmerge");
185 $ENV{'ANSI_COLORS_DISABLED'} = 1, last LSWITCH 186 $ENV{'ANSI_COLORS_DISABLED'} = 1, last LSWITCH
186 if ($arg eq "--nocolor"); 187 if ($arg eq "--nocolor");
187 $list_found = 1, last LSWITCH if ($arg eq "--list"); 188 $list_found = 1, last LSWITCH if ($arg eq "--list");
188 $version_found = 1, last LSWITCH if ($arg eq "--version"); 189 $version_found = 1, last LSWITCH if ($arg eq "--version");
189 $search_found = 1, last LSWITCH if ($arg eq "--search"); 190 $search_found = 1, last LSWITCH if ($arg eq "--search");
190 $info_found = 1, last LSWITCH if ($arg eq "--info"); 191 $info_found = 1, last LSWITCH if ($arg eq "--info");
191 $gmt_found = 1, last LSWITCH if ($arg eq "--gmt"); 192 $gmt_found = 1, last LSWITCH if ($arg eq "--gmt");
192 $rsync_found = 1, last LSWITCH if ($arg eq "--rsync"); 193 $rsync_found = 1, last LSWITCH if ($arg eq "--rsync");
193 194
194 if ($arg eq "--date") 195 if ($arg eq "--date")
195 { 196 {
196 $date_found = 1; 197 $date_found = 1;
197 if (!$userdate1) 198 if (!$userdate1)
198 { 199 {
199 help() if !$ARGV[0]; 200 help() if !$ARGV[0];
200 $userdate1 = ParseDate(\@ARGV); 201 $userdate1 = ParseDate(\@ARGV);
201 unless (UnixDate($userdate1, "%s")) 202 unless (UnixDate($userdate1, "%s"))
202 { 203 {
203 print color 'bold red'; 204 print color 'bold red';
204 print "!!! Error:", " invalid date format (try mm/dd/yyyy)"; 205 print "!!! Error:", " invalid date format (try mm/dd/yyyy)";
205 print color 'reset'; 206 print color 'reset';
206 print "\n"; 207 print "\n";
207 exit -1; 208 exit -1;
208 } 209 }
209 if ((UnixDate($userdate1, "%s") <=> time) <= 0) 210 if ((UnixDate($userdate1, "%s") <=> time) <= 0)
210 { 211 {
211 $searchdate1 = UnixDate($userdate1, "%s"); 212 $searchdate1 = UnixDate($userdate1, "%s");
212 $searchdate2 = time; 213 $searchdate2 = time;
213 } 214 }
214 else 215 else
215 { 216 {
216 die "Date $userdate1 is in the future, not good\n"; 217 die "Date $userdate1 is in the future, not good\n";
217 } 218 }
218 } 219 }
219 elsif (!$userdate2) 220 elsif (!$userdate2)
220 { 221 {
221 $userdate2 = ParseDate(\@ARGV); 222 $userdate2 = ParseDate(\@ARGV);
222 unless (UnixDate($userdate2, "%s")) 223 unless (UnixDate($userdate2, "%s"))
223 { 224 {
224 print color 'bold red'; 225 print color 'bold red';
225 print "!!! Error:", " invalid date format (try mm/dd/yyyy)"; 226 print "!!! Error:", " invalid date format (try mm/dd/yyyy)";
226 print color 'reset'; 227 print color 'reset';
227 print "\n"; 228 print "\n";
228 exit -1; 229 exit -1;
229 } 230 }
230 if ((UnixDate($userdate1, "%s") <=> UnixDate($userdate2, "%s")) <= 0) 231 if ((UnixDate($userdate1, "%s") <=> UnixDate($userdate2, "%s")) <= 0)
231 { 232 {
232 $searchdate2 = UnixDate($userdate2, "%s"); 233 $searchdate2 = UnixDate($userdate2, "%s");
233 } 234 }
234 else 235 else
235 { 236 {
236 $searchdate2 = $searchdate1; 237 $searchdate2 = $searchdate1;
237 $searchdate1 = UnixDate($userdate2, "%s"); 238 $searchdate1 = UnixDate($userdate2, "%s");
238 } 239 }
239 } 240 }
240 else 241 else
241 { 242 {
242 print "too many --date arguments ?\n"; 243 print "too many --date arguments ?\n";
243 die; 244 die;
244 } 245 }
245 last LSWITCH; 246 last LSWITCH;
246 } 247 }
247 $nexist = $arg; 248 $nexist = $arg;
248 } # END LSWITCH 249 } # END LSWITCH
249 if ($nexist) 250 if ($nexist)
250 { 251 {
251 252
252 # This is the standard error message 253 # This is the standard error message
253 print color 'bold red'; 254 print color 'bold red';
254 print "!!! Error: $nexist, invalid option."; 255 print "!!! Error: $nexist, invalid option.";
255 print color 'reset'; 256 print color 'reset';
256 print "\n"; 257 print "\n";
257 exit -1; 258 exit -1;
258 } 259 }
259 return 0; 260 return 0;
260 } 261 }
261 262
262 # short bsd-style options 263 # short bsd-style options
263 if ($arg =~ /^-.*/) 264 if ($arg =~ /^-.*/)
264 { 265 {
265 until ($arg eq "-") 266 until ($arg eq "-")
266 { 267 {
267 my $opt = chop($arg); 268 my $opt = chop($arg);
268 SSWITCH: 269 SSWITCH:
269 { 270 {
270 $help_found = 1, last SSWITCH if ($opt eq "h"); 271 $help_found = 1, last SSWITCH if ($opt eq "h");
271 $help_found = 1, last SSWITCH if ($opt eq "?"); 272 $help_found = 1, last SSWITCH if ($opt eq "?");
272 $time_found = 1, last SSWITCH if ($opt eq "t"); 273 $time_found = 1, last SSWITCH if ($opt eq "t");
273 $unmerge_found = 1, last SSWITCH if ($opt eq "u"); 274 $unmerge_found = 1, last SSWITCH if ($opt eq "u");
274 $ENV{'ANSI_COLORS_DISABLED'} = 1, last SSWITCH if ($opt eq "n"); 275 $ENV{'ANSI_COLORS_DISABLED'} = 1, last SSWITCH if ($opt eq "n");
275 $list_found = 1, last SSWITCH if ($opt eq "l"); 276 $list_found = 1, last SSWITCH if ($opt eq "l");
276 $search_found = 1, last SSWITCH if ($opt eq "s"); 277 $search_found = 1, last SSWITCH if ($opt eq "s");
277 $version_found = 1, last SSWITCH if ($opt eq "v"); 278 $version_found = 1, last SSWITCH if ($opt eq "v");
278 $info_found = 1, last SSWITCH if ($opt eq "i"); 279 $info_found = 1, last SSWITCH if ($opt eq "i");
279 $online_query = 1, last SSWITCH if ($opt eq "q"); 280 $online_query = 1, last SSWITCH if ($opt eq "q");
280 $ssearch_found = 1, last SSWITCH if ($opt eq "S"); 281 $ssearch_found = 1, last SSWITCH if ($opt eq "S");
281 $current_found = 1, last SSWITCH if ($opt eq "c"); 282 $current_found = 1, last SSWITCH if ($opt eq "c");
282 $pretend_found = 1, last SSWITCH if ($opt eq "p"); 283 $pretend_found = 1, last SSWITCH if ($opt eq "p");
283 $rsync_found = 1, last SSWITCH if ($opt eq "r"); 284 $rsync_found = 1, last SSWITCH if ($opt eq "r");
284 $gmt_found = 1, last SSWITCH if ($opt eq "g"); 285 $gmt_found = 1, last SSWITCH if ($opt eq "g");
285 $ebuild_found = 1, last SSWITCH if ($opt eq "e"); 286 $ebuild_found = 1, last SSWITCH if ($opt eq "e");
286 287
287 if ($opt eq "f") 288 if ($opt eq "f")
288 { 289 {
289 if (!$ARGV[0]) 290 if (!$ARGV[0])
290 { 291 {
291 print color 'bold red'; 292 print color 'bold red';
292 print "!!! Error: no logfile specified."; 293 print "!!! Error: no logfile specified.";
293 print color 'reset'; 294 print color 'reset';
294 print "\n"; 295 print "\n";
295 exit -1; 296 exit -1;
296 } 297 }
297 if (!-r $ARGV[0]) 298 if (!-r $ARGV[0])
298 { 299 {
299 print color 'bold red'; 300 print color 'bold red';
300 print "!!! Error: logfile " . $ARGV[0] . " not readable ", "or not found."; 301 print "!!! Error: logfile " . $ARGV[0]
301 print color 'reset'; 302 . " not readable ", "or not found.";
302 print "\n"; 303 print color 'reset';
303 exit -1; 304 print "\n";
304 } 305 exit -1;
306 }
305 print "using logfile " . $ARGV[0] . "\n"; 307 print "using logfile " . $ARGV[0] . "\n";
306 if (!$file_found) 308 if (!$file_found)
307 { 309 {
308 $logfiles[0] = shift @ARGV; 310 $logfiles[0] = shift @ARGV;
309 $file_found = 1; 311 $file_found = 1;
310 } 312 }
311 else 313 else
312 { 314 {
313 push @logfiles, shift(@ARGV); 315 push @logfiles, shift(@ARGV);
314 } 316 }
315 last SSWITCH; 317 last SSWITCH;
316 } 318 }
317 $nexist = $opt; 319 $nexist = $opt;
318 } # END SSWITCH 320 } # END SSWITCH
319 } 321 }
320 if ($nexist) 322 if ($nexist)
321 { 323 {
322 print color 'bold red'; 324 print color 'bold red';
323 print "!!! Error: \-$nexist, invalid option."; 325 print "!!! Error: \-$nexist, invalid option.";
324 print color 'reset'; 326 print color 'reset';
325 print "\n"; 327 print "\n";
326 exit -1; 328 exit -1;
327 } 329 }
328 return 0; 330 return 0;
329 } 331 }
330 push @targets, $arg; 332 push @targets, $arg;
331 return 0; 333 return 0;
332} 334}
333 335
334# provides help information 336# provides help information
335sub help () 337sub help ()
336{ 338{
337 print "Usage: ", colored("genlop ", $COLORS{'blue'}), "[", colored("options", $COLORS{'green'}), "] [", colored("-f ", $COLORS{'green'}), "logfile] [", 339 my $genlop = colored("genlop ", $COLORS{'blue'});
338 colored("category/package", $COLORS{'green'}), "]\n\n", colored("Options:\n", $COLORS{'green'}), colored(" -c ", $COLORS{'green'}), 340 my $options = colored("options", $COLORS{'green'});
339 "display the currently compiling packages (if any)\n", colored(" -e ", $COLORS{'green'}) . "display package history; default if any option is used.\n", 341 my $f = colored("-f", $COLORS{'green'});
342 my $catpkg = colored("category/package", $COLORS{'green'});
343 my $Options = colored("Options:", $COLORS{'green'});
344 my $dateStr = colored("--date", $COLORS{'green'});
345
346 my $help =<<HELP;
347Usage: $genlop [$options] [$f logfile] [$catpkg]
348
349$Options
350
351 -c display the currently compiling packages (if any)
352 -e display package history; default if any option is used.
340 colored(" -f ", $COLORS{'green'}), "read emerge log information from \"logfile\" instead of ", $logfiles[0], "\n", 353 -f read emerge log information from "logfile" instead of "$logfiles[0]"
341 colored(" -h ", $COLORS{'green'}), "print this help\n", colored(" -i ", $COLORS{'green'}), 354 -h print this help
342 "extra infos for the selected package (build specific USE ", "and CFLAGS\n variables, average build time, etc)\n", 355 -i extra infos for the selected package (build specific USE and CFLAGS
343 colored(" -g ", $COLORS{'green'}), "display GMT/UTC, not localized time.\n", colored(" -l ", $COLORS{'green'}), "show full merge history.\n", 356 variables, average build time, etc)
344 colored(" -n ", $COLORS{'green'}), "no color in output\n", colored(" -p ", $COLORS{'green'}), 357 -g display GMT/UTC, not localized time.
345 "estimate build time from a piped \"emerge -p\" output\n", colored(" -q ", $COLORS{'green'}), 358 -l show full merge history.
346 "query gentoo.linuxhowtos.org database if no local emerge was found\n", colored(" -r ", $COLORS{'green'}), 359 -n no color in output
347 "search for portage tree sync/rsync history.\n", colored(" -s ", $COLORS{'green'}), 360 -p estimate build time from a piped "emerge -p" output
348 "use (case insensitive) regular expressions to match package names\n", colored(" -S ", $COLORS{'green'}), 361 -q query gentoo.linuxhowtos.org database if no local emerge was found
349 "use case sensitive regular expressions to match package names\n", colored(" -t ", $COLORS{'green'}), 362 -r search for portage tree sync/rsync history.
350 "calculate merge time for the specific package(s).\n", colored(" -u ", $COLORS{'green'}), "show when packages have been unmerged.\n", 363 -s use (case insensitive) regular expressions to match package names
351 colored(" -v ", $COLORS{'green'}), "display genlop version and exit.\n\n", colored(" --date datestring1", $COLORS{'green'}), " [", 364 -S use case sensitive regular expressions to match package names
352 colored(" --date datestring2", $COLORS{'green'}), "] only shows results between datestring1\n", 365 -t calculate merge time for the specific package(s).
353 " and datestring2. datestring2 dafaults to \"now\" if not", " explicitly set.\n", " (e.g. genlop --list --date 3 days ago)\n", 366 -u show when packages have been unmerged.
354 "\nThis program is licensed under the GPL v2. See COPYING.\n", "For further info about genlop please read the man page.\n"; 367 -v display genlop version and exit.
355 exit 0; 368
369 $dateStr datestring1 [$dateStr datestring2] only shows results between
370 datestring1 and datestring2.
371 datestring2 defaults to "now" if not explicitly set.
372 (e.g. genlop --list --date 3 days ago) shows packages emerged since this
373 time three days ago.
374
375This program is licensed under the GPL v2. See COPYING.
376For further info about genlop please read the man page.
377HELP
378
379 # Color each option green
380 $help =~ s/^ (-.)/" " . &colored($1, $COLORS{'green'})/gme;
381
382 print $help;
383 exit 0
356} 384}
357 385
358sub gtime($) 386sub gtime($)
359{ 387{
360 my $gtime = $_[0]; 388 my $gtime = $_[0];
361 chomp($gtime); 389 chomp($gtime);
362 $secs = $gtime % 60; 390 $secs = $gtime % 60;
363 $gtime = ($gtime - $secs) / 60; 391 $gtime = ($gtime - $secs) / 60;
364 $mins = $gtime % 60; 392 $mins = $gtime % 60;
365 $gtime = ($gtime - $mins) / 60; 393 $gtime = ($gtime - $mins) / 60;
366 $hours = $gtime % 24; 394 $hours = $gtime % 24;
367 $gtime = ($gtime - $hours) / 24; 395 $gtime = ($gtime - $hours) / 24;
368 $days = $gtime % 7; 396 $days = $gtime % 7;
369 if ($gtime < 0) 397 if ($gtime < 0)
370 { 398 {
371 $gtime = 0; 399 $gtime = 0;
372 } 400 }
373} 401}
374 402
375sub print_gtime() 403sub print_gtime()
376{ 404{
377 if ($days > 0) 405 if ($days > 0)
378 { 406 {
379 print colored("$days", $COLORS{'green'}), " day"; 407 print colored("$days", $COLORS{'green'}), " day";
380 print "s" if ($days > 1); 408 print "s" if ($days > 1);
381 } 409 }
382 if ($hours > 0) 410 if ($hours > 0)
383 { 411 {
384 print ", " if ($days > 0); 412 print ", " if ($days > 0);
385 print colored("$hours", $COLORS{'green'}), " hour"; 413 print colored("$hours", $COLORS{'green'}), " hour";
386 print "s" if ($hours > 1); 414 print "s" if ($hours > 1);
387 } 415 }
388 if ($mins > 0) 416 if ($mins > 0)
389 { 417 {
390 print ", " if ($days > 0 or $hours > 0); 418 print ", " if ($days > 0 or $hours > 0);
391 print colored("$mins", $COLORS{'green'}), " minute"; 419 print colored("$mins", $COLORS{'green'}), " minute";
392 print "s" if ($mins > 1); 420 print "s" if ($mins > 1);
393 } 421 }
394 if ($mins < 1 && $hours < 1 && $days < 1 && $secs > 0 && $current_found) 422 if ($mins < 1 && $hours < 1 && $days < 1 && $secs > 0 && $current_found)
395 { 423 {
396 print colored("less than a minute", $COLORS{'green'}); 424 print colored("less than a minute", $COLORS{'green'});
397 } 425 }
398 elsif ($mins < 1 && $hours < 1 && $days < 1 && $secs > 0 && $pretend_found) 426 elsif ($mins < 1 && $hours < 1 && $days < 1 && $secs > 0 && $pretend_found)
399 { 427 {
400 print colored("less than a minute", $COLORS{'green'}); 428 print colored("less than a minute", $COLORS{'green'});
401 } 429 }
402 elsif ($secs > 0 && !$pretend_found) 430 elsif ($secs > 0 && !$pretend_found)
403 { 431 {
404 print " and " if ($days > 0 or $hours > 0 or $mins > 0); 432 print " and " if ($days > 0 or $hours > 0 or $mins > 0);
405 print colored("$secs", $COLORS{'green'}), " second"; 433 print colored("$secs", $COLORS{'green'}), " second";
406 print "s" if ($secs > 1); 434 print "s" if ($secs > 1);
407 } 435 }
408 print "."; 436 print ".";
409} 437}
410 438
411sub gen_regexp ($) 439sub gen_regexp ($)
412{ 440{
413
414 # generates the correct regexp depending on what the user asked us. 441 # generates the correct regexp depending on what the user asked us.
415 # default is to search only the correct package name (eg. mozilla) 442 # default is to search only the correct package name (eg. mozilla)
416 # a different regexp is needed in the following cases: 443 # a different regexp is needed in the following cases:
417 # argument is in the form category/ 444 # argument is in the form category/
418 # argument is in the form category/ebuild 445 # argument is in the form category/ebuild
419 # argument is in the form category/ebuild-version 446 # argument is in the form category/ebuild-version
420 # the user can provide his own regular expression(s) via the -s option 447 # the user can provide his own regular expression(s) via the -s option
421 my $arg = $_[0]; 448 my $arg = $_[0];
422 my ($category, $ebuild, $version); 449 my ($category, $ebuild, $version);
423 my $regexp; 450 my $regexp;
424 my @list; 451 my @list;
425 452
426 if ($list_found) 453 if ($list_found)
427 { 454 {
428 if ($arg =~ m{^=}) 455 if ($arg =~ m{^=})
429 { 456 {
430 $arg =~ s{^=}{}; 457 $arg =~ s{^=}{};
431 $regexp = qr/(.*$arg).*?/; 458 $regexp = qr/(.*$arg).*?/;
432 } 459 }
433 else 460 else
434 { 461 {
435 $regexp = qr/(.*)(-[0-9]{1,7}.*?)/i; 462 $regexp = qr/(.*)(-[0-9]{1,7}.*?)/i;
436 } 463 }
437 return "$regexp"; 464 return "$regexp";
438 } 465 }
439 if ($search_found) 466 if ($search_found)
440 { 467 {
441 468
442 # return user supplied regexp as-is 469 # return user supplied regexp as-is
443 if ($arg =~ m{^=}) 470 if ($arg =~ m{^=})
444 { 471 {
445 $arg =~ s{^=}{}; 472 $arg =~ s{^=}{};
446 $regexp = 473 $regexp =
447 $ssearch_found 474 $ssearch_found
448 ? qr/(.*$arg)(.*?)/ 475 ? qr/(.*$arg)(.*?)/
449 : qr/(.*$arg)(.*?)/i; 476 : qr/(.*$arg)(.*?)/i;
450 } 477 }
451 else 478 else
452 { 479 {
453 $regexp = 480 $regexp =
454 $ssearch_found 481 $ssearch_found
455 ? qr/(.*$arg.*?)(-[0-9]{1,7}.*?)/ 482 ? qr/(.*$arg.*?)(-[0-9]{1,7}.*?)/
456 : qr/(.*$arg.*?)(-[0-9]{1,7}.*?)/i; 483 : qr/(.*$arg.*?)(-[0-9]{1,7}.*?)/i;
457 } 484 }
458 return "$regexp"; 485 return "$regexp";
459 } 486 }
460 487
461 # check if we were asked only the category 488 # check if we were asked only the category
462 if ($arg =~ /.*?\/$/) 489 if ($arg =~ /.*?\/$/)
463 { 490 {
464 $category = $arg; 491 $category = $arg;
465 $regexp = 492 $regexp =
466 $ssearch_found 493 $ssearch_found
467 ? qr/($category.*?)(-[0-9]{1,7}.*?)/ 494 ? qr/($category.*?)(-[0-9]{1,7}.*?)/
468 : qr/($category.*?)(-[0-9]{1,7}.*?)/i; 495 : qr/($category.*?)(-[0-9]{1,7}.*?)/i;
469 return "$regexp"; 496 return "$regexp";
470 } 497 }
471 @list = split(/\//, $arg); 498 @list = split(/\//, $arg);
472 $ebuild = $list[0]; 499 $ebuild = $list[0];
473 if ($list[1]) 500 if ($list[1])
474 { 501 {
475 $category = $list[0]; 502 $category = $list[0];
476 $ebuild = $list[1]; 503 $ebuild = $list[1];
477 @list = (); 504 @list = ();
478 @list = split(/(-[0-9]{1,7})/, $ebuild); 505 @list = split(/(-[0-9]{1,7})/, $ebuild);
479 if ($list[1]) 506 if ($list[1])
480 { 507 {
481 $ebuild = $list[0]; 508 $ebuild = $list[0];
482 $version = $list[2] ? join('', $list[1], $list[2]) : $list[1]; 509 $version = $list[2] ? join('', $list[1], $list[2]) : $list[1];
483 $category =~ s{^=}{}; 510 $category =~ s{^=}{};
484 $regexp = 511 $regexp =
485 $ssearch_found 512 $ssearch_found
486 ? qr!($category\/$ebuild)($version)! 513 ? qr!($category\/$ebuild)($version)!
487 : qr!($category\/$ebuild)($version)!i; 514 : qr!($category\/$ebuild)($version)!i;
488 return "$regexp"; 515 return "$regexp";
489 } 516 }
490 $regexp = 517 $regexp =
491 $ssearch_found 518 $ssearch_found
492 ? qr!($category\/$ebuild)(-[0-9]{1,7}.*?)! 519 ? qr!($category\/$ebuild)(-[0-9]{1,7}.*?)!
493 : qr!($category\/$ebuild)(-[0-9]{1,7}.*?)!i; 520 : qr!($category\/$ebuild)(-[0-9]{1,7}.*?)!i;
494 return "$regexp"; 521 return "$regexp";
495 } 522 }
496 $regexp = 523 $regexp =
497 $ssearch_found 524 $ssearch_found
498 ? qr!(.*?/$ebuild)(-[0-9]{1,7}.*?)! 525 ? qr!(.*?/$ebuild)(-[0-9]{1,7}.*?)!
499 : qr!(.*?/$ebuild)(-[0-9]{1,7}.*?)!i; 526 : qr!(.*?/$ebuild)(-[0-9]{1,7}.*?)!i;
500 return "$regexp"; 527 return "$regexp";
501} 528}
502 529
503# Submitted in bug 157103 by sascha to enable searching against linuxhowtos for compile 530# Submitted in bug 157103 by sascha to enable searching against linuxhowtos for compile
504# times when genlop has no data to work with 531# times when genlop has no data to work with
505sub lhtoquery($$) 532sub lhtoquery($$)
506{ 533{
507 my ( $vcpu, $pcpu, $opcpu ) = (0,0,-1); 534 my ( $vcpu, $pcpu, $opcpu ) = (0,0,-1);
508 my $modelname = ""; 535 my $modelname = "";
509 my $cachesize; 536 my $cachesize;
510 my $packet = shift(@_); 537 my $packet = shift(@_);
511 my $countref = shift(@_); 538 my $countref = shift(@_);
512 open(my $cmdline, "/proc/cpuinfo"); 539 open(my $cmdline, "/proc/cpuinfo");
513 while (<$cmdline>) 540 while (<$cmdline>)
514 { 541 {
515 if (m/processor\s*:\s*(\d*)/) 542 if (m/processor\s*:\s*(\d*)/)
516 { 543 {
517 $vcpu = $1 if ($1 > $vcpu); 544 $vcpu = $1 if ($1 > $vcpu);
518 } 545 }
519 if (m/model name\s*:\s*(.*)$/) 546 if (m/model name\s*:\s*(.*)$/)
520 { 547 {
521 $modelname = $1; 548 $modelname = $1;
522 } 549 }
523 if (m/cache size\s*:\s*(.*)$/) 550 if (m/cache size\s*:\s*(.*)$/)
524 { 551 {
525 $cachesize = $1; 552 $cachesize = $1;
526 } 553 }
527 if (m/physical id\s*:\s*(\d*)$/) 554 if (m/physical id\s*:\s*(\d*)$/)
528 { 555 {
529 $pcpu++ if ($1 != $opcpu); 556 $pcpu++ if ($1 != $opcpu);
530 $opcpu = $1; 557 $opcpu = $1;
531 } 558 }
532 } 559 }
533 $vcpu++; 560 $vcpu++;
534 $pcpu = 1 if ($pcpu == 0); 561 $pcpu = 1 if ($pcpu == 0);
535 my $cpuname = $pcpu . "x $modelname $cachesize"; 562 my $cpuname = $pcpu . "x $modelname $cachesize";
536 $cpuname =~ s/ /%20/g; 563 $cpuname =~ s/ /%20/g;
537 my $retval = LWP::Simple::get("http://gentoo.linuxhowtos.org/query.php?cpuname=$cpuname&vcpu=$vcpu&packetname=$packet"); 564 my $retval = LWP::Simple::get("http://gentoo.linuxhowtos.org/query.php?cpuname=$cpuname&vcpu=$vcpu&packetname=$packet");
538 if ($retval =~ m/estimate: (\d*) seconds/) 565 if ($retval =~ m/estimate: (\d*) seconds/)
539 { 566 {
540 $$countref = 1; 567 $$countref = 1;
541 return $1; 568 return $1;
542 } 569 }
543 if ($retval =~ /unknown cpu/) 570 if ($retval =~ /unknown cpu/)
544 { 571 {
545 $lhtomsg = "Your CPU is not yet known, please add it by following the instructions on http://gentoo.linuxhowtos.org/compiletimeestimator/"; 572 $lhtomsg = "Your CPU is not yet known, please add it by following the instructions on http://gentoo.linuxhowtos.org/compiletimeestimator/";
546 } 573 }
547 return 0; 574 return 0;
548} 575}
549 576
550# --pretend or -p takes an emerge -p `-e -D world, system`, anything you want 577# --pretend or -p takes an emerge -p `-e -D world, system`, anything you want
551# and elaborates its output. for each package is calculated the average build 578# and elaborates its output. for each package is calculated the average build
552# time and summed together. this is the estimated merge time 579# time and summed together. this is the estimated merge time
553sub pretend() 580sub pretend()
554{ 581{
555 if ($pretend_found) 582 if ($pretend_found)
556 { 583 {
557 @targets = (); 584 @targets = ();
558 print "These are the pretended packages:"; 585 print "These are the pretended packages:";
559 print " (this may take a while; wait...)\n\n"; 586 print " (this may take a while; wait...)\n\n";
560 587
561 # open STDIN; that's why emerge -p foo is piped to a genlop -p 588 # open STDIN; that's why emerge -p foo is piped to a genlop -p
562 while (<STDIN>) 589 while (<STDIN>)
563 { 590 {
564 if ($_ =~ m/^\[e.*\] (.*?)\/(.*?)(\-[0-9])/) 591 if ($_ =~ m/^\[e.*\] (.*?)\/(.*?)(\-[0-9])/)
565 { 592 {
566 push @targets, $2; 593 push @targets, $2;
567 print; 594 print;
568 } 595 }
569 } 596 }
570 my $last_ebuild; 597 my $last_ebuild;
571 foreach my $ebuild_arg (@targets) 598 foreach my $ebuild_arg (@targets)
572 { 599 {
573 600
574 # we track the last ebuild processed with $last_ebuild variable 601 # we track the last ebuild processed with $last_ebuild variable
575 $last_ebuild = $ebuild_arg; 602 $last_ebuild = $ebuild_arg;
576 $ebuild_arg =~ s/(\+)/\\$1/g; 603 $ebuild_arg =~ s/(\+)/\\$1/g;
577 foreach my $logfile (@logfiles) 604 foreach my $logfile (@logfiles)
578 { 605 {
579 my $handle; 606 my $handle;
580 open_file($logfile, \$handle); 607 open_file($logfile, \$handle);
581 foreach (<$handle>) 608 foreach (<$handle>)
582 { 609 {
583 if (m/^(.*?)\: \>\>\> emerge.*?\/$ebuild_arg-[0-9].*/) 610 if (m/^(.*?)\: \>\>\> emerge.*?\/$ebuild_arg-[0-9].*/)
584 { 611 {
585 $e_start = $1; 612 $e_start = $1;
586 } 613 }
587 if (m/^(.*?)\: ::: completed .*?\) .*\/$ebuild_arg-[0-9].* to \//) 614 if (m/^(.*?)\: ::: completed .*?\) .*\/$ebuild_arg-[0-9].* to \//)
588 { 615 {
589 $e_end = $1; 616 $e_end = $1;
590 $tm_secondi += ($e_end - $e_start); 617 $tm_secondi += ($e_end - $e_start);
591 $e_count++; 618 $e_count++;
592 } 619 }
593 } 620 }
594 } 621 }
595 if ($e_count == 0) 622 if ($e_count == 0)
596 { 623 {
597 if ($online_query) 624 if ($online_query)
598 { 625 {
599 626 #query gentoo.linuxhowtos.org
600 #query gentoo.linuxhowtos.org
601 $tm_secondi += lhtoquery($last_ebuild, \$e_count); 627 $tm_secondi += lhtoquery($last_ebuild, \$e_count);
602 } 628 }
603 } 629 }
604 if ($e_count == 0) 630 if ($e_count == 0)
605 { 631 {
606 $ebuild_arg =~ s/\\//g; 632 $ebuild_arg =~ s/\\//g;
607 print "\n!!! Error: couldn't get previous ", "merge of $ebuild_arg; skipping..."; 633 print "\n!!! Error: couldn't get previous ", "merge of $ebuild_arg; skipping...";
608 634
609 # if a pretended package haven't any successfull merge 635 # if a pretended package haven't any successfull merge
610 # stored in logfile (ie a new package required by 636 # stored in logfile (ie a new package required by
611 # another, or a logfile corruption), prints a warning 637 # another, or a logfile corruption), prints a warning
612 # and keep track with $last_skipped 638 # and keep track with $last_skipped
613 $last_skipped = $ebuild_arg; 639 $last_skipped = $ebuild_arg;
614 } 640 }
615 else 641 else
616 { 642 {
617 $m_secondi += $tm_secondi / ($e_count); 643 $m_secondi += $tm_secondi / ($e_count);
618 $e_count = 0; 644 $e_count = 0;
619 $tm_secondi = 0; 645 $tm_secondi = 0;
620 $last_skipped = "none-skipped"; 646 $last_skipped = "none-skipped";
621 } 647 }
622 } 648 }
623 if (@targets) 649 if (@targets)
624 { 650 {
625 if ($last_ebuild =~ m/$last_skipped/) 651 if ($last_ebuild =~ m/$last_skipped/)
626 { 652 {
627 print color 'bold red'; 653 print color 'bold red';
628 print "\n!!! Error: $last_skipped never merged; ", "estimated time unknown."; 654 print "\n!!! Error: $last_skipped never merged; ", "estimated time unknown.";
629 print color 'reset'; 655 print color 'reset';
630 print "\n"; 656 print "\n";
631 if ($lhtomsg) 657 if ($lhtomsg)
632 { 658 {
633 print color 'bold yellow'; 659 print color 'bold yellow';
634 print "$lhtomsg\n"; 660 print "$lhtomsg\n";
635 print color 'reset'; 661 print color 'reset';
636 } 662 }
637 exit; 663 exit;
638 } 664 }
639 print "\n\nEstimated update time: "; 665 print "\n\nEstimated update time: ";
640 &gtime($m_secondi); 666 &gtime($m_secondi);
641 &print_gtime; 667 &print_gtime;
642 print "\n"; 668 print "\n";
643 } 669 }
644 else 670 else
645 { 671 {
646 print color 'bold red'; 672 print color 'bold red';
647 print "\n!!! Error: no pretended packages found."; 673 print "\n!!! Error: no pretended packages found.";
648 print color 'reset'; 674 print color 'reset';
649 print "\n"; 675 print "\n";
650 } 676 }
651 exit; 677 exit;
652 } 678 }
653} 679}
654 680
655sub current() 681sub current()
656{ 682{
657
658 # support for 'current' merge. 683 # support for 'current' merge.
659 # 684 #
660 # this whole 'current' thing is based on having sandboxind enabled 685 # this whole 'current' thing is based on having sandboxind enabled
661 # we need to check for it, basically sandboxing is on if 686 # we need to check for it, basically sandboxing is on if
662 # FEATURES contains 'sandbox' and does not contain 'userpriv' 687 # FEATURES contains 'sandbox' and does not contain 'userpriv'
663 # FEATURES contains 'sandbox' and contains both 'userpriv' and 'usersandbox' 688 # FEATURES contains 'sandbox' and contains both 'userpriv' and 'usersandbox'
664 # 20050815 - JeR: On slow systems, running portageq takes a lot of time, 689 # 20050815 - JeR: On slow systems, running portageq takes a lot of time,
665 # sometimes enough to miss all the sandbox action completely. Better to 690 # sometimes enough to miss all the sandbox action completely. Better to
666 # not check for sanity and have users check their FEATURES instead. 691 # not check for sanity and have users check their FEATURES instead.
667 my @targets = (); 692 my @targets = ();
668 my @sandbox_pids = (); 693 my @sandbox_pids = ();
669 my @sandbox_procs = qx{ps ax -o pid,args | tail -n +2 | sed -e's/^ *//' | grep ' sandbox ' | grep -v ' grep '}; 694 my @sandbox_procs = qx{ps ax -o pid,args | tail -n +2 | sed -e's/^ *//' | grep ' sandbox ' | grep -v ' grep '};
670 my ($e_curmerge, $e_lastmerge); 695 my ($e_curmerge, $e_lastmerge);
671 foreach (@sandbox_procs) 696 foreach (@sandbox_procs)
672 { 697 {
673 if (m/^(.*?) \[(.*?)\-[0-9].*?\]/) 698 if (m/^(.*?) \[(.*?)\-[0-9].*?\]/)
674 { 699 {
675 push @sandbox_pids, $1; 700 push @sandbox_pids, $1;
676 push @targets, $2; 701 push @targets, $2;
677 } 702 }
678 } 703 }
679 if (scalar @sandbox_pids == 0) 704 if (scalar @sandbox_pids == 0)
680 { 705 {
681 print colored("!!!", $COLORS{'red'}); 706 print colored("!!!", $COLORS{'red'});
682 print " Error: no working merge found.\n"; 707 print " Error: no working merge found.\n";
683 print "(the -c option only works if there is" . " an ongoing compilation, see manpage)\n"; 708 print "(the -c option only works if there is" . " an ongoing compilation, see manpage)\n";
684 exit; 709 exit;
685 } 710 }
686 if (scalar @targets == 0) 711 if (scalar @targets == 0)
687 { 712 {
688 print colored("!!!", $COLORS{'red'}); 713 print colored("!!!", $COLORS{'red'});
689 print "oops! should not happen, pease file bug\n"; 714 print "oops! should not happen, pease file bug\n";
690 print "empty \@targets\n"; 715 print "empty \@targets\n";
691 exit 1; 716 exit 1;
692 } 717 }
693 foreach my $ebuild_arg (@targets) 718 foreach my $ebuild_arg (@targets)
694 { 719 {
695 my $e_current; 720 my $e_current;
696 $ebuild_arg =~ s/(\+)/\\$1/g; 721 $ebuild_arg =~ s/(\+)/\\$1/g;
697 foreach my $logfile (@logfiles) 722 foreach my $logfile (@logfiles)
698 { 723 {
699 my $handle; 724 my $handle;
700 open_file($logfile, \$handle); 725 open_file($logfile, \$handle);
701 foreach (<$handle>) 726 foreach (<$handle>)
702 { 727 {
703 if (m/^(.*?)\: \>\>\> emerge \((.*?) of (.*?)\)(.*?\/$ebuild_arg-[0-9].*?)to \//) 728 if (m/^(.*?)\: \>\>\> emerge \((.*?) of (.*?)\)(.*?\/$ebuild_arg-[0-9].*?)to \//)
704 { 729 {
705 $e_start = $1; 730 $e_start = $1;
706 $e_curmerge = $2; 731 $e_curmerge = $2;
707 $e_lastmerge = $3; 732 $e_lastmerge = $3;
708 $e_current = $4; 733 $e_current = $4;
709 } 734 }
710 if (m/^(.*?)\: ::: completed .*?\) .*\/$ebuild_arg-[0-9].* to \//) 735 if (m/^(.*?)\: ::: completed .*?\) .*\/$ebuild_arg-[0-9].* to \//)
711 { 736 {
712 $e_end = $1; 737 $e_end = $1;
713 $e_count++; 738 $e_count++;
714 &gtime($e_end - $e_start); 739 &gtime($e_end - $e_start);
715 $tm_secondi += ($e_end - $e_start); 740 $tm_secondi += ($e_end - $e_start);
716 } 741 }
717 } 742 }
718 } 743 }
719 $e_end = CORE::time(); 744 $e_end = CORE::time();
720 &gtime($e_end - $e_start); 745 &gtime($e_end - $e_start);
721 print "\n Currently merging $e_curmerge out of $e_lastmerge\n"; 746 print "\n Currently merging $e_curmerge out of $e_lastmerge\n";
722 print colored("\n \*$e_current\n\n", $COLORS{'blue'}); 747 print colored("\n \*$e_current\n\n", $COLORS{'blue'});
723 print " current merge time: "; 748 print " current merge time: ";
724 $current_found = undef; 749 $current_found = undef;
725 &print_gtime(); 750 &print_gtime();
726 $current_found = 1; 751 $current_found = 1;
727 print "\n"; 752 print "\n";
728 print " ETA: "; 753 print " ETA: ";
729 754
730 if (!$e_count && $online_query) 755 if (!$e_count && $online_query)
731 { 756 {
732 757
733 #query gentoo.linuxhowtos.org 758 #query gentoo.linuxhowtos.org
734 $tm_secondi = lhtoquery($ebuild_arg, \$e_count); 759 $tm_secondi = lhtoquery($ebuild_arg, \$e_count);
735 $e_count = 1; 760 $e_count = 1;
736 } 761 }
737 762
738 if ($e_count && $e_start) 763 if ($e_count && $e_start)
739 { 764 {
740 &gtime(($tm_secondi / $e_count) - ($e_end - $e_start)); 765 &gtime(($tm_secondi / $e_count) - ($e_end - $e_start));
741 if (($e_end - $e_start) >= ($tm_secondi / $e_count)) 766 if (($e_end - $e_start) >= ($tm_secondi / $e_count))
742 { 767 {
743 print colored("any time now.\n", $COLORS{'green'}); 768 print colored("any time now.\n", $COLORS{'green'});
744 } 769 }
745 else 770 else
746 { 771 {
747 &print_gtime(); 772 &print_gtime();
748 print "\n"; 773 print "\n";
749 } 774 }
750 } 775 }
751 else 776 else
752 { 777 {
753 print color 'bold red'; 778 print color 'bold red';
754 print "unknown."; 779 print "unknown.";
755 print color 'reset'; 780 print color 'reset';
756 print "\n"; 781 print "\n";
757 } 782 }
758 } 783 }
759 exit; 784 exit;
760} 785}
761 786
762sub info($) 787sub info($)
763{ 788{
764 my $package = $_[0]; 789 my $package = $_[0];
765 if ($list_found) { &help(); } 790 if ($list_found) { &help(); }
766 if ($e_count) { $m_count = $e_count - $w_count; } 791 if ($e_count) { $m_count = $e_count - $w_count; }
767 if ($m_count == 0) 792 if ($m_count == 0)
768 { 793 {
769 print colored("Total merge time unknown.\n\n", $COLORS{'red'}); 794 print colored("Total merge time unknown.\n\n", $COLORS{'red'});
770 } 795 }
771 else 796 else
772 { 797 {
773 print "\n Total builds: ", colored("$e_count", $COLORS{'green'}); 798 print "\n Total builds: ", colored("$e_count", $COLORS{'green'});
774 print "\n Global build time: "; 799 print "\n Global build time: ";
775 &gtime($tm_secondi); 800 &gtime($tm_secondi);
776 &print_gtime(); 801 &print_gtime();
777 if ($w_count) 802 if ($w_count)
778 { 803 {
779 print " Global build time of $m_count merges.\n"; 804 print " Global build time of $m_count merges.\n";
780 } 805 }
781 else 806 else
782 { 807 {
783 print "\n"; 808 print "\n";
784 } 809 }
785 if ($e_count > 1) 810 if ($e_count > 1)
786 { 811 {
787 print " Average merge time: "; 812 print " Average merge time: ";
788 &gtime($tm_secondi / $m_count); 813 &gtime($tm_secondi / $m_count);
789 &print_gtime(); 814 &print_gtime();
790 print "\n"; 815 print "\n";
791 } 816 }
792 $e_count = 0; 817 $e_count = 0;
793 $tm_secondi = 0; 818 $tm_secondi = 0;
794 819
795 #$gtime = 0; 820 #$gtime = 0;
796 } 821 }
797 $e_count = 0; 822 $e_count = 0;
798 print "\n Info about currently installed ebuild:\n"; 823 print "\n Info about currently installed ebuild:\n";
799 opendir(DIR, "/var/db/pkg/") || die "can't open /var/db/pkg/ $!\n"; 824 opendir(DIR, "/var/db/pkg/") || die "can't open /var/db/pkg/ $!\n";
800 while (defined(my $categoria = readdir(DIR))) 825 while (defined(my $categoria = readdir(DIR)))
801 { 826 {
802 if ($package =~ m/^$categoria.*/g) 827 if ($package =~ m/^$categoria.*/g)
803 { 828 {
804 opendir(DIR2, "/var/db/pkg/$categoria"); 829 opendir(DIR2, "/var/db/pkg/$categoria");
805 while (defined(my $package_dir = readdir(DIR2))) 830 while (defined(my $package_dir = readdir(DIR2)))
806 { 831 {
807 832
808 #$package =~ s/(\+)/\\$1/g; 833 #$package =~ s/(\+)/\\$1/g;
809 my $tmp_package = $package; 834 my $tmp_package = $package;
810 $tmp_package =~ s/\+/\\+/g; 835 $tmp_package =~ s/\+/\\+/g;
811 if ("$categoria/$package_dir" =~ m/$tmp_package\-[0-9].*/) 836 if ("$categoria/$package_dir" =~ m/$tmp_package\-[0-9].*/)
812 { 837 {
813 $info_ok = 1; 838 $info_ok = 1;
814 print colored("\n * $categoria/$package_dir\n", $COLORS{'blue'}); 839 print colored("\n * $categoria/$package_dir\n", $COLORS{'blue'});
815 $package_dir =~ s/(\+)/\\$1/g; 840 $package_dir =~ s/(\+)/\\$1/g;
816 841
817 my $e_date; 842 my $e_date;
818 foreach my $logfile (@logfiles) 843 foreach my $logfile (@logfiles)
819 { 844 {
820 my $handle; 845 my $handle;
821 open_file($logfile, \$handle); 846 open_file($logfile, \$handle);
822 foreach (<$handle>) 847 foreach (<$handle>)
823 { 848 {
824 my $pattern = gen_regexp("$categoria/$package_dir"); 849 my $pattern = gen_regexp("$categoria/$package_dir");
825 if (m/^([0-9]{10})\: ::: completed .*?\) $pattern to \//) 850 if (m/^([0-9]{10})\: ::: completed .*?\) $pattern to \//)
826 { 851 {
827 if ($gmt_found) 852 if ($gmt_found)
828 { 853 {
829 $e_date = scalar gmtime "$1"; 854 $e_date = scalar gmtime "$1";
830 } 855 }
831 else 856 else
832 { 857 {
833 $e_date = scalar localtime "$1"; 858 $e_date = scalar localtime "$1";
834 } 859 }
835 } 860 }
836 } 861 }
837 } 862 }
838 print " Install date: "; 863 print " Install date: ";
839 print colored("$e_date\n", $COLORS{'green'}); 864 print colored("$e_date\n", $COLORS{'green'});
840 865
841 # we use 3 array to collect data: before processing they are 866 # we use 3 array to collect data: before processing they are
842 # @unused_use: contain packages' USEs 867 # @unused_use: contain packages' USEs
843 # @pkg_use: USE declared before compiling that package 868 # @pkg_use: USE declared before compiling that package
844 # @used_use: empty 869 # @used_use: empty
845 my (@potential_use, @pkg_use, @used_use, @unused_use); 870 my (@potential_use, @pkg_use, @used_use, @unused_use);
846 871
847 # each installed package store its information here 872 # each installed package store its information here
848 my $db_pkg_dir = "/var/db/pkg/$categoria/$package_dir/"; 873 my $db_pkg_dir = "/var/db/pkg/$categoria/$package_dir/";
849 if ("$categoria/$package_dir" =~ m/.*\/(.*)/g) 874 if ("$categoria/$package_dir" =~ m/.*\/(.*)/g)
850 { 875 {
851 876
852 # we search into the installed ebuild for USE flags available 877 # we search into the installed ebuild for USE flags available
853 # and store them in @potential_use. 878 # and store them in @potential_use.
854 open(pkg_ebuild, "$db_pkg_dir/$1.ebuild") || return; 879 open(pkg_ebuild, "$db_pkg_dir/$1.ebuild") || return;
855 while (<pkg_ebuild>) 880 while (<pkg_ebuild>)
856 { 881 {
857 if ($_ =~ m/^IUSE=\"(\$\{IUSE\} )?(.*)"/g) 882 if ($_ =~ m/^IUSE=\"(\$\{IUSE\} )?(.*)"/g)
858 { 883 {
859 @potential_use = split(/\ /, $2); 884 @potential_use = split(/\ /, $2);
860 } 885 }
861 } 886 }
862 } 887 }
863 888
864 # this file lists every USE flag defined, even ones in make.conf 889 # this file lists every USE flag defined, even ones in make.conf
865 # we push'em in @pkg_use 890 # we push'em in @pkg_use
866 open(pkg_use, "$db_pkg_dir/USE") || return; 891 open(pkg_use, "$db_pkg_dir/USE") || return;
867 while (<pkg_use>) 892 while (<pkg_use>)
868 { 893 {
869 @pkg_use = split(/\ /, $_); 894 @pkg_use = split(/\ /, $_);
870 } 895 }
871 896
872 # for every possible package USE we search into USEs stored in @pkg_use 897 # for every possible package USE we search into USEs stored in @pkg_use
873 # if a match is found we move it from @potential_use in @used_use. 898 # if a match is found we move it from @potential_use in @used_use.
874 # in this way, when every possible package USE are processed, @used_use 899 # in this way, when every possible package USE are processed, @used_use
875 # contain only used ones and @potential_use the not used ones. 900 # contain only used ones and @potential_use the not used ones.
876 USE: foreach my $use (@potential_use) 901 USE: foreach my $use (@potential_use)
877 { 902 {
878 chomp($use); 903 chomp($use);
879 foreach my $pkg (@pkg_use) 904 foreach my $pkg (@pkg_use)
880 { 905 {
881 chomp($pkg); 906 chomp($pkg);
882 if ($use eq $pkg) 907 if ($use eq $pkg)
883 { 908 {
884 push(@used_use, $use); 909 push(@used_use, $use);
885 next USE; 910 next USE;
886 } 911 }
887 } 912 }
888 push(@unused_use, $use); 913 push(@unused_use, $use);
889 } 914 }
890 915
891 # finally we print'em out 916 # finally we print'em out
892 print " USE=\"", colored("@used_use", $COLORS{'red'}); 917 print " USE=\"", colored("@used_use", $COLORS{'red'});
893 foreach my $unused (@unused_use) 918 foreach my $unused (@unused_use)
894 { 919 {
895 print colored(" -$unused", $COLORS{'blue'}); 920 print colored(" -$unused", $COLORS{'blue'});
896 } 921 }
897 print "\"\n"; 922 print "\"\n";
898 923
899 # easy work here: we simply print the CFLAGS file 924 # easy work here: we simply print the CFLAGS file
900 print " CFLAGS=\""; 925 print " CFLAGS=\"";
901 open(pkg_cflag, "$db_pkg_dir/CFLAGS"); 926 open(pkg_cflag, "$db_pkg_dir/CFLAGS");
902 while (<pkg_cflag>) 927 while (<pkg_cflag>)
903 { 928 {
904 chomp(); 929 chomp();
905 print(); 930 print();
906 } 931 }
907 print "\"\n"; 932 print "\"\n";
908 } 933 }
909 } 934 }
910 } 935 }
911 } 936 }
912 if (!$info_ok) { print " none installed.\n"; } 937 if (!$info_ok) { print " none installed.\n"; }
913} 938}
914 939
915sub rsync() { 940sub rsync() {
916 foreach (@logfiles) { 941 foreach (@logfiles) {
917 my $handle; 942 my $handle;
950parse(shift @ARGV) while ($ARGV[0]); 975parse(shift @ARGV) while ($ARGV[0]);
951 976
952help() if ($help_found); 977help() if ($help_found);
953if ($version_found) 978if ($version_found)
954{ 979{
980 print <<VERSION;
955 print "genlop $version, maintained by Michael Cummings <mcummings\@gentoo.org>\n" 981genlop $version, maintained by Michael Cummings <mcummings\@gentoo.org>
956 . "original code by Giorgio Mandolfo and Antonio Dolcetta\n" 982original code by Giorgio Mandolfo and Antonio Dolcetta
983
957 . "Please file any bugs found online at:\n" 984Please file any bugs found online at:
958 . "https://bugs.gentoo.org\n" 985 https://bugs.gentoo.org
986
959 . "Distribuited under the GPL v2. See COPYING for details\n"; 987Distributed under the GPL v2. See COPYING for details
960 exit; 988VERSION
989 exit 0;
961} 990}
962 991
963if ( !$targets[0] 992if ( !$targets[0]
964 and !$list_found 993 and !$list_found
965 and !$current_found 994 and !$current_found
966 and !$pretend_found 995 and !$pretend_found
967 and !$rsync_found) 996 and !$rsync_found)
968{ 997{
969 help(); 998 help();
970} 999}
971 1000
972# FIXME questi a cosa servono ? 1001# FIXME questi a cosa servono ?
973if ($rsync_found) { @targets = (); push @targets, "-r"; } 1002if ($rsync_found) { @targets = (); push @targets, "-r"; }
974if ($list_found) { @targets = (); push @targets, "-l"; } 1003if ($list_found) { @targets = (); push @targets, "-l"; }
977 1006
978# main code... 1007# main code...
979#cache_files(\@logfiles, \@logfile_cache); 1008#cache_files(\@logfiles, \@logfile_cache);
980if (scalar @logfiles > 1) 1009if (scalar @logfiles > 1)
981{ 1010{
982 @logfiles = order_logs(@logfiles); 1011 @logfiles = order_logs(@logfiles);
983} 1012}
984 1013
985# - Option -r given? > 1014# - Option -r given? >
986if ($rsync_found) { 1015if ($rsync_found) {
987 rsync(); 1016 rsync();
989} 1018}
990 1019
991foreach my $ebuild_arg (@targets) 1020foreach my $ebuild_arg (@targets)
992{ 1021{
993 1022
994 # this is for packages like gtk+ 1023 # this is for packages like gtk+
995 $ebuild_arg =~ s/(\+)/\\$1/g; 1024 $ebuild_arg =~ s/(\+)/\\$1/g;
996 1025
997 foreach my $logfile (@logfiles) 1026 foreach my $logfile (@logfiles)
998 { 1027 {
999 my $handle; 1028 my $handle;
1000 open_file($logfile, \$handle); 1029 open_file($logfile, \$handle);
1001 foreach (<$handle>) 1030 foreach (<$handle>)
1002 { 1031 {
1003 my $pattern = gen_regexp($ebuild_arg); 1032 my $pattern = gen_regexp($ebuild_arg);
1004 if ($date_found) 1033 if ($date_found)
1005 { 1034 {
1006 if ($_ =~ m/^([0-9]{10})\:/) 1035 if ($_ =~ m/^([0-9]{10})\:/)
1007 { 1036 {
1008 if (datecompare($1) <= 0) 1037 if (datecompare($1) <= 0)
1009 { 1038 {
1010 next; 1039 next;
1011 } 1040 }
1012 } 1041 }
1013 } 1042 }
1014 if ($pretend_found) { &pretend; } 1043 if ($pretend_found) { &pretend; }
1015 if ($current_found) { &current; } 1044 if ($current_found) { &current; }
1016 if ($time_found or $info_found) 1045 if ($time_found or $info_found)
1017 { 1046 {
1018 if ($_ =~ m/^([0-9]{10})\: \>\>\> emerge .*?\) $pattern/) 1047 if ($_ =~ m/^([0-9]{10})\: \>\>\> emerge .*?\) $pattern/)
1019 { 1048 {
1020 $e_start = $1; 1049 $e_start = $1;
1021 $info_target = $2; 1050 $info_target = $2;
1022 } 1051 }
1023 } 1052 }
1024 if ($_ =~ m/^([0-9]{10})\: ::: completed .*?\) $pattern to \//) 1053 if ($_ =~ m/^([0-9]{10})\: ::: completed .*?\) $pattern to \//)
1025 { 1054 {
1026 my $e_date; 1055 my $e_date;
1027 if ($gmt_found) 1056 if ($gmt_found)
1028 { 1057 {
1029 $e_date = scalar gmtime "$1"; 1058 $e_date = scalar gmtime "$1";
1030 } 1059 }
1031 else 1060 else
1032 { 1061 {
1033 $e_date = scalar localtime "$1"; 1062 $e_date = scalar localtime "$1";
1034 } 1063 }
1035 $e_end = $1; 1064 $e_end = $1;
1036 if ($time_found or $info_found) 1065 if ($time_found or $info_found)
1037 { 1066 {
1038 &gtime($e_end - $e_start); 1067 &gtime($e_end - $e_start);
1039 if ($e_end - $e_start > 0) 1068 if ($e_end - $e_start > 0)
1040 { 1069 {
1041 $tm_secondi += ($e_end - $e_start); 1070 $tm_secondi += ($e_end - $e_start);
1042 } 1071 }
1043 else 1072 else
1044 { 1073 {
1045 $tm_secondi += 0; 1074 $tm_secondi += 0;
1046 } 1075 }
1047 } 1076 }
1048 if (!$e_count) 1077 if (!$e_count)
1049 { 1078 {
1050 my $p_ebuild = " \* $2\n\n"; 1079 my $p_ebuild = " \* $2\n\n";
1051 $p_ebuild =~ s/\\//g; 1080 $p_ebuild =~ s/\\//g;
1052 if (!$search_found) 1081 if (!$search_found)
1053 { 1082 {
1054 if ($ebuild_arg =~ m/\/$/) 1083 if ($ebuild_arg =~ m/\/$/)
1055 { 1084 {
1056 print colored("\* $ebuild_arg\n\n", $COLORS{'blue'}); 1085 print colored("\* $ebuild_arg\n\n", $COLORS{'blue'});
1057 } 1086 }
1058 else 1087 else
1059 { 1088 {
1060 print colored("$p_ebuild", $COLORS{'blue'}); 1089 print colored("$p_ebuild", $COLORS{'blue'});
1061 } 1090 }
1062 } 1091 }
1063 else 1092 else
1064 { 1093 {
1065 print colored(" \* matches found:\n\n", $COLORS{'blue'}); 1094 print colored(" \* matches found:\n\n", $COLORS{'blue'});
1066 } 1095 }
1067 } 1096 }
1068 if ($ebuild_found or !$info_found or $time_found) 1097 if ($ebuild_found or !$info_found or $time_found)
1069 { 1098 {
1070 my $eb = $2; 1099 my $eb = $2;
1071 my $extra = $3 || ""; 1100 my $extra = $3 || "";
1072 print " $e_date >>>", colored(" $eb$extra\n", $COLORS{'green'}); 1101 print " $e_date >>>", colored(" $eb$extra\n", $COLORS{'green'});
1073 } 1102 }
1074 if ($time_found) 1103 if ($time_found)
1075 { 1104 {
1076 print " merge time: "; 1105 print " merge time: ";
1077 if (($e_end - $e_start) > 0) 1106 if (($e_end - $e_start) > 0)
1078 { 1107 {
1079 &print_gtime(); 1108 &print_gtime();
1080 print "\n\n"; 1109 print "\n\n";
1081 } 1110 }
1082 else 1111 else
1083 { 1112 {
1084 print color 'bold red'; 1113 print color 'bold red';
1085 print "log error; merge time unknown."; 1114 print "log error; merge time unknown.";
1086 print color 'reset'; 1115 print color 'reset';
1087 print "\n\n"; 1116 print "\n\n";
1088 $w_count++; 1117 $w_count++;
1089 } 1118 }
1090 } 1119 }
1091 $e_count++; 1120 $e_count++;
1092 } 1121 }
1093 if ($unmerge_found or $info_found) 1122 if ($unmerge_found or $info_found)
1094 { 1123 {
1095 $pattern = gen_regexp($ebuild_arg); 1124 $pattern = gen_regexp($ebuild_arg);
1096 if (m/^([0-9]{10})\: \>\>\> unmerge success: ($pattern.*)/g) 1125 if (m/^([0-9]{10})\: \>\>\> unmerge success: ($pattern.*)/g)
1097 { 1126 {
1098 my $u_date = scalar localtime "$1"; 1127 my $u_date = scalar localtime "$1";
1099 if ($unmerge_found) 1128 if ($unmerge_found)
1100 { 1129 {
1101 print " $u_date <<<", colored(" $2\n", $COLORS{'red'}); 1130 print " $u_date <<<", colored(" $2\n", $COLORS{'red'});
1102 } 1131 }
1103 } 1132 }
1104 } 1133 }
1105 } 1134 }
1106 } 1135 }
1107 if (!$e_count and !$list_found and !$rsync_found) 1136 if (!$e_count and !$list_found and !$rsync_found)
1108 { 1137 {
1109 if ($e_count == 0) 1138 if ($e_count == 0)
1110 { 1139 {
1111 if ($online_query) 1140 if ($online_query)
1112 { 1141 {
1113 1142
1114 #query gentoo.linuxhowtos.org 1143 #query gentoo.linuxhowtos.org
1115 $tm_secondi += lhtoquery($ebuild_arg, \$e_count); 1144 $tm_secondi += lhtoquery($ebuild_arg, \$e_count);
1116 } 1145 }
1117 } 1146 }
1118 if ($e_count > 0) 1147 if ($e_count > 0)
1119 { 1148 {
1120 print "Estimated merge time: "; 1149 print "Estimated merge time: ";
1121 &gtime($tm_secondi); 1150 &gtime($tm_secondi);
1122 &print_gtime(); 1151 &print_gtime();
1123 } 1152 }
1124 else 1153 else
1125 { 1154 {
1126 print color 'bold red'; 1155 print color 'bold red';
1127 print "!!! Error: no merge found for \'$ebuild_arg\'"; 1156 print "!!! Error: no merge found for \'$ebuild_arg\'";
1128 print color 'reset'; 1157 print color 'reset';
1129 } 1158 }
1130 print "\n"; 1159 print "\n";
1131 } 1160 }
1132 elsif ($info_found) 1161 elsif ($info_found)
1133 { 1162 {
1134 &info($info_target); 1163 &info($info_target);
1135 } 1164 }
1136 else 1165 else
1137 { 1166 {
1138 $e_count = 0; 1167 $e_count = 0;
1139 } 1168 }
1140} 1169}
1141 1170
1142if ($lhtomsg) 1171if ($lhtomsg)
1143{ 1172{
1144 print color 'bold yellow'; 1173 print color 'bold yellow';
1145 print "$lhtomsg\n"; 1174 print "$lhtomsg\n";
1146 print color 'reset'; 1175 print color 'reset';
1147} 1176}
1148 1177

Legend:
Removed from v.206  
changed lines
  Added in v.207

  ViewVC Help
Powered by ViewVC 1.1.20