]>
git.saurik.com Git - apt.git/blob - apt-private/acqprogress.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acqprogress.cc,v 1.24 2003/04/27 01:56:48 doogie Exp $
4 /* ######################################################################
6 Acquire Progress - Command line progress meter
8 ##################################################################### */
10 // Include files /*{{{*/
13 #include <apt-pkg/acquire-item.h>
14 #include <apt-pkg/acquire-worker.h>
15 #include <apt-pkg/configuration.h>
16 #include <apt-pkg/strutl.h>
17 #include <apt-pkg/error.h>
24 #include "acqprogress.h"
30 // AcqTextStatus::AcqTextStatus - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
33 AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth
,unsigned int Quiet
) :
34 ScreenWidth(ScreenWidth
), ID(0), Quiet(Quiet
)
39 // AcqTextStatus::Start - Downloading has started /*{{{*/
40 // ---------------------------------------------------------------------
42 void AcqTextStatus::Start()
44 pkgAcquireStatus::Start();
49 // AcqTextStatus::IMSHit - Called when an item got a HIT response /*{{{*/
50 // ---------------------------------------------------------------------
52 void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc
&Itm
)
58 cout
<< '\r' << BlankLine
<< '\r';
60 cout
<< _("Hit ") << Itm
.Description
;
61 if (Itm
.Owner
->FileSize
!= 0)
62 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
67 // AcqTextStatus::Fetch - An item has started to download /*{{{*/
68 // ---------------------------------------------------------------------
69 /* This prints out the short description and the expected size */
70 void AcqTextStatus::Fetch(pkgAcquire::ItemDesc
&Itm
)
73 if (Itm
.Owner
->Complete
== true)
82 cout
<< '\r' << BlankLine
<< '\r';
84 cout
<< _("Get:") << Itm
.Owner
->ID
<< ' ' << Itm
.Description
;
85 if (Itm
.Owner
->FileSize
!= 0)
86 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
90 // AcqTextStatus::Done - Completed a download /*{{{*/
91 // ---------------------------------------------------------------------
92 /* We don't display anything... */
93 void AcqTextStatus::Done(pkgAcquire::ItemDesc
&Itm
)
98 // AcqTextStatus::Fail - Called when an item fails to download /*{{{*/
99 // ---------------------------------------------------------------------
100 /* We print out the error text */
101 void AcqTextStatus::Fail(pkgAcquire::ItemDesc
&Itm
)
106 // Ignore certain kinds of transient failures (bad code)
107 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatIdle
)
111 cout
<< '\r' << BlankLine
<< '\r';
113 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatDone
)
115 cout
<< _("Ign ") << Itm
.Description
<< endl
;
119 cout
<< _("Err ") << Itm
.Description
<< endl
;
120 cout
<< " " << Itm
.Owner
->ErrorText
<< endl
;
126 // AcqTextStatus::Stop - Finished downloading /*{{{*/
127 // ---------------------------------------------------------------------
128 /* This prints out the bytes downloaded and the overall average line
130 void AcqTextStatus::Stop()
132 pkgAcquireStatus::Stop();
137 cout
<< '\r' << BlankLine
<< '\r' << flush
;
139 if (FetchedBytes
!= 0 && _error
->PendingError() == false)
140 ioprintf(cout
,_("Fetched %sB in %s (%sB/s)\n"),
141 SizeToStr(FetchedBytes
).c_str(),
142 TimeToStr(ElapsedTime
).c_str(),
143 SizeToStr(CurrentCPS
).c_str());
146 // AcqTextStatus::Pulse - Regular event pulse /*{{{*/
147 // ---------------------------------------------------------------------
148 /* This draws the current progress. Each line has an overall percent
149 meter and a per active item status meter along with an overall
150 bandwidth and ETA indicator. */
151 bool AcqTextStatus::Pulse(pkgAcquire
*Owner
)
153 pkgAcquireStatus::Pulse(Owner
);
158 enum {Long
= 0,Medium
,Short
} Mode
= Medium
;
160 char Buffer
[sizeof(BlankLine
)];
161 char *End
= Buffer
+ sizeof(Buffer
);
163 if (ScreenWidth
>= sizeof(Buffer
))
164 ScreenWidth
= sizeof(Buffer
)-1;
166 // Put in the percent done
167 sprintf(S
,"%.0f%%",((CurrentBytes
+ CurrentItems
)*100.0)/(TotalBytes
+TotalItems
));
170 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
171 I
= Owner
->WorkerStep(I
))
175 // There is no item running
176 if (I
->CurrentItem
== 0)
178 if (I
->Status
.empty() == false)
180 snprintf(S
,End
-S
," [%s]",I
->Status
.c_str());
189 // Add in the short description
190 if (I
->CurrentItem
->Owner
->ID
!= 0)
191 snprintf(S
,End
-S
," [%lu %s",I
->CurrentItem
->Owner
->ID
,
192 I
->CurrentItem
->ShortDesc
.c_str());
194 snprintf(S
,End
-S
," [%s",I
->CurrentItem
->ShortDesc
.c_str());
197 // Show the short mode string
198 if (I
->CurrentItem
->Owner
->Mode
!= 0)
200 snprintf(S
,End
-S
," %s",I
->CurrentItem
->Owner
->Mode
);
204 // Add the current progress
206 snprintf(S
,End
-S
," %llu",I
->CurrentSize
);
209 if (Mode
== Medium
|| I
->TotalSize
== 0)
210 snprintf(S
,End
-S
," %sB",SizeToStr(I
->CurrentSize
).c_str());
214 // Add the total size and percent
215 if (I
->TotalSize
> 0 && I
->CurrentItem
->Owner
->Complete
== false)
218 snprintf(S
,End
-S
," %.0f%%",
219 (I
->CurrentSize
*100.0)/I
->TotalSize
);
221 snprintf(S
,End
-S
,"/%sB %.0f%%",SizeToStr(I
->TotalSize
).c_str(),
222 (I
->CurrentSize
*100.0)/I
->TotalSize
);
225 snprintf(S
,End
-S
,"]");
230 snprintf(S
,End
-S
,_(" [Working]"));
232 /* Put in the ETA and cps meter, block off signals to prevent strangeness
234 sigset_t Sigs
,OldSigs
;
236 sigaddset(&Sigs
,SIGWINCH
);
237 sigprocmask(SIG_BLOCK
,&Sigs
,&OldSigs
);
242 unsigned long long ETA
= (TotalBytes
- CurrentBytes
)/CurrentCPS
;
243 sprintf(Tmp
," %sB/s %s",SizeToStr(CurrentCPS
).c_str(),TimeToStr(ETA
).c_str());
244 unsigned int Len
= strlen(Buffer
);
245 unsigned int LenT
= strlen(Tmp
);
246 if (Len
+ LenT
< ScreenWidth
)
248 memset(Buffer
+ Len
,' ',ScreenWidth
- Len
);
249 strcpy(Buffer
+ ScreenWidth
- LenT
,Tmp
);
252 Buffer
[ScreenWidth
] = 0;
253 BlankLine
[ScreenWidth
] = 0;
254 sigprocmask(SIG_SETMASK
,&OldSigs
,0);
256 // Draw the current status
257 if (_config
->FindB("Apt::Color", false) == true)
258 cout
<< _config
->Find("APT::Color::Yellow");
259 if (strlen(Buffer
) == strlen(BlankLine
))
260 cout
<< '\r' << Buffer
<< flush
;
262 cout
<< '\r' << BlankLine
<< '\r' << Buffer
<< flush
;
263 if (_config
->FindB("Apt::Color", false) == true)
264 cout
<< _config
->Find("APT::Color::Neutral");
266 memset(BlankLine
,' ',strlen(Buffer
));
267 BlankLine
[strlen(Buffer
)] = 0;
274 // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/
275 // ---------------------------------------------------------------------
276 /* Prompt for a media swap */
277 bool AcqTextStatus::MediaChange(string Media
,string Drive
)
279 // If we do not output on a terminal and one of the options to avoid user
280 // interaction is given, we assume that no user is present who could react
281 // on your media change request
282 if (isatty(STDOUT_FILENO
) != 1 && Quiet
>= 2 &&
283 (_config
->FindB("APT::Get::Assume-Yes",false) == true ||
284 _config
->FindB("APT::Get::Force-Yes",false) == true ||
285 _config
->FindB("APT::Get::Trivial-Only",false) == true))
290 cout
<< '\r' << BlankLine
<< '\r';
291 ioprintf(cout
,_("Media change: please insert the disc labeled\n"
293 "in the drive '%s' and press enter\n"),
294 Media
.c_str(),Drive
.c_str());
298 while (C
!= '\n' && C
!= '\r')
300 int len
= read(STDIN_FILENO
,&C
,1);
301 if(C
== 'c' || len
<= 0)