]>
git.saurik.com Git - apt.git/blob - cmdline/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
), Quiet(Quiet
)
38 // AcqTextStatus::Start - Downloading has started /*{{{*/
39 // ---------------------------------------------------------------------
41 void AcqTextStatus::Start()
43 pkgAcquireStatus::Start();
48 // AcqTextStatus::IMSHit - Called when an item got a HIT response /*{{{*/
49 // ---------------------------------------------------------------------
51 void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc
&Itm
)
57 cout
<< '\r' << BlankLine
<< '\r';
59 cout
<< _("Hit ") << Itm
.Description
;
60 if (Itm
.Owner
->FileSize
!= 0)
61 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
66 // AcqTextStatus::Fetch - An item has started to download /*{{{*/
67 // ---------------------------------------------------------------------
68 /* This prints out the short description and the expected size */
69 void AcqTextStatus::Fetch(pkgAcquire::ItemDesc
&Itm
)
72 if (Itm
.Owner
->Complete
== true)
81 cout
<< '\r' << BlankLine
<< '\r';
83 cout
<< _("Get:") << Itm
.Owner
->ID
<< ' ' << Itm
.Description
;
84 if (Itm
.Owner
->FileSize
!= 0)
85 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
89 // AcqTextStatus::Done - Completed a download /*{{{*/
90 // ---------------------------------------------------------------------
91 /* We don't display anything... */
92 void AcqTextStatus::Done(pkgAcquire::ItemDesc
&Itm
)
97 // AcqTextStatus::Fail - Called when an item fails to download /*{{{*/
98 // ---------------------------------------------------------------------
99 /* We print out the error text */
100 void AcqTextStatus::Fail(pkgAcquire::ItemDesc
&Itm
)
105 // Ignore certain kinds of transient failures (bad code)
106 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatIdle
)
110 cout
<< '\r' << BlankLine
<< '\r';
112 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatDone
)
114 cout
<< _("Ign ") << Itm
.Description
<< endl
;
118 cout
<< _("Err ") << Itm
.Description
<< endl
;
119 cout
<< " " << Itm
.Owner
->ErrorText
<< endl
;
125 // AcqTextStatus::Stop - Finished downloading /*{{{*/
126 // ---------------------------------------------------------------------
127 /* This prints out the bytes downloaded and the overall average line
129 void AcqTextStatus::Stop()
131 pkgAcquireStatus::Stop();
136 cout
<< '\r' << BlankLine
<< '\r' << flush
;
138 if (FetchedBytes
!= 0 && _error
->PendingError() == false)
139 ioprintf(cout
,_("Fetched %sB in %s (%sB/s)\n"),
140 SizeToStr(FetchedBytes
).c_str(),
141 TimeToStr(ElapsedTime
).c_str(),
142 SizeToStr(CurrentCPS
).c_str());
145 // AcqTextStatus::Pulse - Regular event pulse /*{{{*/
146 // ---------------------------------------------------------------------
147 /* This draws the current progress. Each line has an overall percent
148 meter and a per active item status meter along with an overall
149 bandwidth and ETA indicator. */
150 bool AcqTextStatus::Pulse(pkgAcquire
*Owner
)
152 pkgAcquireStatus::Pulse(Owner
);
157 enum {Long
= 0,Medium
,Short
} Mode
= Medium
;
159 char Buffer
[sizeof(BlankLine
)];
160 char *End
= Buffer
+ sizeof(Buffer
);
162 if (ScreenWidth
>= sizeof(Buffer
))
163 ScreenWidth
= sizeof(Buffer
)-1;
165 // Put in the percent done
166 sprintf(S
,"%.0f%%",((CurrentBytes
+ CurrentItems
)*100.0)/(TotalBytes
+TotalItems
));
169 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
170 I
= Owner
->WorkerStep(I
))
174 // There is no item running
175 if (I
->CurrentItem
== 0)
177 if (I
->Status
.empty() == false)
179 snprintf(S
,End
-S
," [%s]",I
->Status
.c_str());
188 // Add in the short description
189 if (I
->CurrentItem
->Owner
->ID
!= 0)
190 snprintf(S
,End
-S
," [%lu %s",I
->CurrentItem
->Owner
->ID
,
191 I
->CurrentItem
->ShortDesc
.c_str());
193 snprintf(S
,End
-S
," [%s",I
->CurrentItem
->ShortDesc
.c_str());
196 // Show the short mode string
197 if (I
->CurrentItem
->Owner
->Mode
!= 0)
199 snprintf(S
,End
-S
," %s",I
->CurrentItem
->Owner
->Mode
);
203 // Add the current progress
205 snprintf(S
,End
-S
," %llu",I
->CurrentSize
);
208 if (Mode
== Medium
|| I
->TotalSize
== 0)
209 snprintf(S
,End
-S
," %sB",SizeToStr(I
->CurrentSize
).c_str());
213 // Add the total size and percent
214 if (I
->TotalSize
> 0 && I
->CurrentItem
->Owner
->Complete
== false)
217 snprintf(S
,End
-S
," %.0f%%",
218 (I
->CurrentSize
*100.0)/I
->TotalSize
);
220 snprintf(S
,End
-S
,"/%sB %.0f%%",SizeToStr(I
->TotalSize
).c_str(),
221 (I
->CurrentSize
*100.0)/I
->TotalSize
);
224 snprintf(S
,End
-S
,"]");
229 snprintf(S
,End
-S
,_(" [Working]"));
231 /* Put in the ETA and cps meter, block off signals to prevent strangeness
233 sigset_t Sigs
,OldSigs
;
235 sigaddset(&Sigs
,SIGWINCH
);
236 sigprocmask(SIG_BLOCK
,&Sigs
,&OldSigs
);
241 unsigned long long ETA
= (TotalBytes
- CurrentBytes
)/CurrentCPS
;
242 sprintf(Tmp
," %sB/s %s",SizeToStr(CurrentCPS
).c_str(),TimeToStr(ETA
).c_str());
243 unsigned int Len
= strlen(Buffer
);
244 unsigned int LenT
= strlen(Tmp
);
245 if (Len
+ LenT
< ScreenWidth
)
247 memset(Buffer
+ Len
,' ',ScreenWidth
- Len
);
248 strcpy(Buffer
+ ScreenWidth
- LenT
,Tmp
);
251 Buffer
[ScreenWidth
] = 0;
252 BlankLine
[ScreenWidth
] = 0;
253 sigprocmask(SIG_SETMASK
,&OldSigs
,0);
255 // Draw the current status
256 if (strlen(Buffer
) == strlen(BlankLine
))
257 cout
<< '\r' << Buffer
<< flush
;
259 cout
<< '\r' << BlankLine
<< '\r' << Buffer
<< flush
;
260 memset(BlankLine
,' ',strlen(Buffer
));
261 BlankLine
[strlen(Buffer
)] = 0;
268 // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/
269 // ---------------------------------------------------------------------
270 /* Prompt for a media swap */
271 bool AcqTextStatus::MediaChange(string Media
,string Drive
)
273 // If we do not output on a terminal and one of the options to avoid user
274 // interaction is given, we assume that no user is present who could react
275 // on your media change request
276 if (isatty(STDOUT_FILENO
) != 1 && Quiet
>= 2 &&
277 (_config
->FindB("APT::Get::Assume-Yes",false) == true ||
278 _config
->FindB("APT::Get::Force-Yes",false) == true ||
279 _config
->FindB("APT::Get::Trivial-Only",false) == true))
284 cout
<< '\r' << BlankLine
<< '\r';
285 ioprintf(cout
,_("Media change: please insert the disc labeled\n"
287 "in the drive '%s' and press enter\n"),
288 Media
.c_str(),Drive
.c_str());
292 while (C
!= '\n' && C
!= '\r')
294 int len
= read(STDIN_FILENO
,&C
,1);
295 if(C
== 'c' || len
<= 0)