]>
git.saurik.com Git - apt.git/blob - cmdline/acqprogress.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acqprogress.cc,v 1.21 2001/02/20 07:03:17 jgg Exp $
4 /* ######################################################################
6 Acquire Progress - Command line progress meter
8 ##################################################################### */
10 // Include files /*{{{*/
11 #include "acqprogress.h"
12 #include <apt-pkg/acquire-item.h>
13 #include <apt-pkg/acquire-worker.h>
14 #include <apt-pkg/strutl.h>
15 #include <apt-pkg/error.h>
23 // AcqTextStatus::AcqTextStatus - Constructor /*{{{*/
24 // ---------------------------------------------------------------------
26 AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth
,unsigned int Quiet
) :
27 ScreenWidth(ScreenWidth
), Quiet(Quiet
)
31 // AcqTextStatus::Start - Downloading has started /*{{{*/
32 // ---------------------------------------------------------------------
34 void AcqTextStatus::Start()
36 pkgAcquireStatus::Start();
41 // AcqTextStatus::IMSHit - Called when an item got a HIT response /*{{{*/
42 // ---------------------------------------------------------------------
44 void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc
&Itm
)
50 cout
<< '\r' << BlankLine
<< '\r';
52 cout
<< _("Hit ") << Itm
.Description
;
53 if (Itm
.Owner
->FileSize
!= 0)
54 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
59 // AcqTextStatus::Fetch - An item has started to download /*{{{*/
60 // ---------------------------------------------------------------------
61 /* This prints out the short description and the expected size */
62 void AcqTextStatus::Fetch(pkgAcquire::ItemDesc
&Itm
)
65 if (Itm
.Owner
->Complete
== true)
74 cout
<< '\r' << BlankLine
<< '\r';
76 cout
<< _("Get:") << Itm
.Owner
->ID
<< ' ' << Itm
.Description
;
77 if (Itm
.Owner
->FileSize
!= 0)
78 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
82 // AcqTextStatus::Done - Completed a download /*{{{*/
83 // ---------------------------------------------------------------------
84 /* We don't display anything... */
85 void AcqTextStatus::Done(pkgAcquire::ItemDesc
&Itm
)
90 // AcqTextStatus::Fail - Called when an item fails to download /*{{{*/
91 // ---------------------------------------------------------------------
92 /* We print out the error text */
93 void AcqTextStatus::Fail(pkgAcquire::ItemDesc
&Itm
)
98 // Ignore certain kinds of transient failures (bad code)
99 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatIdle
)
103 cout
<< '\r' << BlankLine
<< '\r';
105 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatDone
)
107 cout
<< _("Ign ") << Itm
.Description
<< endl
;
111 cout
<< _("Err ") << Itm
.Description
<< endl
;
112 cout
<< " " << Itm
.Owner
->ErrorText
<< endl
;
118 // AcqTextStatus::Stop - Finished downloading /*{{{*/
119 // ---------------------------------------------------------------------
120 /* This prints out the bytes downloaded and the overall average line
122 void AcqTextStatus::Stop()
124 pkgAcquireStatus::Stop();
129 cout
<< '\r' << BlankLine
<< '\r' << flush
;
131 if (FetchedBytes
!= 0 && _error
->PendingError() == false)
132 ioprintf(cout
,_("Fetched %sB in %s (%sB/s)\n"),
133 SizeToStr(FetchedBytes
).c_str(),
134 TimeToStr(ElapsedTime
).c_str(),
135 SizeToStr(CurrentCPS
).c_str());
138 // AcqTextStatus::Pulse - Regular event pulse /*{{{*/
139 // ---------------------------------------------------------------------
140 /* This draws the current progress. Each line has an overall percent
141 meter and a per active item status meter along with an overall
142 bandwidth and ETA indicator. */
143 bool AcqTextStatus::Pulse(pkgAcquire
*Owner
)
148 pkgAcquireStatus::Pulse(Owner
);
150 enum {Long
= 0,Medium
,Short
} Mode
= Long
;
153 char *End
= Buffer
+ sizeof(Buffer
);
155 if (ScreenWidth
>= sizeof(Buffer
))
156 ScreenWidth
= sizeof(Buffer
)-1;
158 // Put in the percent done
159 sprintf(S
,"%ld%%",long(double((CurrentBytes
+ CurrentItems
)*100.0)/double(TotalBytes
+TotalItems
)));
162 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
163 I
= Owner
->WorkerStep(I
))
167 // There is no item running
168 if (I
->CurrentItem
== 0)
170 if (I
->Status
.empty() == false)
172 snprintf(S
,End
-S
," [%s]",I
->Status
.c_str());
181 // Add in the short description
182 if (I
->CurrentItem
->Owner
->ID
!= 0)
183 snprintf(S
,End
-S
," [%lu %s",I
->CurrentItem
->Owner
->ID
,
184 I
->CurrentItem
->ShortDesc
.c_str());
186 snprintf(S
,End
-S
," [%s",I
->CurrentItem
->ShortDesc
.c_str());
189 // Show the short mode string
190 if (I
->CurrentItem
->Owner
->Mode
!= 0)
192 snprintf(S
,End
-S
," %s",I
->CurrentItem
->Owner
->Mode
);
196 // Add the current progress
198 snprintf(S
,End
-S
," %lu",I
->CurrentSize
);
201 if (Mode
== Medium
|| I
->TotalSize
== 0)
202 snprintf(S
,End
-S
," %sB",SizeToStr(I
->CurrentSize
).c_str());
206 // Add the total size and percent
207 if (I
->TotalSize
> 0 && I
->CurrentItem
->Owner
->Complete
== false)
210 snprintf(S
,End
-S
," %lu%%",
211 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
213 snprintf(S
,End
-S
,"/%sB %lu%%",SizeToStr(I
->TotalSize
).c_str(),
214 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
217 snprintf(S
,End
-S
,"]");
222 snprintf(S
,End
-S
,_(" [Working]"));
224 /* Put in the ETA and cps meter, block off signals to prevent strangeness
226 sigset_t Sigs
,OldSigs
;
228 sigaddset(&Sigs
,SIGWINCH
);
229 sigprocmask(SIG_BLOCK
,&Sigs
,&OldSigs
);
234 unsigned long ETA
= (unsigned long)((TotalBytes
- CurrentBytes
)/CurrentCPS
);
235 sprintf(Tmp
," %sB/s %s",SizeToStr(CurrentCPS
).c_str(),TimeToStr(ETA
).c_str());
236 unsigned int Len
= strlen(Buffer
);
237 unsigned int LenT
= strlen(Tmp
);
238 if (Len
+ LenT
< ScreenWidth
)
240 memset(Buffer
+ Len
,' ',ScreenWidth
- Len
);
241 strcpy(Buffer
+ ScreenWidth
- LenT
,Tmp
);
244 Buffer
[ScreenWidth
] = 0;
245 BlankLine
[ScreenWidth
] = 0;
246 sigprocmask(SIG_SETMASK
,&OldSigs
,0);
248 // Draw the current status
249 if (strlen(Buffer
) == strlen(BlankLine
))
250 cout
<< '\r' << Buffer
<< flush
;
252 cout
<< '\r' << BlankLine
<< '\r' << Buffer
<< flush
;
253 memset(BlankLine
,' ',strlen(Buffer
));
254 BlankLine
[strlen(Buffer
)] = 0;
261 // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/
262 // ---------------------------------------------------------------------
263 /* Prompt for a media swap */
264 bool AcqTextStatus::MediaChange(string Media
,string Drive
)
267 cout
<< '\r' << BlankLine
<< '\r';
268 ioprintf(cout
,_("Media Change: Please insert the disc labeled '%s' in "
269 "the drive '%s' and press enter\n"),
270 Media
.c_str(),Drive
.c_str());
273 while (C
!= '\n' && C
!= '\r')
274 read(STDIN_FILENO
,&C
,1);