portupgrade small hacks

Hello everyone.
First, sorry for my bad english.
I use FreeBSD as desktop more than 3 years. Also, i need to use Gentoo Linux sometimes.
I find some of gentoo's portage some features that interesting and think it's would be great to see similar in FreeBSD ports.
  1. Print information about currently upgrading port in title of terminal.
    I upgrading my ports with portupgrade -a, and i think it's would be great to see status of overall upgrade (ex. 14/17 - "upgrading 14th port of 17 that's needs upgrade) and name of currently upgrading port.
    I don't know ruby (portupgrade is writing on it), so currently i only write package name in title. But i think it's need some corrections (normalize title after break upgrade and ended upgrade). This is my small patch for installed portupgrade:
    Code:
    --- orig_portupgrade	2009-10-14 12:50:42.000000000 +0400
    +++ portupgrade	2009-10-14 12:56:27.000000000 +0400
    @@ -524,6 +524,11 @@
     
         $interrupt_proc = result_proc
     
    +    $isterm = false
    +    if `echo $TERM`.chomp.eql? "xterm"
    +	$isterm = true
    +    end
    +
         begin
           init_global
           init_pkgtools_global
    @@ -798,20 +803,20 @@
           exit 64
         end
     
    -    ntasks = upgrade_tasks.size + install_tasks.size
    -    ctask = 0
    +    $ntasks = upgrade_tasks.size + install_tasks.size
    +    $ctask = 0
     
         $current_pkgname = ''
         install_tasks.each do |origin| 
    -      ctask += 1
    -      setproctitle('[%d/%d] %s', ctask, ntasks, origin)
    +      $ctask += 1
    +      setproctitle('[%d/%d] %s', $ctask, $ntasks, origin)
           do_install(origin)
           progress_message "** Install tasks #{install_tasks.length}: #{$results.summary}" if $emit_summaries || $verbose
         end
     
         upgrade_tasks.each do |pkgname|
    -      ctask += 1
    -      setproctitle('[%d/%d] %s', ctask, ntasks, pkgname)
    +      $ctask += 1
    +      setproctitle('[%d/%d] %s', $ctask, $ntasks, pkgname)
           $current_pkgname = pkgname
           do_upgrade(pkgname)
           progress_message "** Upgrade tasks #{upgrade_tasks.length}: #{$results.summary}" if $emit_summaries || $verbose
    @@ -823,6 +828,29 @@
       stty_sane unless $results.empty?
     
       timer_end("Session")
    +  settermtitle(-1,nil,nil,nil,nil,nil)
    +end
    +
    +def settermtitle(t,cur,tot,old,new,orig)
    +	if $isterm 
    +		case t
    +			when -1
    +				msg = "ended"
    +			when 1
    +				msg = "[ #{cur} / #{tot} ]: Fetching the distfile(s) for '#{new}' (#{orig})"
    +			when 2
    +				msg = "[ #{cur} / #{tot} ]: Upgrading '#{old}' to '#{new}' (#{orig})"
    +			when 3
    +				msg = "[ #{cur} / #{tot} ]: Downgrading '#{old}' to '#{new}' (#{orig})"
    +			when 4
    +				msg = "[ #{cur} / #{tot} ]: Reinstalling '#{old}' (#{orig})"
    +			when 5
    +				msg = "[ #{cur} / #{tot} ]: Installing '#{new}' from a package"
    +			when 6
    +				msg = "[ #{cur} / #{tot} ]: Installing '#{new}' from a port (#{orig})"
    +		end
    +		print "\033]0;portupgrade" + msg + "\007"
    +	end
     end
     
     # Returns:
    @@ -1349,17 +1377,21 @@
       if $fetch_only
         timer_start(time_key = "Fetch for #{origin}")
         progress_message "Fetching the distfile(s) for '#{newpkgname}' (#{origin})"
    +	settermtitle(1,$ctask,$ntasks,nil,newpkgname,origin)
       else
         case service
         when :upgrade
           time_key = "Upgrade of #{origin}"
           msg = "Upgrading '#{oldpkgname}' to '#{newpkgname}' (#{origin})"
    +	  settermtitle(2,$ctask,$ntasks,oldpkgname,newpkgname,origin)
         when :downgrade
           time_key = "Downgrade of #{origin}"
           msg = "Downgrading '#{oldpkgname}' to '#{newpkgname}' (#{origin})"
    +	  settermtitle(3,$ctask,$ntasks,oldpkgname,newpkgname,origin)
         when :reinstall
           time_key = "Reinstallation of #{origin}"
           msg = "Reinstalling '#{oldpkgname}' (#{origin})"
    +	  settermtitle(4,$ctask,$ntasks,oldpkgname,nil,origin)
         end
     
         if have_package
    @@ -1611,8 +1643,10 @@
     
       if have_package
         progress_message "Installing '#{newpkgname}' from a package"
    +	settermtitle(5,$ctask,$ntasks,nil,newpkgname,nil)
       else
         progress_message "Installing '#{newpkgname}' from a port (#{origin})"
    +	settermtitle(6,$ctask,$ntasks,nil,newpkgname,origin)
       end
     
       if $noexecute

  2. Similar as in "1", but for all ports system, for new installing ports with all depends via "cd /usr/ports/blah && make install clean"

  3. Downloading distfiles in background. For example, portupgrade -a - first port rebuilding and the second fetch distfiles in same time. Or similar with depends for new port installing.


If you are finding it's interesting and would like to talk about it's realisation, please write here (in this topic) or contact me dirrectly via:
jabber: xa (at) nobody.su
mail: same as jabber id

Or if you think these ideas are insane and unnecessary - please write why you think so. Thank you.
 
I rewrite my patch, and now it realized point 1 from first post almost entirely (need add check is user's terminal is Xterm
compatible to print title).
I don't write on Ruby never early, so if you find any mistakes or
propose an optimization in patch - please, write me.
Now i will start to write background-fetch feature.

Code:
--- orig_portupgrade	2009-08-03 19:05:28.000000000 +0400
+++ portupgrade	2009-08-08 12:29:31.000000000 +0400
@@ -798,20 +798,20 @@
       exit 64
     end
 
-    ntasks = upgrade_tasks.size + install_tasks.size
-    ctask = 0
+    $ntasks = upgrade_tasks.size + install_tasks.size
+    $ctask = 0
 
     $current_pkgname = ''
     install_tasks.each do |origin| 
-      ctask += 1
-      setproctitle('[%d/%d] %s', ctask, ntasks, origin)
+      $ctask += 1
+      setproctitle('[%d/%d] %s', $ctask, $ntasks, origin)
       do_install(origin)
       progress_message "** Install tasks #{install_tasks.length}: #{$results.summary}" if $emit_summaries || $verbose
     end
 
     upgrade_tasks.each do |pkgname|
-      ctask += 1
-      setproctitle('[%d/%d] %s', ctask, ntasks, pkgname)
+      $ctask += 1
+      setproctitle('[%d/%d] %s', $ctask, $ntasks, pkgname)
       $current_pkgname = pkgname
       do_upgrade(pkgname)
       progress_message "** Upgrade tasks #{upgrade_tasks.length}: #{$results.summary}" if $emit_summaries || $verbose
@@ -823,6 +823,27 @@
   stty_sane unless $results.empty?
 
   timer_end("Session")
+  settermtitle(-1,nil,nil,nil,nil,nil)
+end
+
+def settermtitle(t,cur,tot,old,new,orig)
+	case t
+	when -1
+		msg = "portupgrade ended"
+	when 1
+		msg = "portupgrade [ #{cur} / #{tot} ]: Fetching the distfile(s) for '#{new}' (#{orig})"
+	when 2
+		msg = "portupgrade [ #{cur} / #{tot} ]: Upgrading '#{old}' to '#{new}' (#{orig})"
+	when 3
+		msg = "portupgrade [ #{cur} / #{tot} ]: Downgrading '#{old}' to '#{new}' (#{orig})"
+	when 4
+		msg = "portupgrade [ #{cur} / #{tot} ]: Reinstalling '#{old}' (#{orig})"
+	when 5
+		msg = "portupgrade [ #{cur} / #{tot} ]: Installing '#{new}' from a package"
+	when 6
+		msg = "portupgrade [ #{cur} / #{tot} ]: Installing '#{new}' from a port (#{orig})"
+	end
+	print "\033]0;" + msg + "\007"
 end
 
 # Returns:
@@ -1349,17 +1370,21 @@
   if $fetch_only
     timer_start(time_key = "Fetch for #{origin}")
     progress_message "Fetching the distfile(s) for '#{newpkgname}' (#{origin})"
+	settermtitle(1,$ctask,$ntasks,nil,newpkgname,origin)
   else
     case service
     when :upgrade
       time_key = "Upgrade of #{origin}"
       msg = "Upgrading '#{oldpkgname}' to '#{newpkgname}' (#{origin})"
+	  settermtitle(2,$ctask,$ntasks,oldpkgname,newpkgname,origin)
     when :downgrade
       time_key = "Downgrade of #{origin}"
       msg = "Downgrading '#{oldpkgname}' to '#{newpkgname}' (#{origin})"
+	  settermtitle(3,$ctask,$ntasks,oldpkgname,newpkgname,origin)
     when :reinstall
       time_key = "Reinstallation of #{origin}"
       msg = "Reinstalling '#{oldpkgname}' (#{origin})"
+	  settermtitle(4,$ctask,$ntasks,oldpkgname,nil,origin)
     end
 
     if have_package
@@ -1611,8 +1636,10 @@
 
   if have_package
     progress_message "Installing '#{newpkgname}' from a package"
+	settermtitle(5,$ctask,$ntasks,nil,newpkgname,nil)
   else
     progress_message "Installing '#{newpkgname}' from a port (#{origin})"
+	settermtitle(6,$ctask,$ntasks,nil,newpkgname,origin)
   end
 
   if $noexecute
 
Good!

My english is not good just like you. :)

And thank you for the contribution.

Sometimes I also feel the ports system is rough than Gentoo's portage, but I like FreeBSD than Gentoo.
 
Background fetching postponed for an indefinite period (most likely I was not going to develop it). But i create very small fix for my previous patch: now, portupgrade check is user's TERM is xterm compatible and only if it is - print messages in title.
Here is patch to apply to virgin portupgrade from ports:
Code:
--- orig_portupgrade	2009-10-14 12:50:42.000000000 +0400
+++ portupgrade	2009-10-14 12:56:27.000000000 +0400
@@ -524,6 +524,11 @@
 
     $interrupt_proc = result_proc
 
+    $isterm = false
+    if `echo $TERM`.chomp.eql? "xterm"
+	$isterm = true
+    end
+
     begin
       init_global
       init_pkgtools_global
@@ -798,20 +803,20 @@
       exit 64
     end
 
-    ntasks = upgrade_tasks.size + install_tasks.size
-    ctask = 0
+    $ntasks = upgrade_tasks.size + install_tasks.size
+    $ctask = 0
 
     $current_pkgname = ''
     install_tasks.each do |origin| 
-      ctask += 1
-      setproctitle('[%d/%d] %s', ctask, ntasks, origin)
+      $ctask += 1
+      setproctitle('[%d/%d] %s', $ctask, $ntasks, origin)
       do_install(origin)
       progress_message "** Install tasks #{install_tasks.length}: #{$results.summary}" if $emit_summaries || $verbose
     end
 
     upgrade_tasks.each do |pkgname|
-      ctask += 1
-      setproctitle('[%d/%d] %s', ctask, ntasks, pkgname)
+      $ctask += 1
+      setproctitle('[%d/%d] %s', $ctask, $ntasks, pkgname)
       $current_pkgname = pkgname
       do_upgrade(pkgname)
       progress_message "** Upgrade tasks #{upgrade_tasks.length}: #{$results.summary}" if $emit_summaries || $verbose
@@ -823,6 +828,29 @@
   stty_sane unless $results.empty?
 
   timer_end("Session")
+  settermtitle(-1,nil,nil,nil,nil,nil)
+end
+
+def settermtitle(t,cur,tot,old,new,orig)
+	if $isterm 
+		case t
+			when -1
+				msg = "ended"
+			when 1
+				msg = "[ #{cur} / #{tot} ]: Fetching the distfile(s) for '#{new}' (#{orig})"
+			when 2
+				msg = "[ #{cur} / #{tot} ]: Upgrading '#{old}' to '#{new}' (#{orig})"
+			when 3
+				msg = "[ #{cur} / #{tot} ]: Downgrading '#{old}' to '#{new}' (#{orig})"
+			when 4
+				msg = "[ #{cur} / #{tot} ]: Reinstalling '#{old}' (#{orig})"
+			when 5
+				msg = "[ #{cur} / #{tot} ]: Installing '#{new}' from a package"
+			when 6
+				msg = "[ #{cur} / #{tot} ]: Installing '#{new}' from a port (#{orig})"
+		end
+		print "\033]0;portupgrade" + msg + "\007"
+	end
 end
 
 # Returns:
@@ -1349,17 +1377,21 @@
   if $fetch_only
     timer_start(time_key = "Fetch for #{origin}")
     progress_message "Fetching the distfile(s) for '#{newpkgname}' (#{origin})"
+	settermtitle(1,$ctask,$ntasks,nil,newpkgname,origin)
   else
     case service
     when :upgrade
       time_key = "Upgrade of #{origin}"
       msg = "Upgrading '#{oldpkgname}' to '#{newpkgname}' (#{origin})"
+	  settermtitle(2,$ctask,$ntasks,oldpkgname,newpkgname,origin)
     when :downgrade
       time_key = "Downgrade of #{origin}"
       msg = "Downgrading '#{oldpkgname}' to '#{newpkgname}' (#{origin})"
+	  settermtitle(3,$ctask,$ntasks,oldpkgname,newpkgname,origin)
     when :reinstall
       time_key = "Reinstallation of #{origin}"
       msg = "Reinstalling '#{oldpkgname}' (#{origin})"
+	  settermtitle(4,$ctask,$ntasks,oldpkgname,nil,origin)
     end
 
     if have_package
@@ -1611,8 +1643,10 @@
 
   if have_package
     progress_message "Installing '#{newpkgname}' from a package"
+	settermtitle(5,$ctask,$ntasks,nil,newpkgname,nil)
   else
     progress_message "Installing '#{newpkgname}' from a port (#{origin})"
+	settermtitle(6,$ctask,$ntasks,nil,newpkgname,origin)
   end
 
   if $noexecute
 
Nice patch and idea. But any contribution made for FreeBSD's source code is based on the concept of "more performace" or "more reliable". I mean, a "more friendly" patch is not very welcome here because of some "Historical"\"Legendary"\"Endless" problems..�e
 
Well, portupgrade doesn't belong to 'FreeBSD's source code', as it is a port, not part of the base system. And patches to portupgrade are unlikely to have any effect here. Better ping the port maintainer and suggest the patch to him. Run 'make maintainer' in the port directory or look in the Makefile.
 
I send mail to maintainer with offer to apply this patch on 14.10.2009 and now i'm waiting answer.
p.s. how i understand, now portupgrade maintainer is freebsd ruby group (freebsd wiki says)
 
Back
Top