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

Re: status bars during base download



On Wed, Aug 08, 2001 at 09:14:44PM -0400, Adam Di Carlo wrote:
> 
> Partial work was done to have a status bar which flows across as we
> download packages.  'debootstrap' apparently does indicate between
> each package how many bytes of the total have been downloaded.
> 
> Would be nice to finish that off -- right now, it's very annoying
> debug spam.  If we can't get it done, we should at least not show the
> raw output (XXX  YYY ...) on the screen, flashing on and off...

Please can someone look over this?  I've never done any newt programming
until a couple of hours ago.  Works for me, but

1. I havn't checked how it looks on serial console yet (should be
   much better as there will be less screen redrawing)
2. The progress bar hits 100% after download completes, and then
   sits there while the extracting/configuring phase runs, which
   looks a little odd.
3. Progress bar doesn't move very smoothly, mainly because libc6
   is so much bigger than other pkgs.
4. It's a shame the text with filename doesn't fit on one line,
   might be worth triming the 'Retrieving' lines somehow so we get
   "Retreiving ...foo/bar/wiz/thingy_3.4.5_ia64.deb"
5. Maybe wants 'EB_RESET call to reinitialise things for when you
   restart the download after a failure.

Richard



Index: utilities/dbootstrap/extract_base.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/extract_base.c,v
retrieving revision 1.54
diff -u -r1.54 extract_base.c
--- utilities/dbootstrap/extract_base.c	2001/07/12 11:16:08	1.54
+++ utilities/dbootstrap/extract_base.c	2001/08/09 20:20:34
@@ -19,6 +19,7 @@
 #include <signal.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <newt.h>
 
 char *base_filenames[] = { "base12", "base14", NULL };
 
@@ -73,6 +74,60 @@
  */ 
 
 
+#define EB_OPEN		0
+#define EB_CLOSE	1
+#define EB_UPDATE	2
+
+static void
+eb_update(int action, char *txt)
+{
+  static newtComponent tx = NULL, scale = NULL, f = NULL;
+  static int cur = 0, max = 62;
+  static char last_txt[130];
+
+  switch (action) {
+  case EB_OPEN:
+    {
+      newtCenteredWindow(72, 8, "Please Wait");
+      f = newtForm(NULL, NULL, 0);
+      tx = newtTextbox(1, 1, 71, 4, NEWT_FLAG_WRAP);
+      newtTextboxSetText(tx, last_txt);
+      scale = newtScale(4, 6, 62, 62);
+      newtFormAddComponents(f, tx, scale, NULL);
+      newtDrawForm(f);
+      newtScaleSet(scale, cur * 62 / max);
+      newtRefresh();
+    }
+    break;
+  case EB_CLOSE:
+    {
+      newtPopWindow();
+      newtFormDestroy(f);
+    }
+    break;
+  case EB_UPDATE:
+    {
+      if (txt[0] == 'P' && txt[1] == ':') {
+        sscanf(txt+3, "%d %d", &cur, &max);
+        if (cur > max)
+          cur = max;
+        newtScaleSet(scale, cur * 62 / max);
+      }
+      else if (strlen(txt) > 3 && txt[1] == ':') {
+        strncpy(last_txt, txt+3, 128);
+        newtTextboxSetText(tx, last_txt);
+      }
+      else {
+        strncpy(last_txt, txt, 128);
+        newtTextboxSetText(tx, last_txt);
+      }
+      newtDrawForm(f);
+      newtRefresh();
+    }
+  }
+}
+
+
 /*
    execute 'debootstrap'
    
@@ -138,39 +193,29 @@
 	return -1;
     }
     
-    pleaseWaitBox(_("Calling debootstrap."));
+    eb_update(EB_OPEN, NULL);
 
     while ( (ptr = fgets(buf, sizeof(buf), ifp)))
     {
-	boxPopWindow();
-
 	if (ptr[1] == ':')
 	{
 	    switch (ptr[0]){
-		case 'I':
-		    {
-			pleaseWaitBox(ptr+3);
-			break;
-		    }
 		case 'W':
 		    {
+			eb_update(EB_CLOSE, NULL);
 			problemBox(ptr+3, _("Warning"));
-			pleaseWaitBox(_("Continuing"));
+			eb_update(EB_OPEN, NULL);
 			break;
 		    }
 		case 'E':
 		    {
+			eb_update(EB_CLOSE, NULL);
 			problemBox(ptr+3, _("Error"));
 			return -1;
 		    }
-		case 'P':
-		    {
-			/* FIXME: make a progress bar */
-			pleaseWaitBox(ptr+3);
-			break;
-		    }
 		case '?':
 		    {
+			eb_update(EB_CLOSE, NULL);
 			/* ?: bool Please just tell me: yes, or no? */
 			if (strncmp(ptr+3, "bool", strlen("bool"))) {
 			    if ( (yesNoBox(ptr+8, _("Question")) == -1)) 
@@ -178,19 +223,22 @@
 			    else
 				fwrite("yes", sizeof(char), strlen("yes"), ofp);
 			}
+			eb_update(EB_OPEN, NULL);
 			break;
 		    }
+		case 'I':
+		case 'P':
 		default:
 		    {
-			pleaseWaitBox(ptr);
+			eb_update(EB_UPDATE, ptr);
 		    }
 	    }
 	}
 	else
-	    pleaseWaitBox(ptr);
+	    eb_update(EB_UPDATE, ptr);
     }
    
-    boxPopWindow();
+    eb_update(EB_CLOSE, NULL);
 
     if (waitpid(pid, &status, WNOHANG)  && (WIFEXITED(status) != 0 ))
     {



Reply to: