[Aptitude-svn-commit] r4092 - in branches/aptitude-0.3/aptitude: . src

Daniel Burrows dburrows at costa.debian.org
Thu Sep 15 18:29:13 UTC 2005


Author: dburrows
Date: Thu Sep 15 18:29:10 2005
New Revision: 4092

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/download_list.cc
   branches/aptitude-0.3/aptitude/src/download_list.h
Log:
Add support for a more sensible overall progress bar in the face
of apt's useless progress information.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Thu Sep 15 18:29:10 2005
@@ -1,3 +1,13 @@
+2005-09-15  Daniel Burrows  <dburrows at debian.org>
+
+	* src/download_list.cc, src/download_list.h:
+
+	  Add support for a display mode in which no estimated time is
+	  provided and the progress bar assumes that all files have the
+	  same size; this will be useful for list updates (where apt
+	  kindly provides absolutely useless total-size information to the
+	  status object).
+
 2005-09-14  Daniel Burrows  <dburrows at debian.org>
 
 	* src/generic/resolver_manager.cc:

Modified: branches/aptitude-0.3/aptitude/src/download_list.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download_list.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/download_list.cc	Thu Sep 15 18:29:10 2005
@@ -9,6 +9,7 @@
 
 #include <generic/apt.h>
 #include <generic/config_signal.h>
+#include <generic/util.h>
 
 #include <apt-pkg/acquire-worker.h>
 #include <apt-pkg/acquire-item.h>
@@ -29,12 +30,12 @@
 
 using namespace std;
 
-download_list::workerinf::workerinf(const wstring &_msg, int _current, int _total)
+download_list::workerinf::workerinf(const wstring &_msg, unsigned long _current, unsigned long _total)
   :msg(_msg), current(_current), total(_total)
 {
 }
 
-download_list::workerinf::workerinf(const string &_msg, int _current, int _total)
+download_list::workerinf::workerinf(const string &_msg, unsigned long _current, unsigned long _total)
   :msg(transcode(_msg)), current(_current), total(_total)
 {
 }
@@ -102,11 +103,12 @@
 }
 				 
 
-download_list::download_list(slot0arg _abortslot, bool _display_messages)
+download_list::download_list(slot0arg _abortslot,
+			     bool _display_messages, bool _display_cumulative_progress)
   :start(0), sticky_end(true), cancelled(false), failed(false),
    abortslot(_abortslot), display_messages(_display_messages),
 
-   startx(0),
+   display_cumulative_progress(_display_cumulative_progress), startx(0),
 
    TotalItems(0), CurrentItems(0),
    CurrentCPS(0), TotalBytes(0), CurrentBytes(0)
@@ -176,27 +178,66 @@
 
   if((TotalBytes+TotalItems)>0)
     {
-      char progress_string[50]; // More'n enough chars.
-      unsigned long ETA=0;
-      if(CurrentCPS>0)
-	// Be careful!  CurrentCPS might be 0.
-	ETA=(unsigned long)((TotalBytes-CurrentBytes)/CurrentCPS);
-      // Straight from acqprogress.cc, that is..
-
-      barsize=int((double(width*(CurrentBytes+CurrentItems)))/(TotalBytes+TotalItems));
-      if(barsize>width)
-	barsize=width;
-
-      apply_style(get_style("Status"));
-      if(CurrentCPS>0)
-	snprintf(progress_string, 50, _(" [ %i%% ] (%sB/s, %s remaining)"), int(double((100.0*(CurrentBytes+CurrentItems)))/(TotalBytes+TotalItems)), SizeToStr(CurrentCPS).c_str(), TimeToStr(ETA).c_str());
-      else if(CurrentBytes>0 || CurrentItems>0)
-	snprintf(progress_string, 50, _(" [ %i%% ] (stalled)"), int(double((100.0*(CurrentBytes+CurrentItems)))/(TotalBytes+TotalItems)));
+      string progress_string;
+
+      if(display_cumulative_progress)
+	{
+	  unsigned long ETA = 0;
+
+	  if(CurrentCPS > 0)
+	    ETA=(unsigned long)((TotalBytes-CurrentBytes)/CurrentCPS);
+
+	  double fraction_complete = (double(CurrentBytes + CurrentItems))/(TotalBytes + TotalItems);
+
+	  // Clamp to [0,1]
+	  if(fraction_complete > 1)
+	    fraction_complete = 1;
+	  if(fraction_complete < 0)
+	    fraction_complete = 0;
+
+	  barsize = int(width * fraction_complete);
+
+	  apply_style(get_style("Status"));
+
+	  if(CurrentCPS > 0)
+	    progress_string = ssprintf(_(" [ %i%% ] (%sB/s, %s remaining)"), int(100.0 * fraction_complete), SizeToStr(CurrentCPS).c_str(), TimeToStr(ETA).c_str());
+	  else if(CurrentBytes>0 || CurrentItems>0)
+	    progress_string = ssprintf(_(" [ %i%% ] (stalled)"), int(100.0 * fraction_complete));
+	  else
+	    progress_string = ssprintf(_(" [ %i%% ]"), int(100.0 * fraction_complete));
+	}
       else
-	snprintf(progress_string, 50, _(" [ %i%% ]"), int(double((100.0*(CurrentBytes+CurrentItems)))/(TotalBytes+TotalItems)));
+	{
+	  const unsigned int active_workers = workers.size();
+
+	  unsigned long active_current = 0, active_total = 0;
+	  for(workerlist::const_iterator i = workers.begin();
+	      i != workers.end(); ++i)
+	    {
+	      active_current += i->current;
+	      active_total   += i->total;
+	    }
+
+	  // The contribution of the active workers to the completion
+	  // status.
+	  double active_complete_fraction
+	    = ((double) active_current) / ((double) active_total);
+
+	  double fraction_complete
+	    = (((double) CurrentItems) + active_workers * active_complete_fraction)
+	    / ((double) TotalItems);
+	  if(fraction_complete > 1)
+	    fraction_complete = 1;
+	  if(fraction_complete < 0)
+	    fraction_complete = 0;
+
+
+	  barsize = int(width * fraction_complete);
+	  progress_string = ssprintf(_(" [ %i%% ]"), int(100.0 * fraction_complete));
+	}
 
 
-      output+=transcode(progress_string);
+      output += transcode(progress_string);
     }
 
   show_string_as_progbar(0,

Modified: branches/aptitude-0.3/aptitude/src/download_list.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download_list.h	(original)
+++ branches/aptitude-0.3/aptitude/src/download_list.h	Thu Sep 15 18:29:10 2005
@@ -23,10 +23,10 @@
   struct workerinf
   {
     std::wstring msg;
-    int current,total;
+    unsigned long current, total;
 
-    workerinf(const std::wstring &_msg, int _current, int _total);
-    workerinf(const std::string &_msg, int _current, int _total);
+    workerinf(const std::wstring &_msg, unsigned long _current, unsigned long _total);
+    workerinf(const std::string &_msg, unsigned long _current, unsigned long _total);
   };
 
   typedef std::pair<std::wstring, style> msg;
@@ -61,6 +61,16 @@
   // Will we display things other than the current workers?
   bool display_messages;
 
+  /** Used to hack around the utter braindeadness of apt's download
+   *  status reporting.  If this is \b true, we assume that there is a
+   *  meaningful estimate of the total download size.  Otherwise, we
+   *  calculate our own estimate by assuming that each file takes an
+   *  equal percentage of the time; in addition, the time indicator is
+   *  hidden (since its main effect in this case is to trigger bug
+   *  reports).
+   */
+  bool display_cumulative_progress;
+
   // The starting offset to display messages with.
   std::string::size_type startx;
 
@@ -86,13 +96,15 @@
   void paint(const style &st);
   bool handle_key(const key &k);
 
-  download_list(slot0arg _abortslot=NULL,
-		bool _display_messages=true);
+  download_list(slot0arg _abortslot = NULL,
+		bool _display_messages = true,
+		bool _display_cumulative_progress = true);
 public:
   static ref_ptr<download_list> create(slot0arg abortslot = NULL,
-				       bool display_messages = true)
+				       bool display_messages = true,
+				       bool display_cumulative_progress = true)
   {
-    return new download_list(abortslot, display_messages);
+    return new download_list(abortslot, display_messages, display_cumulative_progress);
   }
 
   void MediaChange(std::string media, std::string drive,



More information about the Aptitude-svn-commit mailing list