Gentoo Archives: gentoo-commits

From: "Paul Varner (fuzzyray)" <fuzzyray@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-perl r207 - genlop/trunk
Date: Fri, 29 Feb 2008 00:15:53
Message-Id: E1JUsuh-00088D-HB@stork.gentoo.org
1 Author: fuzzyray
2 Date: 2008-02-29 00:15:46 +0000 (Fri, 29 Feb 2008)
3 New Revision: 207
4
5 Modified:
6 genlop/trunk/genlop
7 Log:
8 Use tabs for all indentation. Bug #211856
9
10 Modified: genlop/trunk/genlop
11 ===================================================================
12 --- genlop/trunk/genlop 2007-10-20 16:52:47 UTC (rev 206)
13 +++ genlop/trunk/genlop 2008-02-29 00:15:46 UTC (rev 207)
14 @@ -17,6 +17,10 @@
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
17
18 +# TODO: dberkholz recommended changing --date <string> [--date <string>]
19 +# to --start-date and --end-date to alleviate confusion like
20 +# http://bugs.gentoo.org/show_bug.cgi?id=128194#c0
21 +
22 use strict;
23 use warnings;
24 use POSIX;
25 @@ -28,36 +32,36 @@
26 my $version = "0.30.7";
27 my @logfiles = ("/var/log/emerge.log");
28 my %COLORS = (
29 - 'blue' => 'bold blue',
30 - 'green' => 'bold green',
31 - 'red' => 'bold red',
32 + 'blue' => 'bold blue',
33 + 'green' => 'bold green',
34 + 'red' => 'bold red',
35 );
36 my ($e_count, $w_count, $tm_secondi, $m_secondi) = (0, 0, 0, 0);
37
38 # variabili per la funzione parse
39 my (
40 $date_found,
41 - $search_found,
42 - $unmerge_found,
43 - $list_found,
44 - $file_found,
45 - $time_found,
46 - $help_found,
47 - $current_found,
48 - $pretend_found,
49 - $version_found,
50 - $info_found,
51 - $gmt_found,
52 - $rsync_found,
53 - $info_ok,
54 - $info_target,
55 - $ssearch_found,
56 + $search_found,
57 + $unmerge_found,
58 + $list_found,
59 + $file_found,
60 + $time_found,
61 + $help_found,
62 + $current_found,
63 + $pretend_found,
64 + $version_found,
65 + $info_found,
66 + $gmt_found,
67 + $rsync_found,
68 + $info_ok,
69 + $info_target,
70 + $ssearch_found,
71 $online_query,
72 $secs,
73 $mins,
74 $hours,
75 $days,
76 - $lhtomsg,
77 + $lhtomsg,
78 $last_skipped
79 );
80
81 @@ -71,36 +75,32 @@
82
83 my ($userdate1, $userdate2, $searchdate1, $searchdate2);
84
85 -sub datecompare ($)
86 +sub datecompare ($)
87 {
88 -
89 - # datecompare( epoch )
90 - # returns -1 if epoch is outside searchdates 1 and 2
91 - # returns 1 if inside
92 - # returns undefined for errors
93 - # expects searchdate1 to be before searchdate2 and neither should be in
94 - # the future (but it's probably ok if searchdate2 is)
95 - die if (!$searchdate1);
96 - die if (!$searchdate2);
97 - my $epochdate = $_[0];
98 - if (($epochdate <=> $searchdate1) < 0)
99 - {
100 -
101 - # epoch is outside period
102 - return -1;
103 - }
104 - elsif (($epochdate <=> $searchdate2) > 0)
105 - {
106 -
107 - # epoch is outside period
108 - return -1;
109 - }
110 - else
111 - {
112 - return 1;
113 - }
114 -
115 - #TODO check that it's actually the case
116 + # datecompare( epoch )
117 + # returns -1 if epoch is outside searchdates 1 and 2
118 + # returns 1 if inside
119 + # returns undefined for errors
120 + # expects searchdate1 to be before searchdate2 and neither should be in
121 + # the future (but it's probably ok if searchdate2 is)
122 + die if (!$searchdate1);
123 + die if (!$searchdate2);
124 + my $epochdate = $_[0];
125 + if (($epochdate <=> $searchdate1) < 0)
126 + {
127 + # epoch is outside period
128 + return -1;
129 + }
130 + elsif (($epochdate <=> $searchdate2) > 0)
131 + {
132 + # epoch is outside period
133 + return -1;
134 + }
135 + else
136 + {
137 + return 1;
138 + }
139 + #TODO check that it's actually the case
140 }
141
142 # test a file, before opening it for reading
143 @@ -108,57 +108,58 @@
144 # a filehandle to the first argument
145 sub open_file
146 {
147 - my ($file, $fh) = @_;
148 - if ($file eq "/var/log/emerge.log" && !-r $file)
149 - {
150 - 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";
151 - exit 1;
152 - }
153 - if (-T $file)
154 - {
155 - open $$fh, '<', "$file"
156 - or die "could not open $file";
157 - return 0;
158 - }
159 + my ($file, $fh) = @_;
160 + if ($file eq "/var/log/emerge.log" && !-r $file)
161 + {
162 + print "$progname: cannot open " . $file . " for reading\n"
163 + . "maybe you are not a member of the portage group ?\n"
164 + . "try genlop -h for help\n";
165 + exit 1;
166 + }
167 + if (-T $file)
168 + {
169 + open $$fh, '<', "$file"
170 + or die "could not open $file";
171 + return 0;
172 + }
173
174 - # if we got here file is unreadable, might simply be compressed...
175 - # let's try this
176 - my $nature = qx{file $file}
177 - or die "could not determine nature of (nonASCII) $file";
178 - if ($nature =~ /gzip/)
179 - {
180 - open $$fh, "gzip -d -c $file |"
181 - or die "could not open (gzipped) $file";
182 - return 0;
183 - }
184 - elsif ($nature =~ /bzip/)
185 - {
186 - open $$fh, "bzip2 -d -c $file |"
187 - or die "could not open (bzipped) $file";
188 - return 0;
189 - }
190 - else
191 - {
192 -
193 - # giving up...
194 - print "could not determine file type of $file\n";
195 - exit 1;
196 - }
197 + # if we got here file is unreadable, might simply be compressed...
198 + # let's try this
199 + my $nature = qx{file $file}
200 + or die "could not determine nature of (nonASCII) $file";
201 + if ($nature =~ /gzip/)
202 + {
203 + open $$fh, "gzip -d -c $file |"
204 + or die "could not open (gzipped) $file";
205 + return 0;
206 + }
207 + elsif ($nature =~ /bzip/)
208 + {
209 + open $$fh, "bzip2 -d -c $file |"
210 + or die "could not open (bzipped) $file";
211 + return 0;
212 + }
213 + else
214 + {
215 + # giving up...
216 + print "could not determine file type of $file\n";
217 + exit 1;
218 + }
219 }
220
221 # orderes logfiles by date
222 sub order_logs (@)
223 {
224 - my @files = @_;
225 - my %ordered;
226 - foreach my $logfile (@files)
227 - {
228 - my $handle;
229 - open_file("$logfile", \$handle);
230 - my $fline = <$handle>; # first line
231 - $ordered{$logfile} = (split /:/, $fline)[0];
232 - }
233 - return sort { $ordered{$a} <=> $ordered{$b} } keys %ordered;
234 + my @files = @_;
235 + my %ordered;
236 + foreach my $logfile (@files)
237 + {
238 + my $handle;
239 + open_file("$logfile", \$handle);
240 + my $fline = <$handle>; # first line
241 + $ordered{$logfile} = (split /:/, $fline)[0];
242 + }
243 + return sort { $ordered{$a} <=> $ordered{$b} } keys %ordered;
244 }
245
246 # parse(arg), a hacked-up version of getopts
247 @@ -168,383 +169,409 @@
248 # FIXME Getopt::Long would be much better
249 sub parse ($)
250 {
251 - my $arg = $_[0];
252 - my $nexist = 0;
253 - chomp $arg;
254 + my $arg = $_[0];
255 + my $nexist = 0;
256 + chomp $arg;
257
258 - # long (--foo) options
259 - if ($arg =~ /^--/)
260 - {
261 - LSWITCH:
262 - {
263 - $current_found = 1, last LSWITCH if ($arg eq "--current");
264 - $pretend_found = 1, last LSWITCH if ($arg eq "--pretend");
265 - $help_found = 1, last LSWITCH if ($arg eq "--help");
266 - $time_found = 1, last LSWITCH if ($arg eq "--time");
267 - $unmerge_found = 1, last LSWITCH if ($arg eq "--unmerge");
268 - $ENV{'ANSI_COLORS_DISABLED'} = 1, last LSWITCH
269 - if ($arg eq "--nocolor");
270 - $list_found = 1, last LSWITCH if ($arg eq "--list");
271 - $version_found = 1, last LSWITCH if ($arg eq "--version");
272 - $search_found = 1, last LSWITCH if ($arg eq "--search");
273 - $info_found = 1, last LSWITCH if ($arg eq "--info");
274 - $gmt_found = 1, last LSWITCH if ($arg eq "--gmt");
275 - $rsync_found = 1, last LSWITCH if ($arg eq "--rsync");
276 + # long (--foo) options
277 + if ($arg =~ /^--/)
278 + {
279 + LSWITCH:
280 + {
281 + $current_found = 1, last LSWITCH if ($arg eq "--current");
282 + $pretend_found = 1, last LSWITCH if ($arg eq "--pretend");
283 + $help_found = 1, last LSWITCH if ($arg eq "--help");
284 + $time_found = 1, last LSWITCH if ($arg eq "--time");
285 + $unmerge_found = 1, last LSWITCH if ($arg eq "--unmerge");
286 + $ENV{'ANSI_COLORS_DISABLED'} = 1, last LSWITCH
287 + if ($arg eq "--nocolor");
288 + $list_found = 1, last LSWITCH if ($arg eq "--list");
289 + $version_found = 1, last LSWITCH if ($arg eq "--version");
290 + $search_found = 1, last LSWITCH if ($arg eq "--search");
291 + $info_found = 1, last LSWITCH if ($arg eq "--info");
292 + $gmt_found = 1, last LSWITCH if ($arg eq "--gmt");
293 + $rsync_found = 1, last LSWITCH if ($arg eq "--rsync");
294
295 - if ($arg eq "--date")
296 - {
297 - $date_found = 1;
298 - if (!$userdate1)
299 - {
300 - help() if !$ARGV[0];
301 - $userdate1 = ParseDate(\@ARGV);
302 - unless (UnixDate($userdate1, "%s"))
303 - {
304 - print color 'bold red';
305 - print "!!! Error:", " invalid date format (try mm/dd/yyyy)";
306 - print color 'reset';
307 - print "\n";
308 - exit -1;
309 - }
310 - if ((UnixDate($userdate1, "%s") <=> time) <= 0)
311 - {
312 - $searchdate1 = UnixDate($userdate1, "%s");
313 - $searchdate2 = time;
314 - }
315 - else
316 - {
317 - die "Date $userdate1 is in the future, not good\n";
318 - }
319 - }
320 - elsif (!$userdate2)
321 - {
322 - $userdate2 = ParseDate(\@ARGV);
323 - unless (UnixDate($userdate2, "%s"))
324 - {
325 - print color 'bold red';
326 - print "!!! Error:", " invalid date format (try mm/dd/yyyy)";
327 - print color 'reset';
328 - print "\n";
329 - exit -1;
330 - }
331 - if ((UnixDate($userdate1, "%s") <=> UnixDate($userdate2, "%s")) <= 0)
332 - {
333 - $searchdate2 = UnixDate($userdate2, "%s");
334 - }
335 - else
336 - {
337 - $searchdate2 = $searchdate1;
338 - $searchdate1 = UnixDate($userdate2, "%s");
339 - }
340 - }
341 - else
342 - {
343 - print "too many --date arguments ?\n";
344 - die;
345 - }
346 - last LSWITCH;
347 - }
348 - $nexist = $arg;
349 - } # END LSWITCH
350 - if ($nexist)
351 - {
352 + if ($arg eq "--date")
353 + {
354 + $date_found = 1;
355 + if (!$userdate1)
356 + {
357 + help() if !$ARGV[0];
358 + $userdate1 = ParseDate(\@ARGV);
359 + unless (UnixDate($userdate1, "%s"))
360 + {
361 + print color 'bold red';
362 + print "!!! Error:", " invalid date format (try mm/dd/yyyy)";
363 + print color 'reset';
364 + print "\n";
365 + exit -1;
366 + }
367 + if ((UnixDate($userdate1, "%s") <=> time) <= 0)
368 + {
369 + $searchdate1 = UnixDate($userdate1, "%s");
370 + $searchdate2 = time;
371 + }
372 + else
373 + {
374 + die "Date $userdate1 is in the future, not good\n";
375 + }
376 + }
377 + elsif (!$userdate2)
378 + {
379 + $userdate2 = ParseDate(\@ARGV);
380 + unless (UnixDate($userdate2, "%s"))
381 + {
382 + print color 'bold red';
383 + print "!!! Error:", " invalid date format (try mm/dd/yyyy)";
384 + print color 'reset';
385 + print "\n";
386 + exit -1;
387 + }
388 + if ((UnixDate($userdate1, "%s") <=> UnixDate($userdate2, "%s")) <= 0)
389 + {
390 + $searchdate2 = UnixDate($userdate2, "%s");
391 + }
392 + else
393 + {
394 + $searchdate2 = $searchdate1;
395 + $searchdate1 = UnixDate($userdate2, "%s");
396 + }
397 + }
398 + else
399 + {
400 + print "too many --date arguments ?\n";
401 + die;
402 + }
403 + last LSWITCH;
404 + }
405 + $nexist = $arg;
406 + } # END LSWITCH
407 + if ($nexist)
408 + {
409
410 - # This is the standard error message
411 - print color 'bold red';
412 - print "!!! Error: $nexist, invalid option.";
413 - print color 'reset';
414 - print "\n";
415 - exit -1;
416 - }
417 - return 0;
418 - }
419 + # This is the standard error message
420 + print color 'bold red';
421 + print "!!! Error: $nexist, invalid option.";
422 + print color 'reset';
423 + print "\n";
424 + exit -1;
425 + }
426 + return 0;
427 + }
428
429 - # short bsd-style options
430 - if ($arg =~ /^-.*/)
431 - {
432 - until ($arg eq "-")
433 - {
434 - my $opt = chop($arg);
435 - SSWITCH:
436 - {
437 - $help_found = 1, last SSWITCH if ($opt eq "h");
438 - $help_found = 1, last SSWITCH if ($opt eq "?");
439 - $time_found = 1, last SSWITCH if ($opt eq "t");
440 - $unmerge_found = 1, last SSWITCH if ($opt eq "u");
441 - $ENV{'ANSI_COLORS_DISABLED'} = 1, last SSWITCH if ($opt eq "n");
442 - $list_found = 1, last SSWITCH if ($opt eq "l");
443 - $search_found = 1, last SSWITCH if ($opt eq "s");
444 - $version_found = 1, last SSWITCH if ($opt eq "v");
445 - $info_found = 1, last SSWITCH if ($opt eq "i");
446 - $online_query = 1, last SSWITCH if ($opt eq "q");
447 - $ssearch_found = 1, last SSWITCH if ($opt eq "S");
448 - $current_found = 1, last SSWITCH if ($opt eq "c");
449 - $pretend_found = 1, last SSWITCH if ($opt eq "p");
450 - $rsync_found = 1, last SSWITCH if ($opt eq "r");
451 - $gmt_found = 1, last SSWITCH if ($opt eq "g");
452 - $ebuild_found = 1, last SSWITCH if ($opt eq "e");
453 + # short bsd-style options
454 + if ($arg =~ /^-.*/)
455 + {
456 + until ($arg eq "-")
457 + {
458 + my $opt = chop($arg);
459 + SSWITCH:
460 + {
461 + $help_found = 1, last SSWITCH if ($opt eq "h");
462 + $help_found = 1, last SSWITCH if ($opt eq "?");
463 + $time_found = 1, last SSWITCH if ($opt eq "t");
464 + $unmerge_found = 1, last SSWITCH if ($opt eq "u");
465 + $ENV{'ANSI_COLORS_DISABLED'} = 1, last SSWITCH if ($opt eq "n");
466 + $list_found = 1, last SSWITCH if ($opt eq "l");
467 + $search_found = 1, last SSWITCH if ($opt eq "s");
468 + $version_found = 1, last SSWITCH if ($opt eq "v");
469 + $info_found = 1, last SSWITCH if ($opt eq "i");
470 + $online_query = 1, last SSWITCH if ($opt eq "q");
471 + $ssearch_found = 1, last SSWITCH if ($opt eq "S");
472 + $current_found = 1, last SSWITCH if ($opt eq "c");
473 + $pretend_found = 1, last SSWITCH if ($opt eq "p");
474 + $rsync_found = 1, last SSWITCH if ($opt eq "r");
475 + $gmt_found = 1, last SSWITCH if ($opt eq "g");
476 + $ebuild_found = 1, last SSWITCH if ($opt eq "e");
477
478 - if ($opt eq "f")
479 - {
480 - if (!$ARGV[0])
481 - {
482 - print color 'bold red';
483 - print "!!! Error: no logfile specified.";
484 - print color 'reset';
485 - print "\n";
486 - exit -1;
487 - }
488 - if (!-r $ARGV[0])
489 - {
490 - print color 'bold red';
491 - print "!!! Error: logfile " . $ARGV[0] . " not readable ", "or not found.";
492 - print color 'reset';
493 - print "\n";
494 - exit -1;
495 - }
496 - print "using logfile " . $ARGV[0] . "\n";
497 - if (!$file_found)
498 - {
499 - $logfiles[0] = shift @ARGV;
500 - $file_found = 1;
501 - }
502 - else
503 - {
504 - push @logfiles, shift(@ARGV);
505 - }
506 - last SSWITCH;
507 - }
508 - $nexist = $opt;
509 - } # END SSWITCH
510 - }
511 - if ($nexist)
512 - {
513 - print color 'bold red';
514 - print "!!! Error: \-$nexist, invalid option.";
515 - print color 'reset';
516 - print "\n";
517 - exit -1;
518 - }
519 - return 0;
520 - }
521 - push @targets, $arg;
522 - return 0;
523 + if ($opt eq "f")
524 + {
525 + if (!$ARGV[0])
526 + {
527 + print color 'bold red';
528 + print "!!! Error: no logfile specified.";
529 + print color 'reset';
530 + print "\n";
531 + exit -1;
532 + }
533 + if (!-r $ARGV[0])
534 + {
535 + print color 'bold red';
536 + print "!!! Error: logfile " . $ARGV[0]
537 + . " not readable ", "or not found.";
538 + print color 'reset';
539 + print "\n";
540 + exit -1;
541 + }
542 + print "using logfile " . $ARGV[0] . "\n";
543 + if (!$file_found)
544 + {
545 + $logfiles[0] = shift @ARGV;
546 + $file_found = 1;
547 + }
548 + else
549 + {
550 + push @logfiles, shift(@ARGV);
551 + }
552 + last SSWITCH;
553 + }
554 + $nexist = $opt;
555 + } # END SSWITCH
556 + }
557 + if ($nexist)
558 + {
559 + print color 'bold red';
560 + print "!!! Error: \-$nexist, invalid option.";
561 + print color 'reset';
562 + print "\n";
563 + exit -1;
564 + }
565 + return 0;
566 + }
567 + push @targets, $arg;
568 + return 0;
569 }
570
571 # provides help information
572 sub help ()
573 {
574 - print "Usage: ", colored("genlop ", $COLORS{'blue'}), "[", colored("options", $COLORS{'green'}), "] [", colored("-f ", $COLORS{'green'}), "logfile] [",
575 - colored("category/package", $COLORS{'green'}), "]\n\n", colored("Options:\n", $COLORS{'green'}), colored(" -c ", $COLORS{'green'}),
576 - "display the currently compiling packages (if any)\n", colored(" -e ", $COLORS{'green'}) . "display package history; default if any option is used.\n",
577 - colored(" -f ", $COLORS{'green'}), "read emerge log information from \"logfile\" instead of ", $logfiles[0], "\n",
578 - colored(" -h ", $COLORS{'green'}), "print this help\n", colored(" -i ", $COLORS{'green'}),
579 - "extra infos for the selected package (build specific USE ", "and CFLAGS\n variables, average build time, etc)\n",
580 - colored(" -g ", $COLORS{'green'}), "display GMT/UTC, not localized time.\n", colored(" -l ", $COLORS{'green'}), "show full merge history.\n",
581 - colored(" -n ", $COLORS{'green'}), "no color in output\n", colored(" -p ", $COLORS{'green'}),
582 - "estimate build time from a piped \"emerge -p\" output\n", colored(" -q ", $COLORS{'green'}),
583 - "query gentoo.linuxhowtos.org database if no local emerge was found\n", colored(" -r ", $COLORS{'green'}),
584 - "search for portage tree sync/rsync history.\n", colored(" -s ", $COLORS{'green'}),
585 - "use (case insensitive) regular expressions to match package names\n", colored(" -S ", $COLORS{'green'}),
586 - "use case sensitive regular expressions to match package names\n", colored(" -t ", $COLORS{'green'}),
587 - "calculate merge time for the specific package(s).\n", colored(" -u ", $COLORS{'green'}), "show when packages have been unmerged.\n",
588 - colored(" -v ", $COLORS{'green'}), "display genlop version and exit.\n\n", colored(" --date datestring1", $COLORS{'green'}), " [",
589 - colored(" --date datestring2", $COLORS{'green'}), "] only shows results between datestring1\n",
590 - " and datestring2. datestring2 dafaults to \"now\" if not", " explicitly set.\n", " (e.g. genlop --list --date 3 days ago)\n",
591 - "\nThis program is licensed under the GPL v2. See COPYING.\n", "For further info about genlop please read the man page.\n";
592 - exit 0;
593 + my $genlop = colored("genlop ", $COLORS{'blue'});
594 + my $options = colored("options", $COLORS{'green'});
595 + my $f = colored("-f", $COLORS{'green'});
596 + my $catpkg = colored("category/package", $COLORS{'green'});
597 + my $Options = colored("Options:", $COLORS{'green'});
598 + my $dateStr = colored("--date", $COLORS{'green'});
599 +
600 + my $help =<<HELP;
601 +Usage: $genlop [$options] [$f logfile] [$catpkg]
602 +
603 +$Options
604 +
605 + -c display the currently compiling packages (if any)
606 + -e display package history; default if any option is used.
607 + -f read emerge log information from "logfile" instead of "$logfiles[0]"
608 + -h print this help
609 + -i extra infos for the selected package (build specific USE and CFLAGS
610 + variables, average build time, etc)
611 + -g display GMT/UTC, not localized time.
612 + -l show full merge history.
613 + -n no color in output
614 + -p estimate build time from a piped "emerge -p" output
615 + -q query gentoo.linuxhowtos.org database if no local emerge was found
616 + -r search for portage tree sync/rsync history.
617 + -s use (case insensitive) regular expressions to match package names
618 + -S use case sensitive regular expressions to match package names
619 + -t calculate merge time for the specific package(s).
620 + -u show when packages have been unmerged.
621 + -v display genlop version and exit.
622 +
623 + $dateStr datestring1 [$dateStr datestring2] only shows results between
624 + datestring1 and datestring2.
625 + datestring2 defaults to "now" if not explicitly set.
626 + (e.g. genlop --list --date 3 days ago) shows packages emerged since this
627 + time three days ago.
628 +
629 +This program is licensed under the GPL v2. See COPYING.
630 +For further info about genlop please read the man page.
631 +HELP
632 +
633 + # Color each option green
634 + $help =~ s/^ (-.)/" " . &colored($1, $COLORS{'green'})/gme;
635 +
636 + print $help;
637 + exit 0
638 }
639
640 sub gtime($)
641 {
642 - my $gtime = $_[0];
643 - chomp($gtime);
644 - $secs = $gtime % 60;
645 - $gtime = ($gtime - $secs) / 60;
646 - $mins = $gtime % 60;
647 - $gtime = ($gtime - $mins) / 60;
648 - $hours = $gtime % 24;
649 - $gtime = ($gtime - $hours) / 24;
650 - $days = $gtime % 7;
651 - if ($gtime < 0)
652 - {
653 - $gtime = 0;
654 - }
655 + my $gtime = $_[0];
656 + chomp($gtime);
657 + $secs = $gtime % 60;
658 + $gtime = ($gtime - $secs) / 60;
659 + $mins = $gtime % 60;
660 + $gtime = ($gtime - $mins) / 60;
661 + $hours = $gtime % 24;
662 + $gtime = ($gtime - $hours) / 24;
663 + $days = $gtime % 7;
664 + if ($gtime < 0)
665 + {
666 + $gtime = 0;
667 + }
668 }
669
670 sub print_gtime()
671 {
672 - if ($days > 0)
673 - {
674 - print colored("$days", $COLORS{'green'}), " day";
675 - print "s" if ($days > 1);
676 - }
677 - if ($hours > 0)
678 - {
679 - print ", " if ($days > 0);
680 - print colored("$hours", $COLORS{'green'}), " hour";
681 - print "s" if ($hours > 1);
682 - }
683 - if ($mins > 0)
684 - {
685 - print ", " if ($days > 0 or $hours > 0);
686 - print colored("$mins", $COLORS{'green'}), " minute";
687 - print "s" if ($mins > 1);
688 - }
689 - if ($mins < 1 && $hours < 1 && $days < 1 && $secs > 0 && $current_found)
690 - {
691 - print colored("less than a minute", $COLORS{'green'});
692 - }
693 - elsif ($mins < 1 && $hours < 1 && $days < 1 && $secs > 0 && $pretend_found)
694 - {
695 - print colored("less than a minute", $COLORS{'green'});
696 - }
697 - elsif ($secs > 0 && !$pretend_found)
698 - {
699 - print " and " if ($days > 0 or $hours > 0 or $mins > 0);
700 - print colored("$secs", $COLORS{'green'}), " second";
701 - print "s" if ($secs > 1);
702 - }
703 - print ".";
704 + if ($days > 0)
705 + {
706 + print colored("$days", $COLORS{'green'}), " day";
707 + print "s" if ($days > 1);
708 + }
709 + if ($hours > 0)
710 + {
711 + print ", " if ($days > 0);
712 + print colored("$hours", $COLORS{'green'}), " hour";
713 + print "s" if ($hours > 1);
714 + }
715 + if ($mins > 0)
716 + {
717 + print ", " if ($days > 0 or $hours > 0);
718 + print colored("$mins", $COLORS{'green'}), " minute";
719 + print "s" if ($mins > 1);
720 + }
721 + if ($mins < 1 && $hours < 1 && $days < 1 && $secs > 0 && $current_found)
722 + {
723 + print colored("less than a minute", $COLORS{'green'});
724 + }
725 + elsif ($mins < 1 && $hours < 1 && $days < 1 && $secs > 0 && $pretend_found)
726 + {
727 + print colored("less than a minute", $COLORS{'green'});
728 + }
729 + elsif ($secs > 0 && !$pretend_found)
730 + {
731 + print " and " if ($days > 0 or $hours > 0 or $mins > 0);
732 + print colored("$secs", $COLORS{'green'}), " second";
733 + print "s" if ($secs > 1);
734 + }
735 + print ".";
736 }
737
738 sub gen_regexp ($)
739 {
740 + # generates the correct regexp depending on what the user asked us.
741 + # default is to search only the correct package name (eg. mozilla)
742 + # a different regexp is needed in the following cases:
743 + # argument is in the form category/
744 + # argument is in the form category/ebuild
745 + # argument is in the form category/ebuild-version
746 + # the user can provide his own regular expression(s) via the -s option
747 + my $arg = $_[0];
748 + my ($category, $ebuild, $version);
749 + my $regexp;
750 + my @list;
751
752 - # generates the correct regexp depending on what the user asked us.
753 - # default is to search only the correct package name (eg. mozilla)
754 - # a different regexp is needed in the following cases:
755 - # argument is in the form category/
756 - # argument is in the form category/ebuild
757 - # argument is in the form category/ebuild-version
758 - # the user can provide his own regular expression(s) via the -s option
759 - my $arg = $_[0];
760 - my ($category, $ebuild, $version);
761 - my $regexp;
762 - my @list;
763 + if ($list_found)
764 + {
765 + if ($arg =~ m{^=})
766 + {
767 + $arg =~ s{^=}{};
768 + $regexp = qr/(.*$arg).*?/;
769 + }
770 + else
771 + {
772 + $regexp = qr/(.*)(-[0-9]{1,7}.*?)/i;
773 + }
774 + return "$regexp";
775 + }
776 + if ($search_found)
777 + {
778
779 - if ($list_found)
780 - {
781 - if ($arg =~ m{^=})
782 - {
783 - $arg =~ s{^=}{};
784 - $regexp = qr/(.*$arg).*?/;
785 - }
786 - else
787 - {
788 - $regexp = qr/(.*)(-[0-9]{1,7}.*?)/i;
789 - }
790 - return "$regexp";
791 - }
792 - if ($search_found)
793 - {
794 + # return user supplied regexp as-is
795 + if ($arg =~ m{^=})
796 + {
797 + $arg =~ s{^=}{};
798 + $regexp =
799 + $ssearch_found
800 + ? qr/(.*$arg)(.*?)/
801 + : qr/(.*$arg)(.*?)/i;
802 + }
803 + else
804 + {
805 + $regexp =
806 + $ssearch_found
807 + ? qr/(.*$arg.*?)(-[0-9]{1,7}.*?)/
808 + : qr/(.*$arg.*?)(-[0-9]{1,7}.*?)/i;
809 + }
810 + return "$regexp";
811 + }
812
813 - # return user supplied regexp as-is
814 - if ($arg =~ m{^=})
815 - {
816 - $arg =~ s{^=}{};
817 - $regexp =
818 - $ssearch_found
819 - ? qr/(.*$arg)(.*?)/
820 - : qr/(.*$arg)(.*?)/i;
821 - }
822 - else
823 - {
824 - $regexp =
825 - $ssearch_found
826 - ? qr/(.*$arg.*?)(-[0-9]{1,7}.*?)/
827 - : qr/(.*$arg.*?)(-[0-9]{1,7}.*?)/i;
828 - }
829 - return "$regexp";
830 - }
831 -
832 - # check if we were asked only the category
833 - if ($arg =~ /.*?\/$/)
834 - {
835 - $category = $arg;
836 - $regexp =
837 - $ssearch_found
838 - ? qr/($category.*?)(-[0-9]{1,7}.*?)/
839 - : qr/($category.*?)(-[0-9]{1,7}.*?)/i;
840 - return "$regexp";
841 - }
842 - @list = split(/\//, $arg);
843 - $ebuild = $list[0];
844 - if ($list[1])
845 - {
846 - $category = $list[0];
847 - $ebuild = $list[1];
848 - @list = ();
849 - @list = split(/(-[0-9]{1,7})/, $ebuild);
850 - if ($list[1])
851 - {
852 - $ebuild = $list[0];
853 - $version = $list[2] ? join('', $list[1], $list[2]) : $list[1];
854 - $category =~ s{^=}{};
855 - $regexp =
856 - $ssearch_found
857 - ? qr!($category\/$ebuild)($version)!
858 - : qr!($category\/$ebuild)($version)!i;
859 - return "$regexp";
860 - }
861 - $regexp =
862 - $ssearch_found
863 - ? qr!($category\/$ebuild)(-[0-9]{1,7}.*?)!
864 - : qr!($category\/$ebuild)(-[0-9]{1,7}.*?)!i;
865 - return "$regexp";
866 - }
867 - $regexp =
868 - $ssearch_found
869 - ? qr!(.*?/$ebuild)(-[0-9]{1,7}.*?)!
870 - : qr!(.*?/$ebuild)(-[0-9]{1,7}.*?)!i;
871 - return "$regexp";
872 + # check if we were asked only the category
873 + if ($arg =~ /.*?\/$/)
874 + {
875 + $category = $arg;
876 + $regexp =
877 + $ssearch_found
878 + ? qr/($category.*?)(-[0-9]{1,7}.*?)/
879 + : qr/($category.*?)(-[0-9]{1,7}.*?)/i;
880 + return "$regexp";
881 + }
882 + @list = split(/\//, $arg);
883 + $ebuild = $list[0];
884 + if ($list[1])
885 + {
886 + $category = $list[0];
887 + $ebuild = $list[1];
888 + @list = ();
889 + @list = split(/(-[0-9]{1,7})/, $ebuild);
890 + if ($list[1])
891 + {
892 + $ebuild = $list[0];
893 + $version = $list[2] ? join('', $list[1], $list[2]) : $list[1];
894 + $category =~ s{^=}{};
895 + $regexp =
896 + $ssearch_found
897 + ? qr!($category\/$ebuild)($version)!
898 + : qr!($category\/$ebuild)($version)!i;
899 + return "$regexp";
900 + }
901 + $regexp =
902 + $ssearch_found
903 + ? qr!($category\/$ebuild)(-[0-9]{1,7}.*?)!
904 + : qr!($category\/$ebuild)(-[0-9]{1,7}.*?)!i;
905 + return "$regexp";
906 + }
907 + $regexp =
908 + $ssearch_found
909 + ? qr!(.*?/$ebuild)(-[0-9]{1,7}.*?)!
910 + : qr!(.*?/$ebuild)(-[0-9]{1,7}.*?)!i;
911 + return "$regexp";
912 }
913
914 # Submitted in bug 157103 by sascha to enable searching against linuxhowtos for compile
915 # times when genlop has no data to work with
916 sub lhtoquery($$)
917 {
918 - my ( $vcpu, $pcpu, $opcpu ) = (0,0,-1);
919 - my $modelname = "";
920 + my ( $vcpu, $pcpu, $opcpu ) = (0,0,-1);
921 + my $modelname = "";
922 my $cachesize;
923 - my $packet = shift(@_);
924 - my $countref = shift(@_);
925 - open(my $cmdline, "/proc/cpuinfo");
926 - while (<$cmdline>)
927 - {
928 - if (m/processor\s*:\s*(\d*)/)
929 - {
930 - $vcpu = $1 if ($1 > $vcpu);
931 - }
932 - if (m/model name\s*:\s*(.*)$/)
933 - {
934 - $modelname = $1;
935 - }
936 - if (m/cache size\s*:\s*(.*)$/)
937 - {
938 - $cachesize = $1;
939 - }
940 - if (m/physical id\s*:\s*(\d*)$/)
941 - {
942 - $pcpu++ if ($1 != $opcpu);
943 - $opcpu = $1;
944 - }
945 - }
946 - $vcpu++;
947 - $pcpu = 1 if ($pcpu == 0);
948 - my $cpuname = $pcpu . "x $modelname $cachesize";
949 - $cpuname =~ s/ /%20/g;
950 - my $retval = LWP::Simple::get("http://gentoo.linuxhowtos.org/query.php?cpuname=$cpuname&vcpu=$vcpu&packetname=$packet");
951 - if ($retval =~ m/estimate: (\d*) seconds/)
952 - {
953 - $$countref = 1;
954 - return $1;
955 - }
956 - if ($retval =~ /unknown cpu/)
957 - {
958 - $lhtomsg = "Your CPU is not yet known, please add it by following the instructions on http://gentoo.linuxhowtos.org/compiletimeestimator/";
959 - }
960 - return 0;
961 + my $packet = shift(@_);
962 + my $countref = shift(@_);
963 + open(my $cmdline, "/proc/cpuinfo");
964 + while (<$cmdline>)
965 + {
966 + if (m/processor\s*:\s*(\d*)/)
967 + {
968 + $vcpu = $1 if ($1 > $vcpu);
969 + }
970 + if (m/model name\s*:\s*(.*)$/)
971 + {
972 + $modelname = $1;
973 + }
974 + if (m/cache size\s*:\s*(.*)$/)
975 + {
976 + $cachesize = $1;
977 + }
978 + if (m/physical id\s*:\s*(\d*)$/)
979 + {
980 + $pcpu++ if ($1 != $opcpu);
981 + $opcpu = $1;
982 + }
983 + }
984 + $vcpu++;
985 + $pcpu = 1 if ($pcpu == 0);
986 + my $cpuname = $pcpu . "x $modelname $cachesize";
987 + $cpuname =~ s/ /%20/g;
988 + my $retval = LWP::Simple::get("http://gentoo.linuxhowtos.org/query.php?cpuname=$cpuname&vcpu=$vcpu&packetname=$packet");
989 + if ($retval =~ m/estimate: (\d*) seconds/)
990 + {
991 + $$countref = 1;
992 + return $1;
993 + }
994 + if ($retval =~ /unknown cpu/)
995 + {
996 + $lhtomsg = "Your CPU is not yet known, please add it by following the instructions on http://gentoo.linuxhowtos.org/compiletimeestimator/";
997 + }
998 + return 0;
999 }
1000
1001 # --pretend or -p takes an emerge -p `-e -D world, system`, anything you want
1002 @@ -552,364 +579,362 @@
1003 # time and summed together. this is the estimated merge time
1004 sub pretend()
1005 {
1006 - if ($pretend_found)
1007 - {
1008 - @targets = ();
1009 - print "These are the pretended packages:";
1010 - print " (this may take a while; wait...)\n\n";
1011 + if ($pretend_found)
1012 + {
1013 + @targets = ();
1014 + print "These are the pretended packages:";
1015 + print " (this may take a while; wait...)\n\n";
1016
1017 - # open STDIN; that's why emerge -p foo is piped to a genlop -p
1018 - while (<STDIN>)
1019 - {
1020 - if ($_ =~ m/^\[e.*\] (.*?)\/(.*?)(\-[0-9])/)
1021 - {
1022 - push @targets, $2;
1023 - print;
1024 - }
1025 - }
1026 + # open STDIN; that's why emerge -p foo is piped to a genlop -p
1027 + while (<STDIN>)
1028 + {
1029 + if ($_ =~ m/^\[e.*\] (.*?)\/(.*?)(\-[0-9])/)
1030 + {
1031 + push @targets, $2;
1032 + print;
1033 + }
1034 + }
1035 my $last_ebuild;
1036 - foreach my $ebuild_arg (@targets)
1037 - {
1038 + foreach my $ebuild_arg (@targets)
1039 + {
1040
1041 - # we track the last ebuild processed with $last_ebuild variable
1042 - $last_ebuild = $ebuild_arg;
1043 - $ebuild_arg =~ s/(\+)/\\$1/g;
1044 - foreach my $logfile (@logfiles)
1045 - {
1046 - my $handle;
1047 - open_file($logfile, \$handle);
1048 - foreach (<$handle>)
1049 - {
1050 - if (m/^(.*?)\: \>\>\> emerge.*?\/$ebuild_arg-[0-9].*/)
1051 - {
1052 - $e_start = $1;
1053 - }
1054 - if (m/^(.*?)\: ::: completed .*?\) .*\/$ebuild_arg-[0-9].* to \//)
1055 - {
1056 - $e_end = $1;
1057 - $tm_secondi += ($e_end - $e_start);
1058 - $e_count++;
1059 - }
1060 - }
1061 - }
1062 - if ($e_count == 0)
1063 - {
1064 - if ($online_query)
1065 - {
1066 + # we track the last ebuild processed with $last_ebuild variable
1067 + $last_ebuild = $ebuild_arg;
1068 + $ebuild_arg =~ s/(\+)/\\$1/g;
1069 + foreach my $logfile (@logfiles)
1070 + {
1071 + my $handle;
1072 + open_file($logfile, \$handle);
1073 + foreach (<$handle>)
1074 + {
1075 + if (m/^(.*?)\: \>\>\> emerge.*?\/$ebuild_arg-[0-9].*/)
1076 + {
1077 + $e_start = $1;
1078 + }
1079 + if (m/^(.*?)\: ::: completed .*?\) .*\/$ebuild_arg-[0-9].* to \//)
1080 + {
1081 + $e_end = $1;
1082 + $tm_secondi += ($e_end - $e_start);
1083 + $e_count++;
1084 + }
1085 + }
1086 + }
1087 + if ($e_count == 0)
1088 + {
1089 + if ($online_query)
1090 + {
1091 + #query gentoo.linuxhowtos.org
1092 + $tm_secondi += lhtoquery($last_ebuild, \$e_count);
1093 + }
1094 + }
1095 + if ($e_count == 0)
1096 + {
1097 + $ebuild_arg =~ s/\\//g;
1098 + print "\n!!! Error: couldn't get previous ", "merge of $ebuild_arg; skipping...";
1099
1100 - #query gentoo.linuxhowtos.org
1101 - $tm_secondi += lhtoquery($last_ebuild, \$e_count);
1102 - }
1103 - }
1104 - if ($e_count == 0)
1105 - {
1106 - $ebuild_arg =~ s/\\//g;
1107 - print "\n!!! Error: couldn't get previous ", "merge of $ebuild_arg; skipping...";
1108 -
1109 - # if a pretended package haven't any successfull merge
1110 - # stored in logfile (ie a new package required by
1111 - # another, or a logfile corruption), prints a warning
1112 - # and keep track with $last_skipped
1113 - $last_skipped = $ebuild_arg;
1114 - }
1115 - else
1116 - {
1117 - $m_secondi += $tm_secondi / ($e_count);
1118 - $e_count = 0;
1119 - $tm_secondi = 0;
1120 - $last_skipped = "none-skipped";
1121 - }
1122 - }
1123 - if (@targets)
1124 - {
1125 - if ($last_ebuild =~ m/$last_skipped/)
1126 - {
1127 - print color 'bold red';
1128 - print "\n!!! Error: $last_skipped never merged; ", "estimated time unknown.";
1129 - print color 'reset';
1130 - print "\n";
1131 - if ($lhtomsg)
1132 - {
1133 - print color 'bold yellow';
1134 - print "$lhtomsg\n";
1135 - print color 'reset';
1136 - }
1137 - exit;
1138 - }
1139 - print "\n\nEstimated update time: ";
1140 - &gtime($m_secondi);
1141 - &print_gtime;
1142 - print "\n";
1143 - }
1144 - else
1145 - {
1146 - print color 'bold red';
1147 - print "\n!!! Error: no pretended packages found.";
1148 - print color 'reset';
1149 - print "\n";
1150 - }
1151 - exit;
1152 - }
1153 + # if a pretended package haven't any successfull merge
1154 + # stored in logfile (ie a new package required by
1155 + # another, or a logfile corruption), prints a warning
1156 + # and keep track with $last_skipped
1157 + $last_skipped = $ebuild_arg;
1158 + }
1159 + else
1160 + {
1161 + $m_secondi += $tm_secondi / ($e_count);
1162 + $e_count = 0;
1163 + $tm_secondi = 0;
1164 + $last_skipped = "none-skipped";
1165 + }
1166 + }
1167 + if (@targets)
1168 + {
1169 + if ($last_ebuild =~ m/$last_skipped/)
1170 + {
1171 + print color 'bold red';
1172 + print "\n!!! Error: $last_skipped never merged; ", "estimated time unknown.";
1173 + print color 'reset';
1174 + print "\n";
1175 + if ($lhtomsg)
1176 + {
1177 + print color 'bold yellow';
1178 + print "$lhtomsg\n";
1179 + print color 'reset';
1180 + }
1181 + exit;
1182 + }
1183 + print "\n\nEstimated update time: ";
1184 + &gtime($m_secondi);
1185 + &print_gtime;
1186 + print "\n";
1187 + }
1188 + else
1189 + {
1190 + print color 'bold red';
1191 + print "\n!!! Error: no pretended packages found.";
1192 + print color 'reset';
1193 + print "\n";
1194 + }
1195 + exit;
1196 + }
1197 }
1198
1199 sub current()
1200 {
1201 -
1202 - # support for 'current' merge.
1203 - #
1204 - # this whole 'current' thing is based on having sandboxind enabled
1205 - # we need to check for it, basically sandboxing is on if
1206 - # FEATURES contains 'sandbox' and does not contain 'userpriv'
1207 - # FEATURES contains 'sandbox' and contains both 'userpriv' and 'usersandbox'
1208 - # 20050815 - JeR: On slow systems, running portageq takes a lot of time,
1209 - # sometimes enough to miss all the sandbox action completely. Better to
1210 - # not check for sanity and have users check their FEATURES instead.
1211 - my @targets = ();
1212 - my @sandbox_pids = ();
1213 - my @sandbox_procs = qx{ps ax -o pid,args | tail -n +2 | sed -e's/^ *//' | grep ' sandbox ' | grep -v ' grep '};
1214 - my ($e_curmerge, $e_lastmerge);
1215 - foreach (@sandbox_procs)
1216 - {
1217 - if (m/^(.*?) \[(.*?)\-[0-9].*?\]/)
1218 - {
1219 - push @sandbox_pids, $1;
1220 - push @targets, $2;
1221 - }
1222 - }
1223 - if (scalar @sandbox_pids == 0)
1224 - {
1225 - print colored("!!!", $COLORS{'red'});
1226 - print " Error: no working merge found.\n";
1227 - print "(the -c option only works if there is" . " an ongoing compilation, see manpage)\n";
1228 - exit;
1229 - }
1230 - if (scalar @targets == 0)
1231 - {
1232 - print colored("!!!", $COLORS{'red'});
1233 - print "oops! should not happen, pease file bug\n";
1234 - print "empty \@targets\n";
1235 - exit 1;
1236 - }
1237 - foreach my $ebuild_arg (@targets)
1238 - {
1239 + # support for 'current' merge.
1240 + #
1241 + # this whole 'current' thing is based on having sandboxind enabled
1242 + # we need to check for it, basically sandboxing is on if
1243 + # FEATURES contains 'sandbox' and does not contain 'userpriv'
1244 + # FEATURES contains 'sandbox' and contains both 'userpriv' and 'usersandbox'
1245 + # 20050815 - JeR: On slow systems, running portageq takes a lot of time,
1246 + # sometimes enough to miss all the sandbox action completely. Better to
1247 + # not check for sanity and have users check their FEATURES instead.
1248 + my @targets = ();
1249 + my @sandbox_pids = ();
1250 + my @sandbox_procs = qx{ps ax -o pid,args | tail -n +2 | sed -e's/^ *//' | grep ' sandbox ' | grep -v ' grep '};
1251 + my ($e_curmerge, $e_lastmerge);
1252 + foreach (@sandbox_procs)
1253 + {
1254 + if (m/^(.*?) \[(.*?)\-[0-9].*?\]/)
1255 + {
1256 + push @sandbox_pids, $1;
1257 + push @targets, $2;
1258 + }
1259 + }
1260 + if (scalar @sandbox_pids == 0)
1261 + {
1262 + print colored("!!!", $COLORS{'red'});
1263 + print " Error: no working merge found.\n";
1264 + print "(the -c option only works if there is" . " an ongoing compilation, see manpage)\n";
1265 + exit;
1266 + }
1267 + if (scalar @targets == 0)
1268 + {
1269 + print colored("!!!", $COLORS{'red'});
1270 + print "oops! should not happen, pease file bug\n";
1271 + print "empty \@targets\n";
1272 + exit 1;
1273 + }
1274 + foreach my $ebuild_arg (@targets)
1275 + {
1276 my $e_current;
1277 - $ebuild_arg =~ s/(\+)/\\$1/g;
1278 - foreach my $logfile (@logfiles)
1279 - {
1280 - my $handle;
1281 - open_file($logfile, \$handle);
1282 - foreach (<$handle>)
1283 - {
1284 - if (m/^(.*?)\: \>\>\> emerge \((.*?) of (.*?)\)(.*?\/$ebuild_arg-[0-9].*?)to \//)
1285 - {
1286 - $e_start = $1;
1287 - $e_curmerge = $2;
1288 - $e_lastmerge = $3;
1289 - $e_current = $4;
1290 - }
1291 - if (m/^(.*?)\: ::: completed .*?\) .*\/$ebuild_arg-[0-9].* to \//)
1292 - {
1293 - $e_end = $1;
1294 - $e_count++;
1295 - &gtime($e_end - $e_start);
1296 - $tm_secondi += ($e_end - $e_start);
1297 - }
1298 - }
1299 - }
1300 - $e_end = CORE::time();
1301 - &gtime($e_end - $e_start);
1302 - print "\n Currently merging $e_curmerge out of $e_lastmerge\n";
1303 - print colored("\n \*$e_current\n\n", $COLORS{'blue'});
1304 - print " current merge time: ";
1305 - $current_found = undef;
1306 - &print_gtime();
1307 - $current_found = 1;
1308 - print "\n";
1309 - print " ETA: ";
1310 + $ebuild_arg =~ s/(\+)/\\$1/g;
1311 + foreach my $logfile (@logfiles)
1312 + {
1313 + my $handle;
1314 + open_file($logfile, \$handle);
1315 + foreach (<$handle>)
1316 + {
1317 + if (m/^(.*?)\: \>\>\> emerge \((.*?) of (.*?)\)(.*?\/$ebuild_arg-[0-9].*?)to \//)
1318 + {
1319 + $e_start = $1;
1320 + $e_curmerge = $2;
1321 + $e_lastmerge = $3;
1322 + $e_current = $4;
1323 + }
1324 + if (m/^(.*?)\: ::: completed .*?\) .*\/$ebuild_arg-[0-9].* to \//)
1325 + {
1326 + $e_end = $1;
1327 + $e_count++;
1328 + &gtime($e_end - $e_start);
1329 + $tm_secondi += ($e_end - $e_start);
1330 + }
1331 + }
1332 + }
1333 + $e_end = CORE::time();
1334 + &gtime($e_end - $e_start);
1335 + print "\n Currently merging $e_curmerge out of $e_lastmerge\n";
1336 + print colored("\n \*$e_current\n\n", $COLORS{'blue'});
1337 + print " current merge time: ";
1338 + $current_found = undef;
1339 + &print_gtime();
1340 + $current_found = 1;
1341 + print "\n";
1342 + print " ETA: ";
1343
1344 - if (!$e_count && $online_query)
1345 - {
1346 + if (!$e_count && $online_query)
1347 + {
1348
1349 - #query gentoo.linuxhowtos.org
1350 - $tm_secondi = lhtoquery($ebuild_arg, \$e_count);
1351 - $e_count = 1;
1352 - }
1353 + #query gentoo.linuxhowtos.org
1354 + $tm_secondi = lhtoquery($ebuild_arg, \$e_count);
1355 + $e_count = 1;
1356 + }
1357
1358 - if ($e_count && $e_start)
1359 - {
1360 - &gtime(($tm_secondi / $e_count) - ($e_end - $e_start));
1361 - if (($e_end - $e_start) >= ($tm_secondi / $e_count))
1362 - {
1363 - print colored("any time now.\n", $COLORS{'green'});
1364 - }
1365 - else
1366 - {
1367 - &print_gtime();
1368 - print "\n";
1369 - }
1370 - }
1371 - else
1372 - {
1373 - print color 'bold red';
1374 - print "unknown.";
1375 - print color 'reset';
1376 - print "\n";
1377 - }
1378 - }
1379 - exit;
1380 + if ($e_count && $e_start)
1381 + {
1382 + &gtime(($tm_secondi / $e_count) - ($e_end - $e_start));
1383 + if (($e_end - $e_start) >= ($tm_secondi / $e_count))
1384 + {
1385 + print colored("any time now.\n", $COLORS{'green'});
1386 + }
1387 + else
1388 + {
1389 + &print_gtime();
1390 + print "\n";
1391 + }
1392 + }
1393 + else
1394 + {
1395 + print color 'bold red';
1396 + print "unknown.";
1397 + print color 'reset';
1398 + print "\n";
1399 + }
1400 + }
1401 + exit;
1402 }
1403
1404 sub info($)
1405 {
1406 - my $package = $_[0];
1407 - if ($list_found) { &help(); }
1408 - if ($e_count) { $m_count = $e_count - $w_count; }
1409 - if ($m_count == 0)
1410 - {
1411 - print colored("Total merge time unknown.\n\n", $COLORS{'red'});
1412 - }
1413 - else
1414 - {
1415 - print "\n Total builds: ", colored("$e_count", $COLORS{'green'});
1416 - print "\n Global build time: ";
1417 - &gtime($tm_secondi);
1418 - &print_gtime();
1419 - if ($w_count)
1420 - {
1421 - print " Global build time of $m_count merges.\n";
1422 - }
1423 - else
1424 - {
1425 - print "\n";
1426 - }
1427 - if ($e_count > 1)
1428 - {
1429 - print " Average merge time: ";
1430 - &gtime($tm_secondi / $m_count);
1431 - &print_gtime();
1432 - print "\n";
1433 - }
1434 - $e_count = 0;
1435 - $tm_secondi = 0;
1436 + my $package = $_[0];
1437 + if ($list_found) { &help(); }
1438 + if ($e_count) { $m_count = $e_count - $w_count; }
1439 + if ($m_count == 0)
1440 + {
1441 + print colored("Total merge time unknown.\n\n", $COLORS{'red'});
1442 + }
1443 + else
1444 + {
1445 + print "\n Total builds: ", colored("$e_count", $COLORS{'green'});
1446 + print "\n Global build time: ";
1447 + &gtime($tm_secondi);
1448 + &print_gtime();
1449 + if ($w_count)
1450 + {
1451 + print " Global build time of $m_count merges.\n";
1452 + }
1453 + else
1454 + {
1455 + print "\n";
1456 + }
1457 + if ($e_count > 1)
1458 + {
1459 + print " Average merge time: ";
1460 + &gtime($tm_secondi / $m_count);
1461 + &print_gtime();
1462 + print "\n";
1463 + }
1464 + $e_count = 0;
1465 + $tm_secondi = 0;
1466
1467 - #$gtime = 0;
1468 - }
1469 - $e_count = 0;
1470 - print "\n Info about currently installed ebuild:\n";
1471 - opendir(DIR, "/var/db/pkg/") || die "can't open /var/db/pkg/ $!\n";
1472 - while (defined(my $categoria = readdir(DIR)))
1473 - {
1474 - if ($package =~ m/^$categoria.*/g)
1475 - {
1476 - opendir(DIR2, "/var/db/pkg/$categoria");
1477 - while (defined(my $package_dir = readdir(DIR2)))
1478 - {
1479 + #$gtime = 0;
1480 + }
1481 + $e_count = 0;
1482 + print "\n Info about currently installed ebuild:\n";
1483 + opendir(DIR, "/var/db/pkg/") || die "can't open /var/db/pkg/ $!\n";
1484 + while (defined(my $categoria = readdir(DIR)))
1485 + {
1486 + if ($package =~ m/^$categoria.*/g)
1487 + {
1488 + opendir(DIR2, "/var/db/pkg/$categoria");
1489 + while (defined(my $package_dir = readdir(DIR2)))
1490 + {
1491
1492 - #$package =~ s/(\+)/\\$1/g;
1493 - my $tmp_package = $package;
1494 - $tmp_package =~ s/\+/\\+/g;
1495 - if ("$categoria/$package_dir" =~ m/$tmp_package\-[0-9].*/)
1496 - {
1497 - $info_ok = 1;
1498 - print colored("\n * $categoria/$package_dir\n", $COLORS{'blue'});
1499 - $package_dir =~ s/(\+)/\\$1/g;
1500 + #$package =~ s/(\+)/\\$1/g;
1501 + my $tmp_package = $package;
1502 + $tmp_package =~ s/\+/\\+/g;
1503 + if ("$categoria/$package_dir" =~ m/$tmp_package\-[0-9].*/)
1504 + {
1505 + $info_ok = 1;
1506 + print colored("\n * $categoria/$package_dir\n", $COLORS{'blue'});
1507 + $package_dir =~ s/(\+)/\\$1/g;
1508
1509 my $e_date;
1510 - foreach my $logfile (@logfiles)
1511 - {
1512 - my $handle;
1513 - open_file($logfile, \$handle);
1514 - foreach (<$handle>)
1515 - {
1516 - my $pattern = gen_regexp("$categoria/$package_dir");
1517 - if (m/^([0-9]{10})\: ::: completed .*?\) $pattern to \//)
1518 - {
1519 - if ($gmt_found)
1520 - {
1521 - $e_date = scalar gmtime "$1";
1522 - }
1523 - else
1524 - {
1525 - $e_date = scalar localtime "$1";
1526 - }
1527 - }
1528 - }
1529 - }
1530 - print " Install date: ";
1531 - print colored("$e_date\n", $COLORS{'green'});
1532 + foreach my $logfile (@logfiles)
1533 + {
1534 + my $handle;
1535 + open_file($logfile, \$handle);
1536 + foreach (<$handle>)
1537 + {
1538 + my $pattern = gen_regexp("$categoria/$package_dir");
1539 + if (m/^([0-9]{10})\: ::: completed .*?\) $pattern to \//)
1540 + {
1541 + if ($gmt_found)
1542 + {
1543 + $e_date = scalar gmtime "$1";
1544 + }
1545 + else
1546 + {
1547 + $e_date = scalar localtime "$1";
1548 + }
1549 + }
1550 + }
1551 + }
1552 + print " Install date: ";
1553 + print colored("$e_date\n", $COLORS{'green'});
1554
1555 - # we use 3 array to collect data: before processing they are
1556 - # @unused_use: contain packages' USEs
1557 - # @pkg_use: USE declared before compiling that package
1558 - # @used_use: empty
1559 - my (@potential_use, @pkg_use, @used_use, @unused_use);
1560 + # we use 3 array to collect data: before processing they are
1561 + # @unused_use: contain packages' USEs
1562 + # @pkg_use: USE declared before compiling that package
1563 + # @used_use: empty
1564 + my (@potential_use, @pkg_use, @used_use, @unused_use);
1565
1566 - # each installed package store its information here
1567 - my $db_pkg_dir = "/var/db/pkg/$categoria/$package_dir/";
1568 - if ("$categoria/$package_dir" =~ m/.*\/(.*)/g)
1569 - {
1570 + # each installed package store its information here
1571 + my $db_pkg_dir = "/var/db/pkg/$categoria/$package_dir/";
1572 + if ("$categoria/$package_dir" =~ m/.*\/(.*)/g)
1573 + {
1574
1575 - # we search into the installed ebuild for USE flags available
1576 - # and store them in @potential_use.
1577 - open(pkg_ebuild, "$db_pkg_dir/$1.ebuild") || return;
1578 - while (<pkg_ebuild>)
1579 - {
1580 - if ($_ =~ m/^IUSE=\"(\$\{IUSE\} )?(.*)"/g)
1581 - {
1582 - @potential_use = split(/\ /, $2);
1583 - }
1584 - }
1585 - }
1586 + # we search into the installed ebuild for USE flags available
1587 + # and store them in @potential_use.
1588 + open(pkg_ebuild, "$db_pkg_dir/$1.ebuild") || return;
1589 + while (<pkg_ebuild>)
1590 + {
1591 + if ($_ =~ m/^IUSE=\"(\$\{IUSE\} )?(.*)"/g)
1592 + {
1593 + @potential_use = split(/\ /, $2);
1594 + }
1595 + }
1596 + }
1597
1598 - # this file lists every USE flag defined, even ones in make.conf
1599 - # we push'em in @pkg_use
1600 - open(pkg_use, "$db_pkg_dir/USE") || return;
1601 - while (<pkg_use>)
1602 - {
1603 - @pkg_use = split(/\ /, $_);
1604 - }
1605 + # this file lists every USE flag defined, even ones in make.conf
1606 + # we push'em in @pkg_use
1607 + open(pkg_use, "$db_pkg_dir/USE") || return;
1608 + while (<pkg_use>)
1609 + {
1610 + @pkg_use = split(/\ /, $_);
1611 + }
1612
1613 - # for every possible package USE we search into USEs stored in @pkg_use
1614 - # if a match is found we move it from @potential_use in @used_use.
1615 - # in this way, when every possible package USE are processed, @used_use
1616 - # contain only used ones and @potential_use the not used ones.
1617 - USE: foreach my $use (@potential_use)
1618 - {
1619 - chomp($use);
1620 - foreach my $pkg (@pkg_use)
1621 - {
1622 - chomp($pkg);
1623 - if ($use eq $pkg)
1624 - {
1625 - push(@used_use, $use);
1626 - next USE;
1627 - }
1628 - }
1629 - push(@unused_use, $use);
1630 - }
1631 + # for every possible package USE we search into USEs stored in @pkg_use
1632 + # if a match is found we move it from @potential_use in @used_use.
1633 + # in this way, when every possible package USE are processed, @used_use
1634 + # contain only used ones and @potential_use the not used ones.
1635 + USE: foreach my $use (@potential_use)
1636 + {
1637 + chomp($use);
1638 + foreach my $pkg (@pkg_use)
1639 + {
1640 + chomp($pkg);
1641 + if ($use eq $pkg)
1642 + {
1643 + push(@used_use, $use);
1644 + next USE;
1645 + }
1646 + }
1647 + push(@unused_use, $use);
1648 + }
1649
1650 - # finally we print'em out
1651 - print " USE=\"", colored("@used_use", $COLORS{'red'});
1652 - foreach my $unused (@unused_use)
1653 - {
1654 - print colored(" -$unused", $COLORS{'blue'});
1655 - }
1656 - print "\"\n";
1657 + # finally we print'em out
1658 + print " USE=\"", colored("@used_use", $COLORS{'red'});
1659 + foreach my $unused (@unused_use)
1660 + {
1661 + print colored(" -$unused", $COLORS{'blue'});
1662 + }
1663 + print "\"\n";
1664
1665 - # easy work here: we simply print the CFLAGS file
1666 - print " CFLAGS=\"";
1667 - open(pkg_cflag, "$db_pkg_dir/CFLAGS");
1668 - while (<pkg_cflag>)
1669 - {
1670 - chomp();
1671 - print();
1672 - }
1673 - print "\"\n";
1674 - }
1675 - }
1676 - }
1677 - }
1678 - if (!$info_ok) { print " none installed.\n"; }
1679 + # easy work here: we simply print the CFLAGS file
1680 + print " CFLAGS=\"";
1681 + open(pkg_cflag, "$db_pkg_dir/CFLAGS");
1682 + while (<pkg_cflag>)
1683 + {
1684 + chomp();
1685 + print();
1686 + }
1687 + print "\"\n";
1688 + }
1689 + }
1690 + }
1691 + }
1692 + if (!$info_ok) { print " none installed.\n"; }
1693 }
1694
1695 sub rsync() {
1696 @@ -952,21 +977,25 @@
1697 help() if ($help_found);
1698 if ($version_found)
1699 {
1700 - print "genlop $version, maintained by Michael Cummings <mcummings\@gentoo.org>\n"
1701 - . "original code by Giorgio Mandolfo and Antonio Dolcetta\n"
1702 - . "Please file any bugs found online at:\n"
1703 - . "https://bugs.gentoo.org\n"
1704 - . "Distribuited under the GPL v2. See COPYING for details\n";
1705 - exit;
1706 + print <<VERSION;
1707 +genlop $version, maintained by Michael Cummings <mcummings\@gentoo.org>
1708 +original code by Giorgio Mandolfo and Antonio Dolcetta
1709 +
1710 +Please file any bugs found online at:
1711 + https://bugs.gentoo.org
1712 +
1713 +Distributed under the GPL v2. See COPYING for details
1714 +VERSION
1715 + exit 0;
1716 }
1717
1718 if ( !$targets[0]
1719 - and !$list_found
1720 - and !$current_found
1721 - and !$pretend_found
1722 - and !$rsync_found)
1723 + and !$list_found
1724 + and !$current_found
1725 + and !$pretend_found
1726 + and !$rsync_found)
1727 {
1728 - help();
1729 + help();
1730 }
1731
1732 # FIXME questi a cosa servono ?
1733 @@ -979,7 +1008,7 @@
1734 #cache_files(\@logfiles, \@logfile_cache);
1735 if (scalar @logfiles > 1)
1736 {
1737 - @logfiles = order_logs(@logfiles);
1738 + @logfiles = order_logs(@logfiles);
1739 }
1740
1741 # - Option -r given? >
1742 @@ -991,158 +1020,158 @@
1743 foreach my $ebuild_arg (@targets)
1744 {
1745
1746 - # this is for packages like gtk+
1747 - $ebuild_arg =~ s/(\+)/\\$1/g;
1748 + # this is for packages like gtk+
1749 + $ebuild_arg =~ s/(\+)/\\$1/g;
1750
1751 - foreach my $logfile (@logfiles)
1752 - {
1753 - my $handle;
1754 - open_file($logfile, \$handle);
1755 - foreach (<$handle>)
1756 - {
1757 - my $pattern = gen_regexp($ebuild_arg);
1758 - if ($date_found)
1759 - {
1760 - if ($_ =~ m/^([0-9]{10})\:/)
1761 - {
1762 - if (datecompare($1) <= 0)
1763 - {
1764 - next;
1765 - }
1766 - }
1767 - }
1768 - if ($pretend_found) { &pretend; }
1769 - if ($current_found) { &current; }
1770 - if ($time_found or $info_found)
1771 - {
1772 - if ($_ =~ m/^([0-9]{10})\: \>\>\> emerge .*?\) $pattern/)
1773 - {
1774 - $e_start = $1;
1775 - $info_target = $2;
1776 - }
1777 - }
1778 - if ($_ =~ m/^([0-9]{10})\: ::: completed .*?\) $pattern to \//)
1779 - {
1780 + foreach my $logfile (@logfiles)
1781 + {
1782 + my $handle;
1783 + open_file($logfile, \$handle);
1784 + foreach (<$handle>)
1785 + {
1786 + my $pattern = gen_regexp($ebuild_arg);
1787 + if ($date_found)
1788 + {
1789 + if ($_ =~ m/^([0-9]{10})\:/)
1790 + {
1791 + if (datecompare($1) <= 0)
1792 + {
1793 + next;
1794 + }
1795 + }
1796 + }
1797 + if ($pretend_found) { &pretend; }
1798 + if ($current_found) { &current; }
1799 + if ($time_found or $info_found)
1800 + {
1801 + if ($_ =~ m/^([0-9]{10})\: \>\>\> emerge .*?\) $pattern/)
1802 + {
1803 + $e_start = $1;
1804 + $info_target = $2;
1805 + }
1806 + }
1807 + if ($_ =~ m/^([0-9]{10})\: ::: completed .*?\) $pattern to \//)
1808 + {
1809 my $e_date;
1810 - if ($gmt_found)
1811 - {
1812 - $e_date = scalar gmtime "$1";
1813 - }
1814 - else
1815 - {
1816 - $e_date = scalar localtime "$1";
1817 - }
1818 - $e_end = $1;
1819 - if ($time_found or $info_found)
1820 - {
1821 - &gtime($e_end - $e_start);
1822 - if ($e_end - $e_start > 0)
1823 - {
1824 - $tm_secondi += ($e_end - $e_start);
1825 - }
1826 - else
1827 - {
1828 - $tm_secondi += 0;
1829 - }
1830 - }
1831 - if (!$e_count)
1832 - {
1833 - my $p_ebuild = " \* $2\n\n";
1834 - $p_ebuild =~ s/\\//g;
1835 - if (!$search_found)
1836 - {
1837 - if ($ebuild_arg =~ m/\/$/)
1838 - {
1839 - print colored("\* $ebuild_arg\n\n", $COLORS{'blue'});
1840 - }
1841 - else
1842 - {
1843 - print colored("$p_ebuild", $COLORS{'blue'});
1844 - }
1845 - }
1846 - else
1847 - {
1848 - print colored(" \* matches found:\n\n", $COLORS{'blue'});
1849 - }
1850 - }
1851 - if ($ebuild_found or !$info_found or $time_found)
1852 - {
1853 - my $eb = $2;
1854 - my $extra = $3 || "";
1855 - print " $e_date >>>", colored(" $eb$extra\n", $COLORS{'green'});
1856 - }
1857 - if ($time_found)
1858 - {
1859 - print " merge time: ";
1860 - if (($e_end - $e_start) > 0)
1861 - {
1862 - &print_gtime();
1863 - print "\n\n";
1864 - }
1865 - else
1866 - {
1867 - print color 'bold red';
1868 - print "log error; merge time unknown.";
1869 - print color 'reset';
1870 - print "\n\n";
1871 - $w_count++;
1872 - }
1873 - }
1874 - $e_count++;
1875 - }
1876 - if ($unmerge_found or $info_found)
1877 - {
1878 - $pattern = gen_regexp($ebuild_arg);
1879 - if (m/^([0-9]{10})\: \>\>\> unmerge success: ($pattern.*)/g)
1880 - {
1881 - my $u_date = scalar localtime "$1";
1882 - if ($unmerge_found)
1883 - {
1884 - print " $u_date <<<", colored(" $2\n", $COLORS{'red'});
1885 - }
1886 - }
1887 - }
1888 - }
1889 - }
1890 - if (!$e_count and !$list_found and !$rsync_found)
1891 - {
1892 - if ($e_count == 0)
1893 - {
1894 - if ($online_query)
1895 - {
1896 + if ($gmt_found)
1897 + {
1898 + $e_date = scalar gmtime "$1";
1899 + }
1900 + else
1901 + {
1902 + $e_date = scalar localtime "$1";
1903 + }
1904 + $e_end = $1;
1905 + if ($time_found or $info_found)
1906 + {
1907 + &gtime($e_end - $e_start);
1908 + if ($e_end - $e_start > 0)
1909 + {
1910 + $tm_secondi += ($e_end - $e_start);
1911 + }
1912 + else
1913 + {
1914 + $tm_secondi += 0;
1915 + }
1916 + }
1917 + if (!$e_count)
1918 + {
1919 + my $p_ebuild = " \* $2\n\n";
1920 + $p_ebuild =~ s/\\//g;
1921 + if (!$search_found)
1922 + {
1923 + if ($ebuild_arg =~ m/\/$/)
1924 + {
1925 + print colored("\* $ebuild_arg\n\n", $COLORS{'blue'});
1926 + }
1927 + else
1928 + {
1929 + print colored("$p_ebuild", $COLORS{'blue'});
1930 + }
1931 + }
1932 + else
1933 + {
1934 + print colored(" \* matches found:\n\n", $COLORS{'blue'});
1935 + }
1936 + }
1937 + if ($ebuild_found or !$info_found or $time_found)
1938 + {
1939 + my $eb = $2;
1940 + my $extra = $3 || "";
1941 + print " $e_date >>>", colored(" $eb$extra\n", $COLORS{'green'});
1942 + }
1943 + if ($time_found)
1944 + {
1945 + print " merge time: ";
1946 + if (($e_end - $e_start) > 0)
1947 + {
1948 + &print_gtime();
1949 + print "\n\n";
1950 + }
1951 + else
1952 + {
1953 + print color 'bold red';
1954 + print "log error; merge time unknown.";
1955 + print color 'reset';
1956 + print "\n\n";
1957 + $w_count++;
1958 + }
1959 + }
1960 + $e_count++;
1961 + }
1962 + if ($unmerge_found or $info_found)
1963 + {
1964 + $pattern = gen_regexp($ebuild_arg);
1965 + if (m/^([0-9]{10})\: \>\>\> unmerge success: ($pattern.*)/g)
1966 + {
1967 + my $u_date = scalar localtime "$1";
1968 + if ($unmerge_found)
1969 + {
1970 + print " $u_date <<<", colored(" $2\n", $COLORS{'red'});
1971 + }
1972 + }
1973 + }
1974 + }
1975 + }
1976 + if (!$e_count and !$list_found and !$rsync_found)
1977 + {
1978 + if ($e_count == 0)
1979 + {
1980 + if ($online_query)
1981 + {
1982
1983 - #query gentoo.linuxhowtos.org
1984 - $tm_secondi += lhtoquery($ebuild_arg, \$e_count);
1985 - }
1986 - }
1987 - if ($e_count > 0)
1988 - {
1989 - print "Estimated merge time: ";
1990 - &gtime($tm_secondi);
1991 - &print_gtime();
1992 - }
1993 - else
1994 - {
1995 - print color 'bold red';
1996 - print "!!! Error: no merge found for \'$ebuild_arg\'";
1997 - print color 'reset';
1998 - }
1999 - print "\n";
2000 - }
2001 - elsif ($info_found)
2002 - {
2003 - &info($info_target);
2004 - }
2005 - else
2006 - {
2007 - $e_count = 0;
2008 - }
2009 + #query gentoo.linuxhowtos.org
2010 + $tm_secondi += lhtoquery($ebuild_arg, \$e_count);
2011 + }
2012 + }
2013 + if ($e_count > 0)
2014 + {
2015 + print "Estimated merge time: ";
2016 + &gtime($tm_secondi);
2017 + &print_gtime();
2018 + }
2019 + else
2020 + {
2021 + print color 'bold red';
2022 + print "!!! Error: no merge found for \'$ebuild_arg\'";
2023 + print color 'reset';
2024 + }
2025 + print "\n";
2026 + }
2027 + elsif ($info_found)
2028 + {
2029 + &info($info_target);
2030 + }
2031 + else
2032 + {
2033 + $e_count = 0;
2034 + }
2035 }
2036
2037 if ($lhtomsg)
2038 {
2039 - print color 'bold yellow';
2040 - print "$lhtomsg\n";
2041 - print color 'reset';
2042 + print color 'bold yellow';
2043 + print "$lhtomsg\n";
2044 + print color 'reset';
2045 }
2046
2047
2048 --
2049 gentoo-commits@l.g.o mailing list