]>
git.saurik.com Git - apt.git/blob - cmdline/acqprogress.cc
e2ef83501181e93a28e24d2a18eb70e0a3e6a2f2
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acqprogress.cc,v 1.20 2000/05/12 04:03:27 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>
21 // AcqTextStatus::AcqTextStatus - Constructor /*{{{*/
22 // ---------------------------------------------------------------------
24 AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth
,unsigned int Quiet
) :
25 ScreenWidth(ScreenWidth
), Quiet(Quiet
)
29 // AcqTextStatus::Start - Downloading has started /*{{{*/
30 // ---------------------------------------------------------------------
32 void AcqTextStatus::Start()
34 pkgAcquireStatus::Start();
39 // AcqTextStatus::IMSHit - Called when an item got a HIT response /*{{{*/
40 // ---------------------------------------------------------------------
42 void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc
&Itm
)
48 cout
<< '\r' << BlankLine
<< '\r';
50 cout
<< "Hit " << Itm
.Description
;
51 if (Itm
.Owner
->FileSize
!= 0)
52 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
57 // AcqTextStatus::Fetch - An item has started to download /*{{{*/
58 // ---------------------------------------------------------------------
59 /* This prints out the short description and the expected size */
60 void AcqTextStatus::Fetch(pkgAcquire::ItemDesc
&Itm
)
63 if (Itm
.Owner
->Complete
== true)
72 cout
<< '\r' << BlankLine
<< '\r';
74 cout
<< "Get:" << Itm
.Owner
->ID
<< ' ' << Itm
.Description
;
75 if (Itm
.Owner
->FileSize
!= 0)
76 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "B]";
80 // AcqTextStatus::Done - Completed a download /*{{{*/
81 // ---------------------------------------------------------------------
82 /* We don't display anything... */
83 void AcqTextStatus::Done(pkgAcquire::ItemDesc
&Itm
)
88 // AcqTextStatus::Fail - Called when an item fails to download /*{{{*/
89 // ---------------------------------------------------------------------
90 /* We print out the error text */
91 void AcqTextStatus::Fail(pkgAcquire::ItemDesc
&Itm
)
96 // Ignore certain kinds of transient failures (bad code)
97 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatIdle
)
101 cout
<< '\r' << BlankLine
<< '\r';
103 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatDone
)
105 cout
<< "Ign " << Itm
.Description
<< endl
;
109 cout
<< "Err " << Itm
.Description
<< endl
;
110 cout
<< " " << Itm
.Owner
->ErrorText
<< endl
;
116 // AcqTextStatus::Stop - Finished downloading /*{{{*/
117 // ---------------------------------------------------------------------
118 /* This prints out the bytes downloaded and the overall average line
120 void AcqTextStatus::Stop()
122 pkgAcquireStatus::Stop();
127 cout
<< '\r' << BlankLine
<< '\r' << flush
;
129 if (FetchedBytes
!= 0 && _error
->PendingError() == false)
130 cout
<< "Fetched " << SizeToStr(FetchedBytes
) << "B in " <<
131 TimeToStr(ElapsedTime
) << " (" << SizeToStr(CurrentCPS
) <<
135 // AcqTextStatus::Pulse - Regular event pulse /*{{{*/
136 // ---------------------------------------------------------------------
137 /* This draws the current progress. Each line has an overall percent
138 meter and a per active item status meter along with an overall
139 bandwidth and ETA indicator. */
140 bool AcqTextStatus::Pulse(pkgAcquire
*Owner
)
145 pkgAcquireStatus::Pulse(Owner
);
147 enum {Long
= 0,Medium
,Short
} Mode
= Long
;
150 char *End
= Buffer
+ sizeof(Buffer
);
152 if (ScreenWidth
>= sizeof(Buffer
))
153 ScreenWidth
= sizeof(Buffer
)-1;
155 // Put in the percent done
156 sprintf(S
,"%ld%%",long(double((CurrentBytes
+ CurrentItems
)*100.0)/double(TotalBytes
+TotalItems
)));
159 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
160 I
= Owner
->WorkerStep(I
))
164 // There is no item running
165 if (I
->CurrentItem
== 0)
167 if (I
->Status
.empty() == false)
169 snprintf(S
,End
-S
," [%s]",I
->Status
.c_str());
178 // Add in the short description
179 if (I
->CurrentItem
->Owner
->ID
!= 0)
180 snprintf(S
,End
-S
," [%lu %s",I
->CurrentItem
->Owner
->ID
,
181 I
->CurrentItem
->ShortDesc
.c_str());
183 snprintf(S
,End
-S
," [%s",I
->CurrentItem
->ShortDesc
.c_str());
186 // Show the short mode string
187 if (I
->CurrentItem
->Owner
->Mode
!= 0)
189 snprintf(S
,End
-S
," %s",I
->CurrentItem
->Owner
->Mode
);
193 // Add the current progress
195 snprintf(S
,End
-S
," %lu",I
->CurrentSize
);
198 if (Mode
== Medium
|| I
->TotalSize
== 0)
199 snprintf(S
,End
-S
," %sB",SizeToStr(I
->CurrentSize
).c_str());
203 // Add the total size and percent
204 if (I
->TotalSize
> 0 && I
->CurrentItem
->Owner
->Complete
== false)
207 snprintf(S
,End
-S
," %lu%%",
208 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
210 snprintf(S
,End
-S
,"/%sB %lu%%",SizeToStr(I
->TotalSize
).c_str(),
211 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
214 snprintf(S
,End
-S
,"]");
219 snprintf(S
,End
-S
," [Working]");
221 /* Put in the ETA and cps meter, block off signals to prevent strangeness
223 sigset_t Sigs
,OldSigs
;
225 sigaddset(&Sigs
,SIGWINCH
);
226 sigprocmask(SIG_BLOCK
,&Sigs
,&OldSigs
);
231 unsigned long ETA
= (unsigned long)((TotalBytes
- CurrentBytes
)/CurrentCPS
);
232 sprintf(Tmp
," %sB/s %s",SizeToStr(CurrentCPS
).c_str(),TimeToStr(ETA
).c_str());
233 unsigned int Len
= strlen(Buffer
);
234 unsigned int LenT
= strlen(Tmp
);
235 if (Len
+ LenT
< ScreenWidth
)
237 memset(Buffer
+ Len
,' ',ScreenWidth
- Len
);
238 strcpy(Buffer
+ ScreenWidth
- LenT
,Tmp
);
241 Buffer
[ScreenWidth
] = 0;
242 BlankLine
[ScreenWidth
] = 0;
243 sigprocmask(SIG_UNBLOCK
,&OldSigs
,0);
245 // Draw the current status
246 if (strlen(Buffer
) == strlen(BlankLine
))
247 cout
<< '\r' << Buffer
<< flush
;
249 cout
<< '\r' << BlankLine
<< '\r' << Buffer
<< flush
;
250 memset(BlankLine
,' ',strlen(Buffer
));
251 BlankLine
[strlen(Buffer
)] = 0;
258 // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/
259 // ---------------------------------------------------------------------
260 /* Prompt for a media swap */
261 bool AcqTextStatus::MediaChange(string Media
,string Drive
)
264 cout
<< '\r' << BlankLine
<< '\r';
265 cout
<< "Media Change: Please insert the disc labeled '" << Media
<< "' in "\
266 "the drive '" << Drive
<< "' and press enter" << endl
;
269 while (C
!= '\n' && C
!= '\r')
270 read(STDIN_FILENO
,&C
,1);