View previous topic :: View next topic |
Author |
Message |
GBob Tux's lil' helper
Joined: 13 Nov 2004 Posts: 110 Location: Portland, Oregon
|
Posted: Thu Apr 21, 2005 12:20 pm Post subject: Emerge Progress Wrapper |
|
|
Okay, I'm putting this up to be poked, proded, and examined. Why do I just feel like I went the to the doctor's office? Anyways, here's a perl script which wraps around emerge and displays progress (though not always accurately.)
[Edit]
Use soft tab of 4, hard at 8 for viewing[/Edit]
Code: | #!/usr/local/bin/perl -w
############################################################
# File - emerge.pl
# Author - GBob
# Date - Wednesday, April 20, 2005
# E-Mail - Guardian.Bob@gmail.com
# Description - Wrapper for emerge, shows progress.
# Flags - See emerge
# Notes - Ask is done inside this code
###########################################################
use strict;
use Term::ANSIColor qw(:constants);
############################################################
# Function - yesno
# Date - Wednesday, April 20, 2005
# Input - Question to ask
# ReturnVal - 1 yes, 0 no, -1 unknown
# Description - Asks a question with a yes/no answer.
# The user's choice is then returned.
############################################################
sub yesno{
my $quest = shift;
print WHITE, BOLD, $quest, RESET;
print "[";
print BOLD GREEN, "Yes", RESET;
print "/";
print BOLD RED, "No", RESET;
print "] ";
select((select(STDOUT), $| = 1)[0]);
my $line=<STDIN>;
if($line =~ m/^yes$/i){
return 1;
}
if($line =~ m/^no$/i){
return 0;
}
if($line =~ m/^y$/i){
return 1;
}
if($line =~ m/^n$/i){
return 0;
}
return -1;
}
############################################################
# Function - askpack
# Date - Wednesday, April 20, 2005
# Input - command line options to use
# ReturnVal - 1 on continue
# Description - This function exits if the user doesn't
# want to merge, returns 1 if okay.
############################################################
sub askpack{
my $cmdline = shift;
my $child_pid;
$cmdline .= "-p";
if($child_pid = fork){
$SIG{INT}=sub{kill INT $child_pid};
waitpid($child_pid, 0);
$SIG{INT}='DEFAULT';
my $result;
while(($result=yesno("Do you want me to merge these packages? ")) == -1){}
if($result == 0){
exit;
}
}else{
die "cannot fork: $!" unless defined $child_pid;
exec((split(/ /, "/usr/bin/emerge ".$cmdline)));
}
return 1;
}
############################################################
# Function - status
# Date - Wednesday, April 20, 2005
# Input - none
# ReturnVal - string, status line
# Description - returns a string to print on the status
# line
############################################################
sub status{
my $FULL=`tail -n 2 /var/log/emerge.log | grep Compiling`;
$FULL =~ s/(.*)Compiling\/Merging \((.*)::.*$/$2/;
$FULL =~ s/(\([a-zA-Z].*\))\/\(.*\)/$1\/$2/;
chomp($FULL);
if($FULL eq ""){
return "";
}
my $CUR=$FULL;
$CUR=~s/(.*)\/(.*)/$2/;
my $TOT=`find /var/tmp/portage/$CUR -iname "*.c*" | wc -l`;
my $PROG=`find /var/tmp/portage/$CUR -iname "*.o*" | wc -l`;
my $PER;
if($TOT==0){
$PER=0;
}else{
$PER = int( $PROG/$TOT * 100);
}
if($PER > 100){
$PER=100;
}
return "Currently Compiling Package: $FULL ($PER%)";
}
my $pretend=0;
my $ask=0;
my $line="";
for (@ARGV){
if(m/^--/i){
if(!m/--ask/){
$line .= $_." ";
}else{
$ask=1;
}
if(m/--pretend/){
$pretend=1;
}
}elsif(m/^-[a-z]+/i){
if(m/a/){
$ask=1;
}
if(m/p/){
$pretend=1;
}
$_=~s/a//;
$line.=$_." ";
}else{
$line.=$_." ";
}
}
if($pretend != 0){
exec((split(/ /, "/usr/bin/emerge ".$line)));
}
if($ask != 0){
askpack($line);
}
my $c_pid=open(PH, "/usr/bin/emerge ".$line . " 2>&1 |");
while(<PH>){
select((select(STDOUT), $| = 0)[0]);
print "\r".(" " x 80)."\r".$_, BLACK ON_WHITE status(), RESET;
select((select(STDOUT), $| = 1)[0]);
}
print "\r".(" " x 80)."\r";
|
Comments/flames/improvements to Guardian.Bob@gmail.com _________________ rank[0]-=('n'-'d');
rank[3]-=('b'-'d');
It is better to say nothing and have people think your are an idiot,
Than open your mouth and remove all doubt. |
|
Back to top |
|
|
exklusve Apprentice
Joined: 23 Aug 2002 Posts: 270 Location: currently ~/
|
Posted: Thu Apr 21, 2005 3:13 pm Post subject: |
|
|
Hey man I checked out this script. Looks really good from what i've seen so far
I have one bitch about it.....
when I was upgrading my firefox (first time using this script)
I get this on my screen when it is downloading the package..
Code: | 7800K .......... .......... .......... .......... .......... 24% 61.53 KB/s
7850K .......... .......... .......... .......... .......... 24% 136.61 KB/s
7900K .......... .......... .......... .......... .......... 24% 139.04 KB/s
7950K .......... .......... .......... .......... .......... 24% 145.05 KB/s
8000K .......... .......... .......... .......... .......... 25% 120.16 KB/s
8050K .......... .......... .......... .......... .......... 25% 115.16 KB/s
8100K .......... .......... .......... .......... .......... 25% 152.96 KB/s
8150K .......... .......... .......... .......... .......... 25% 168.95 KB/s
8200K .......... .......... .......... .......... .......... 25% 179.32 KB/s
8250K .......... .......... .......... .......... .......... 25% 93.21 KB/s
8300K .......... .......... .......... .......... .......... 26% 139.50 KB/s
8350K .......... .......... .......... .......... .......... 26% 193.01 KB/s
8400K .......... .......... .......... .......... .......... 26% 166.17 KB/s
8450K .......... .......... .......... .......... .......... 26% 125.52 KB/s
8500K .......... .......... .......... .......... .......... 26% 86.50 KB/s
8550K .......... .......... .......... .......... .......... 26% 122.23 KB/s
8600K .......... .......... .......... .......... .......... 27% 199.63 KB/s
8650K .......... .......... .......... .......... .......... 27% 234.88 KB/s
8700K .......... .......... .......... .......... .......... 27% 237.13 KB/s
8750K .......... .......... .......... .......... .......... 27% 243.64 KB/s
8800K .......... .......... .......... .......... .......... 27% 93.85 KB/s
8850K .......... .......... .......... .......... .......... 27% 175.68 KB/s
8900K .......... .......... .......... .......... .......... 27% 174.56 KB/s
Currently Compiling Package: www-client/mozilla-firefox-1.0.3 (0%)
|
I thought maybe it was using aget instead of wget to get these packages. But I didn't see aget anywhere in the script.
If i didn't have that scrolling the whole time packages were downloading that would be very cool.
I haven't really looked through the code to see if i can change it. I'm armed with only minimal perl knowledge, so I'll see what i can do.
Check out this perl script I wrote to admin LPR print que's. Almost full administration for a LPR server.
https://forums.gentoo.org/viewtopic-t-310064-highlight-.html I'd like some feedback if you can provide any.
Thanks! and thanks for the great script!
(edit)
Found one more thing. Again its of no major consequence, just cosmetic...
Code: | checking for int64... no
checking for uint... yes
checking for uint_t... no
checking for uint16_t... no
checking for uname.domainname... yes
checking for uname.__domainname... no
checking for usable wchar_t (2 bytes, unsigned)... no
checking for compiler -fshort-wchar option... yes
checking for .hidden assembler directive... yes
Currently Compiling Package: www-client/mozilla-firefox-1.0.3 (2%) find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest: No such file or directory
find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest.c: No such file or directory
checking whether __attribute__((visibility())) is supported... yes
checking for dirent.h that defines DIR... yes
Currently Compiling Package: www-client/mozilla-firefox-1.0.3 (2%) find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest: No such file or directory
checking for opendir in -ldir... no
Currently Compiling Package: www-client/mozilla-firefox-1.0.3 (2%) find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest.C: No such file or directory
checking for sys/byteorder.h... no
Currently Compiling Package: www-client/mozilla-firefox-1.0.3 (2%) find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest: No such file or directory
checking for compat.h... no
checking for getopt.h... yes
Currently Compiling Package: www-client/mozilla-firefox-1.0.3 (2%) find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest.c: No such file or directory
find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest: No such file or directory
find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest.C: No such file or directory
checking for sys/bitypes.h... yes
Currently Compiling Package: www-client/mozilla-firefox-1.0.3 (2%) find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest.c: No such file or directory
find: /var/tmp/portage/mozilla-firefox-1.0.3/work/mozilla/conftest.o: No such file or directory
checking for memory.h... yes
checking for unistd.h... yes
Currently Compiling Package: www-client/mozilla-firefox-1.0.3 (2%)
|
When an error comes up, it will scroll the progress bar though the screen...not sure if that can be easily changed...I'm going to let this compile finish, i'd like to see how accurate the progress thing is.
Thanks again for the script dude! _________________ eXklusve
You do know that no one gives a shit about your system spec's right? |
|
Back to top |
|
|
GurliGebis Retired Dev
Joined: 08 Aug 2002 Posts: 509
|
Posted: Tue Apr 26, 2005 7:35 am Post subject: |
|
|
This requires that every .c file will be compiled, AFAIK not every package compiles every .c file, so it might not be accurate.
Some packages also does other things than compiling .c files.
How about .cpp files btw. ? _________________ Queen Rocks. |
|
Back to top |
|
|
elvisthedj Guru
Joined: 21 Jun 2004 Posts: 483 Location: Nampa, ID
|
Posted: Tue Apr 26, 2005 9:11 am Post subject: |
|
|
I just emerged powertweak using the wrapper and it looked like it was progressing normally to 41%.. which is where it stayed until the build finished
Quote: |
his requires that every .c file will be compiled, AFAIK not every package compiles every .c file, so it might not be accurate.
Some packages also does other things than compiling .c files.
How about .cpp files btw. ?
|
I hope you don't give up on the idea. God knows I wish for such a thing everytime I emerge something like kde
Would it be possible to determine the number of files being compiled after the makefiles were generated? Perhaps have a two line progress bar for batch and current?
Edit: Now that I think about it.... That doesn't seem possible.. at least not to work with all. Maybe it could someday be part of the ebuilds. The package maintainer could include a customized wrapper for the specific build.... you know, cuz they have nothing better to do (at least dating doesn't get in the way for the average programmer ...kidding ... kinda)
Do these avatars make the text wiggle, or am I having an acid flashback? _________________ Kris Edwards
kris edwards at g mail dot c0m
PGP
WWW |
|
Back to top |
|
|
Cagnulein l33t
Joined: 18 Sep 2003 Posts: 861 Location: Modena, Italy
|
Posted: Tue Apr 26, 2005 11:29 am Post subject: |
|
|
works fine here too, great job man |
|
Back to top |
|
|
GBob Tux's lil' helper
Joined: 13 Nov 2004 Posts: 110 Location: Portland, Oregon
|
Posted: Sun May 01, 2005 6:01 pm Post subject: |
|
|
GurliGebis wrote: | This requires that every .c file will be compiled, AFAIK not every package compiles every .c file, so it might not be accurate.
Some packages also does other things than compiling .c files.
How about .cpp files btw. ? |
It grabs .c*
elvisthedj wrote: | I just emerged powertweak using the wrapper and it looked like it was progressing normally to 41%.. which is where it stayed until the build finished |
I have a new version, but it requires a small change to /usr/lib/portage/emake, and while it doesn't get to 100%, it is a whole lot more accurate.
(It doesn't get to 100% due to buffering and such.)
Code: | #!/usr/bin/perl -w
############################################################
# File - emerge.pl
# Author - GBob
# Date - Wednesday, April 20, 2005
# E-Mail - Guardian.Bob@gmail.com
# Description - Wrapper for emerge, shows progress.
# Flags - See emerge
# Notes - Ask is done inside this code
###########################################################
use strict;
use Term::ANSIColor qw(:constants);
############################################################
# Function - yesno
# Date - Wednesday, April 20, 2005
# Input - Question to ask
# ReturnVal - 1 yes, 0 no, -1 unknown
# Description - Asks a question with a yes/no answer.
# The user's choice is then returned.
############################################################
sub yesno{
my $quest = shift;
print WHITE, BOLD, $quest, RESET;
print "[";
print BOLD GREEN, "Yes", RESET;
print "/";
print BOLD RED, "No", RESET;
print "] ";
select((select(STDOUT), $| = 1)[0]);
my $line=<STDIN>;
if($line =~ m/^yes$/i){
return 1;
}
if($line =~ m/^no$/i){
return 0;
}
if($line =~ m/^y$/i){
return 1;
}
if($line =~ m/^n$/i){
return 0;
}
return -1;
}
############################################################
# Function - askpack
# Date - Wednesday, April 20, 2005
# Input - command line options to use
# ReturnVal - 1 on continue
# Description - This function exits if the user doesn't
# want to merge, returns 1 if okay.
############################################################
sub askpack{
my $cmdline = shift;
my $child_pid;
$cmdline .= "-p";
if($child_pid = fork){
$SIG{INT}=sub{kill INT $child_pid};
waitpid($child_pid, 0);
$SIG{INT}='DEFAULT';
exit $? if($? != 0);
my $result;
while(($result=yesno("Do you want me to merge these packages? ")) == -1){}
if($result == 0){
exit;
}
}else{
die "cannot fork: $!" unless defined $child_pid;
exec((split(/ /, "/usr/bin/emerge ".$cmdline)));
}
return 1;
}
############################################################
# Function - status
# Date - Wednesday, April 20, 2005
# Input - none
# ReturnVal - string, status line
# Description - returns a string to print on the status
# line
############################################################
sub status{
my $FULL=`tail -n 2 /var/log/emerge.log | grep Compiling`;
$FULL =~ s/(.*)Compiling\/Merging \((.*)::.*$/$2/;
$FULL =~ s/(\([a-zA-Z].*\))\/\(.*\)/$1\/$2/;
chomp($FULL);
if($FULL eq ""){
return "";
}
return "" unless(-f "/tmp/emerge.cur.build");
my $CUR=$FULL;
if(! -f "/tmp/emerge.cur.build"){
$main::total=0;
$main::prog=0;
%main::linehash={};
}
$CUR=~s/(.*)\/(.*)/$2/;
my $TOT=`cat /tmp/emerge.cur.build | wc -l`;
if($TOT!=$main::total){
$main::total=$TOT;
$main::prog=0;
%main::linehash={};
open(FH,"</tmp/emerge.cur.build");
while(<FH>){
$main::linehash{$_}=0 unless defined $main::linehash{$_};
$main::linehash{$_}++;
}
return "";
}
my $var=shift;
if(defined $main::linehash{$var} && $main::linehash{$var}>0){
$main::prog++;
$main::linehash{$var}--;
}
my $PROG=$main::prog;
my $PER=0;
if($TOT!=0){
$PER = int( $PROG/$TOT * 100);
}
if($PER > 100){
$PER=100;
}
return "Currently Compiling Package: $FULL ($PER%)";
}
$main::total=0;
$main::prog=0;
my $pretend=0;
my $ask=0;
my $fetch=0;
my $line="";
for (@ARGV){
if(m/^--/i){
if(!m/--ask/){
$line .= $_." ";
}else{
$ask=1;
}
$pretend=1 if(m/--pretend/);
$fetch=1 if(m/--fetchonly/);
}elsif(m/^-[a-z]+/i){
$ask=1 if(m/a/);
$pretend=1 if(m/p/);
$fetch=1 if(m/f/);
$_=~s/a//;
$line.=$_." ";
}else{
$line.=$_." ";
}
}
if($pretend != 0){
exec((split(/ /, "/usr/bin/emerge ".$line)));
}
if($ask != 0){
askpack($line);
}
unlink("/tmp/emerge.cur.build");
my $clean=0;
if($fetch){
exec((split(/ /, "/usr/bin/emerge ".$line)));
}
print "Starting Fetching...\n";
my $fetch_start=0;
my $c_pid2=open(FH, "/usr/bin/emerge -f ".$line . " 2>&1 && echo \">>>\"|");
my $cid;
while(<FH>){
if($fetch_start==0){
if(m/^>>>/){
$fetch_start=1;
if($cid=fork){
$SIG{INT}=sub{kill $cid};
while(<FH>){}
waitpid($cid, 0);
$SIG{INT}='DEFAULT';
exit $? if($? != 0);
}else{
my $c_pid=open(PH, "/usr/bin/emerge ".$line . " 2>&1 |");
while(<PH>){
if(! -f "/tmp/emerge.cur.build"){
print "\r".(" " x 80)."\r" if(!$clean);
print $_;
$clean=0;
}else{
$clean=1;
print "\r".(" " x 80)."\r".$_, BLACK ON_WHITE status($_), RESET;
select((select(STDOUT), $| = 1)[0]);
}
}
print "\r".(" " x 80)."\r" if(!$clean);
close(PH);
exit $?;
}
}
}
} |
Making /usr/lib/portage/bin/emake:
Code: | #!/bin/bash
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-src/portage/bin/emake,v 1.9 2004/10/04 13:56:50 vapier Exp $
#
# emake: Supplies some default parameters to GNU make. At the moment the
# only parameter supplied is -jN, where N is a number of
# parallel processes that should be ideal for the running host
# (e.g. on a single-CPU machine, N=2). The MAKEOPTS variable
# is set in /etc/make.globals. We don't source
# /etc/make.globals here because emake is only called from an
# ebuild.
if [ -f /tmp/emerge.cur.build ]; then
make ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
else
make -n -i -w ${MAKEOPTS} ${EXTRA_EMAKE} "$@" 2>&1 | egrep "^g?make\[?" >> /tmp/emerge.cur.build
make -w ${MAKEOPTS} ${EXTRA_EMAKE} "$@" && rm /tmp/emerge.cur.build
fi
|
Oh and it does fetch in parallel. I'm hoping to add overall progress soon, but haven't gotten it quite yet. Also, this is by no means fool proof. Suggestions welcomed. _________________ rank[0]-=('n'-'d');
rank[3]-=('b'-'d');
It is better to say nothing and have people think your are an idiot,
Than open your mouth and remove all doubt. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|