]>
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.h>
14 #include <apt-pkg/acquire-item.h>
15 #include <apt-pkg/acquire-worker.h>
16 #include <apt-pkg/configuration.h>
17 #include <apt-pkg/strutl.h>
18 #include <apt-pkg/error.h>
26 #include "acqprogress.h"
32 // AcqTextStatus::AcqTextStatus - Constructor /*{{{*/
33 // ---------------------------------------------------------------------
35 AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth
,unsigned int Quiet
) :
36 ScreenWidth(ScreenWidth
), ID(0), Quiet(Quiet
)
41 // AcqTextStatus::Start - Downloading has started /*{{{*/
42 // ---------------------------------------------------------------------
44 void AcqTextStatus::Start()
46 pkgAcquireStatus::Start();
51 // AcqTextStatus::IMSHit - Called when an item got a HIT response /*{{{*/
52 // ---------------------------------------------------------------------
54 void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc
&Itm
)
60 cout
<< '\r' << BlankLine
<< '\r';
62 cout
<< _("Hit ") << Itm
.Description
;
63 if (Itm
.Owner
->FileSize
!= 0)
64 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
69 // AcqTextStatus::Fetch - An item has started to download /*{{{*/
70 // ---------------------------------------------------------------------
71 /* This prints out the short description and the expected size */
72 void AcqTextStatus::Fetch(pkgAcquire::ItemDesc
&Itm
)
75 if (Itm
.Owner
->Complete
== true)
84 cout
<< '\r' << BlankLine
<< '\r';
86 cout
<< _("Get:") << Itm
.Owner
->ID
<< ' ' << Itm
.Description
;
87 if (Itm
.Owner
->FileSize
!= 0)
88 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
92 // AcqTextStatus::Done - Completed a download /*{{{*/
93 // ---------------------------------------------------------------------
94 /* We don't display anything... */
95 void AcqTextStatus::Done(pkgAcquire::ItemDesc
&Itm
)
100 // AcqTextStatus::Fail - Called when an item fails to download /*{{{*/
101 // ---------------------------------------------------------------------
102 /* We print out the error text */
103 void AcqTextStatus::Fail(pkgAcquire::ItemDesc
&Itm
)
108 // Ignore certain kinds of transient failures (bad code)
109 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatIdle
)
113 cout
<< '\r' << BlankLine
<< '\r';
115 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatDone
)
117 cout
<< _("Ign ") << Itm
.Description
<< endl
;
121 cout
<< _("Err ") << Itm
.Description
<< endl
;
122 cout
<< " " << Itm
.Owner
->ErrorText
<< endl
;
128 // AcqTextStatus::Stop - Finished downloading /*{{{*/
129 // ---------------------------------------------------------------------
130 /* This prints out the bytes downloaded and the overall average line
132 void AcqTextStatus::Stop()
134 pkgAcquireStatus::Stop();
139 cout
<< '\r' << BlankLine
<< '\r' << flush
;
141 if (FetchedBytes
!= 0 && _error
->PendingError() == false)
142 ioprintf(cout
,_("Fetched %sB in %s (%sB/s)\n"),
143 SizeToStr(FetchedBytes
).c_str(),
144 TimeToStr(ElapsedTime
).c_str(),
145 SizeToStr(CurrentCPS
).c_str());
148 // AcqTextStatus::Pulse - Regular event pulse /*{{{*/
149 // ---------------------------------------------------------------------
150 /* This draws the current progress. Each line has an overall percent
151 meter and a per active item status meter along with an overall
152 bandwidth and ETA indicator. */
153 bool AcqTextStatus::Pulse(pkgAcquire
*Owner
)
155 pkgAcquireStatus::Pulse(Owner
);
160 enum {Long
= 0,Medium
,Short
} Mode
= Medium
;
162 char Buffer
[sizeof(BlankLine
)];
163 char *End
= Buffer
+ sizeof(Buffer
);
165 if (ScreenWidth
>= sizeof(Buffer
))
166 ScreenWidth
= sizeof(Buffer
)-1;
168 // Put in the percent done
169 sprintf(S
,"%.0f%%",((CurrentBytes
+ CurrentItems
)*100.0)/(TotalBytes
+TotalItems
));
172 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
173 I
= Owner
->WorkerStep(I
))
177 // There is no item running
178 if (I
->CurrentItem
== 0)
180 if (I
->Status
.empty() == false)
182 snprintf(S
,End
-S
," [%s]",I
->Status
.c_str());
191 // Add in the short description
192 if (I
->CurrentItem
->Owner
->ID
!= 0)
193 snprintf(S
,End
-S
," [%lu %s",I
->CurrentItem
->Owner
->ID
,
194 I
->CurrentItem
->ShortDesc
.c_str());
196 snprintf(S
,End
-S
," [%s",I
->CurrentItem
->ShortDesc
.c_str());
199 // Show the short mode string
200 if (I
->CurrentItem
->Owner
->Mode
!= 0)
202 snprintf(S
,End
-S
," %s",I
->CurrentItem
->Owner
->Mode
);
206 // Add the current progress
208 snprintf(S
,End
-S
," %llu",I
->CurrentSize
);
211 if (Mode
== Medium
|| I
->TotalSize
== 0)
212 snprintf(S
,End
-S
," %sB",SizeToStr(I
->CurrentSize
).c_str());
216 // Add the total size and percent
217 if (I
->TotalSize
> 0 && I
->CurrentItem
->Owner
->Complete
== false)
220 snprintf(S
,End
-S
," %.0f%%",
221 (I
->CurrentSize
*100.0)/I
->TotalSize
);
223 snprintf(S
,End
-S
,"/%sB %.0f%%",SizeToStr(I
->TotalSize
).c_str(),
224 (I
->CurrentSize
*100.0)/I
->TotalSize
);
227 snprintf(S
,End
-S
,"]");
232 snprintf(S
,End
-S
,_(" [Working]"));
234 /* Put in the ETA and cps meter, block off signals to prevent strangeness
236 sigset_t Sigs
,OldSigs
;
238 sigaddset(&Sigs
,SIGWINCH
);
239 sigprocmask(SIG_BLOCK
,&Sigs
,&OldSigs
);
244 unsigned long long ETA
= (TotalBytes
- CurrentBytes
)/CurrentCPS
;
245 sprintf(Tmp
," %sB/s %s",SizeToStr(CurrentCPS
).c_str(),TimeToStr(ETA
).c_str());
246 unsigned int Len
= strlen(Buffer
);
247 unsigned int LenT
= strlen(Tmp
);
248 if (Len
+ LenT
< ScreenWidth
)
250 memset(Buffer
+ Len
,' ',ScreenWidth
- Len
);
251 strcpy(Buffer
+ ScreenWidth
- LenT
,Tmp
);
254 Buffer
[ScreenWidth
] = 0;
255 BlankLine
[ScreenWidth
] = 0;
256 sigprocmask(SIG_SETMASK
,&OldSigs
,0);
258 // Draw the current status
259 if (strlen(Buffer
) == strlen(BlankLine
))
260 cout
<< '\r' << Buffer
<< flush
;
262 cout
<< '\r' << BlankLine
<< '\r' << Buffer
<< flush
;
263 memset(BlankLine
,' ',strlen(Buffer
));
264 BlankLine
[strlen(Buffer
)] = 0;
271 // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/
272 // ---------------------------------------------------------------------
273 /* Prompt for a media swap */
274 bool AcqTextStatus::MediaChange(string Media
,string Drive
)
276 // If we do not output on a terminal and one of the options to avoid user
277 // interaction is given, we assume that no user is present who could react
278 // on your media change request
279 if (isatty(STDOUT_FILENO
) != 1 && Quiet
>= 2 &&
280 (_config
->FindB("APT::Get::Assume-Yes",false) == true ||
281 _config
->FindB("APT::Get::Force-Yes",false) == true ||
282 _config
->FindB("APT::Get::Trivial-Only",false) == true))
287 cout
<< '\r' << BlankLine
<< '\r';
288 ioprintf(cout
,_("Media change: please insert the disc labeled\n"
290 "in the drive '%s' and press enter\n"),
291 Media
.c_str(),Drive
.c_str());
295 while (C
!= '\n' && C
!= '\r')
297 int len
= read(STDIN_FILENO
,&C
,1);
298 if(C
== 'c' || len
<= 0)