[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] cancellable apt-setup with progress display



I've tested and fixed up yesterday's patch. I think this works rather
well, just a few issues:

* debconf-apt-progress only advances the bar 15% while downloading,
  I'll de-hardcode that later.
* 50mirror validates a mirror and then adds a deb-src line at the end.
  The progress bar for downloading/validating that line isn't allowed to
  advance since it's already advanced all the way.
* Needs svn debconf, which I won't upload for at least another 4 days,
  since Frans's patch needs unstable debconf to propigate testing.
* It's too much fun to try farflung mirrors, cancel, and change to
  another one. Works entirely too well. ;-)

-- 
see shy jo
Index: debian/changelog
===================================================================
--- debian/changelog	(revision 50009)
+++ debian/changelog	(working copy)
@@ -1,3 +1,21 @@
+apt-setup (1:0.32) UNRELEASED; urgency=low
+
+  * Allocate 100 steps on the progress bar for each generator, and
+    set the progress absolutely to the next position after calling each
+    generator. This allows generators to step the progress bar up to 100
+    steps if desired.
+  * Export PROGRESS_FROM and PROGRESS_TO to generators, giving the
+    starting and ending progress bar position for that generator. This can
+    be used by generators that need an absolute progress bar position for
+    calling debconf-apt-progress.
+  * apt-setup-verify: Use debconf-apt-progress and add a way for generators
+    to specify how it should advance the progress bar.
+  * Allow the progress bar to be canceled (needs debconf 1.5.17 for proper
+    operation).
+  * 50mirror: Call choose-mirror -n to avoid trashing the progress bar.
+
+ -- Joey Hess <joeyh@debian.org>  Fri, 02 Nov 2007 16:33:10 -0400
+
 apt-setup (1:0.31) unstable; urgency=low
 
   * Correct inverted test for CD sources, which caused it to skip verification
Index: apt-setup
===================================================================
--- apt-setup	(revision 50009)
+++ apt-setup	(working copy)
@@ -2,7 +2,6 @@
 set -e
 
 . /usr/share/debconf/confmodule
-db_capb backup
 
 gendir=/usr/lib/apt-setup/generators
 
@@ -34,14 +33,19 @@
 }
 
 gencount=`ls "$gendir"/* | wc -l`
-db_progress START 0 $gencount apt-setup/progress/title
+db_capb backup progresscancel
+db_progress START 0 $(expr "$gencount" \* 100) apt-setup/progress/title
 
+PROGRESS_FROM=0
+PROGRESS_TO=100
+export PROGRESS_FROM
+export PROGRESS_TO
 for generator in $gendir/*; do
 	base=$(basename $generator | sed 's/[0-9]*//')
 	base="${base%%.*}"
 	if ! db_progress INFO apt-setup/progress/$base; then
 		db_subst apt-setup/progress/fallback SCRIPT "$base"
-		db_progress INFO apt-setup/progress/fallback
+		db_progress INFO apt-setup/progress/fallback || true
 	fi
 	
 	tmp=$($chroot $ROOT tempfile)
@@ -63,6 +67,7 @@
 		log "$generator backed up"
 		rm -f $ROOT$tmp $ROOT/etc/apt/sources.list.new
 		db_progress STOP
+		db_capb backup
 		exit 10
 		;;
 	    *)
@@ -70,7 +75,10 @@
 		;;
 	esac
 	rm -f $ROOT$tmp
-	db_progress STEP 1
+
+	db_progress SET $PROGRESS_TO || true
+	PROGRESS_FROM=$PROGRESS_TO
+	PROGRESS_TO=$(expr $PROGRESS_FROM + 100)
 done
 mv $ROOT/etc/apt/sources.list.new $ROOT/etc/apt/sources.list
 if [ -s $ROOT/etc/apt/apt.conf.new ]; then
@@ -80,3 +88,4 @@
 fi
 
 db_progress STOP
+db_capb backup
Index: apt-setup-verify
===================================================================
--- apt-setup-verify	(revision 50009)
+++ apt-setup-verify	(working copy)
@@ -12,16 +12,27 @@
 fi
 
 file="$1"
-saveto="$2"
+if [ "$2" != "--" ]; then
+	saveto="$2"
+fi
 
+while [ -n "$1" ] && [ "$1" != "--" ]; do
+	shift 1
+done
+if [ "$1" = "--" ]; then
+	shift 1
+fi
+
 logoutput=""
 if [ "$CATCHLOG" ]; then
 	logoutput="log-output -t apt-setup"
 fi
 
 chroot=
+intarget=
 if [ "$ROOT" ]; then
 	chroot=chroot
+	intarget=in-target
 fi
 
 saveline () {
@@ -32,15 +43,20 @@
 
 valid () {
 	line="$1"
+	shift 1
 
 	[ "${line%%:*}" != "deb cdrom" ] || return 0
 
 	tmp=$($chroot $ROOT tempfile)
 	echo "$line" > $ROOT$tmp
-	
-	if $logoutput $chroot $ROOT apt-get -o APT::Get::List-Cleanup=false \
-		-o Dir::Etc::sourcelist=$tmp $ASV_TIMEOUT update
-	then
+	code=0
+	$logoutput $intarget debconf-apt-progress \
+		"${@:---no-progress}" --logstderr -- \
+		apt-get -o APT::Get::List-Cleanup=false \
+			-o Dir::Etc::sourcelist=$tmp $ASV_TIMEOUT update || code=$?
+	if [ "$code" == 30 ]; then
+		exit 30 # canceled
+	elif [ "$code" == 0 ]; then
 		rm -f $ROOT$tmp
 	else
 		rm -f $ROOT$tmp
@@ -65,13 +81,22 @@
 			saveline ""
 		fi
 
-		if [ -z "$NOTEST" ] && valid "$line"; then
+		if [ -z "$NOTEST" ] && valid "$line" "$@"; then
 			gooditems=$(expr "$gooditems" + 1)
 			saveline "$line"
 		else
 			saveline "# Line commented out by installer because it failed to verify:"
 			saveline "#$line"
 		fi
+		
+		# shift away remaining options to avoid passing them
+		# to debconf-apt-progress a second time.
+		while [ -n "$1" ] && [ "$1" != "--" ]; do
+			shift 1
+		done
+		if [ "$1" = "--" ]; then
+			shift 1
+		fi
 	else
 		# Ignore leading empty lines
 		if [ $items != 0 ] || [ "$line" ]; then
Index: generators/50mirror
===================================================================
--- generators/50mirror	(revision 50009)
+++ generators/50mirror	(working copy)
@@ -184,7 +184,7 @@
 
 	echo "deb $protocol://$hostname$directory $codename $dists" > $file
 	
-	if apt-setup-verify $file; then
+	if apt-setup-verify $file -- --from $PROGRESS_FROM --to $PROGRESS_TO; then
 		done=1
 	else
 		db_set apt-setup/mirror/error Retry
@@ -192,7 +192,7 @@
 		db_go || exit 10
 		db_get apt-setup/mirror/error
 		if [ "$RET" = "Change mirror" ]; then
-			choose-mirror || true
+			choose-mirror -n || true
 		elif [ "$RET" = Ignore ]; then
 			exit 1
 		fi
Index: generators/91security
===================================================================
--- generators/91security	(revision 50009)
+++ generators/91security	(working copy)
@@ -36,7 +36,7 @@
 else
 	CODE=0
 	export ASV_TIMEOUT="-o Acquire::http::Timeout=30"
-	if ! apt-setup-verify $file; then
+	if ! apt-setup-verify $file -- --from $PROGRESS_FROM --to $PROGRESS_TO; then
 		db_subst apt-setup/service-failed HOST "$host"
 		db_input critical apt-setup/service-failed || true
 		if ! db_go; then
Index: generators/92volatile
===================================================================
--- generators/92volatile	(revision 50009)
+++ generators/92volatile	(working copy)
@@ -42,7 +42,7 @@
 else
 	CODE=0
 	export ASV_TIMEOUT="-o Acquire::http::Timeout=30"
-	if ! apt-setup-verify $file; then
+	if ! apt-setup-verify $file -- --from $PROGRESS_FROM --to $PROGRESS_TO; then
 		db_subst apt-setup/service-failed HOST "$host"
 		db_input critical apt-setup/service-failed || true
 		if ! db_go; then
Index: README
===================================================================
--- README	(revision 50009)
+++ README	(working copy)
@@ -6,11 +6,12 @@
 (and comments) to.
 
 After the generator finishes writing the file, apt-setup-verify will be run
-on it to verify that each line of the sources sources works, and it will be
+on it to verify that each line of the sources works, and it will be
 added to the sources.list. Generators can also run apt-setup-verify
 themselves and do their own error recovery if it fails. apt-setup-verify
 tests each line of the file and comments out lines that do not work, and
-exits nonzero if all deb and deb-src lines in the file failed.
+exits zero if all deb and deb-src lines in the file are ok, 30 if the
+verification process was canceled, and otherwise nonzero on error.
 
 Generators should add both "deb" lines and corresponding
 deb-src lines to the sources.list. apt-setup-verify will handle commenting
@@ -25,6 +26,17 @@
 progress template name, so that different scripts that share the same
 purpose can easily be written.
 
+Generators can advance the progress bar from PROGRESS_FROM up to
+PROGRESS_TO, or it will be moved to the next step before the next
+generator is started.
+
+apt-setup-verify runs apt-get update inside debconf-apt-progress, to update
+the progress bar with apt progress information. By default,
+debconf-apt-progress is not allowed to move the progress bar. To override
+this, pass apt-setup-verify options after "--"; these options will be
+passed on to debconf-apt-progress. For example:
+	apt-setup-verify file -- --from 1 --to 100
+
 Note that apt-setup and its generators may be run against some other system
 in a chroot. (i.e., when installing Debian.) If apt-setup is running this
 way, then ROOT will be set to the root of the chroot that it is acting on

Attachment: signature.asc
Description: Digital signature


Reply to: