View | Details | Raw Unified | Return to bug 168935
Collapse All | Expand All

(-)src/output/OutNormal.cc (-5 / +17 lines)
Lines 2-7 Link Here
2
#include <sstream>
2
#include <sstream>
3
3
4
#include "zypp/Pathname.h"
4
#include "zypp/Pathname.h"
5
#include "zypp/ByteCount.h" // for download progress reporting
5
6
6
#include "../zypper-main.h"
7
#include "../zypper-main.h"
7
#include "../AliveCursor.h"
8
#include "../AliveCursor.h"
Lines 150-156 Link Here
150
151
151
void OutNormal::dwnldProgress(const zypp::Url & uri,
152
void OutNormal::dwnldProgress(const zypp::Url & uri,
152
                              int value,
153
                              int value,
153
                              int rate)
154
                              long rate) 
154
{
155
{
155
  if (verbosity() < NORMAL)
156
  if (verbosity() < NORMAL)
156
    return;
157
    return;
Lines 162-173 Link Here
162
  else
163
  else
163
    cout << zypp::Pathname(uri.getPathName()).basename();
164
    cout << zypp::Pathname(uri.getPathName()).basename();
164
  // dont display percents if invalid
165
  // dont display percents if invalid
165
  if (value >= 0 && value <= 100)
166
  if ((value >= 0 && value <= 100) || rate >= 0)
166
    cout << " [" << value << "%]";
167
  {
168
    cout << " [";
169
    if (value >= 0 && value <= 100)
170
      cout << value << "%";
171
    if (rate >= 0)
172
      cout << " (" << zypp::ByteCount(rate) << "/s)";
173
    cout << "]";
174
  }
175
167
  cout << std::flush;
176
  cout << std::flush;
168
}
177
}
169
178
170
void OutNormal::dwnldProgressEnd(const zypp::Url & uri, int rate, bool error)
179
void OutNormal::dwnldProgressEnd(const zypp::Url & uri, long rate, bool error)
171
{
180
{
172
  if (verbosity() < NORMAL)
181
  if (verbosity() < NORMAL)
173
    return;
182
    return;
Lines 178-184 Link Here
178
    cout << uri; //! \todo shorten to fit the width of the terminal
187
    cout << uri; //! \todo shorten to fit the width of the terminal
179
  else
188
  else
180
    cout << zypp::Pathname(uri.getPathName()).basename();
189
    cout << zypp::Pathname(uri.getPathName()).basename();
181
  cout << " [" << (error ? _("error") : _("done")) << "]";
190
  cout << " [" << (error ? _("error") : _("done"));
191
  if (rate >= 0)
192
    cout << " (" << zypp::ByteCount(rate) << "/s)";
193
  cout << "]";
182
  cout << endl << std::flush;
194
  cout << endl << std::flush;
183
}
195
}
184
196
(-)src/output/OutNormal.h (-2 / +2 lines)
Lines 48-56 Link Here
48
  virtual void dwnldProgressStart(const zypp::Url & uri);
48
  virtual void dwnldProgressStart(const zypp::Url & uri);
49
  virtual void dwnldProgress(const zypp::Url & uri,
49
  virtual void dwnldProgress(const zypp::Url & uri,
50
                             int value = -1,
50
                             int value = -1,
51
                             int rate = -1);
51
                             long rate = -1);
52
  virtual void dwnldProgressEnd(const zypp::Url & uri,
52
  virtual void dwnldProgressEnd(const zypp::Url & uri,
53
                                int rate = -1,
53
                                long rate = -1,
54
                                bool error = false);
54
                                bool error = false);
55
  
55
  
56
  virtual void prompt(PromptId id,
56
  virtual void prompt(PromptId id,
(-)src/output/OutXML.cc (-2 / +2 lines)
Lines 168-174 Link Here
168
168
169
void OutXML::dwnldProgress(const zypp::Url & uri,
169
void OutXML::dwnldProgress(const zypp::Url & uri,
170
                           int value,
170
                           int value,
171
                           int rate)
171
                           long rate)
172
{
172
{
173
  cout << "<download"
173
  cout << "<download"
174
    << " url=\"" << xml_encode(uri.asString()) << "\""
174
    << " url=\"" << xml_encode(uri.asString()) << "\""
Lines 177-183 Link Here
177
    << "/>" << endl;
177
    << "/>" << endl;
178
}
178
}
179
179
180
void OutXML::dwnldProgressEnd(const zypp::Url & uri, int rate, bool error)
180
void OutXML::dwnldProgressEnd(const zypp::Url & uri, long rate, bool error)
181
{
181
{
182
  cout << "<download"
182
  cout << "<download"
183
    << " url=\"" << xml_encode(uri.asString()) << "\""
183
    << " url=\"" << xml_encode(uri.asString()) << "\""
(-)src/output/Out.h (-4 / +4 lines)
Lines 190-209 Link Here
190
   * 
190
   * 
191
   * \param uri   Uri of the file being downloaded. 
191
   * \param uri   Uri of the file being downloaded. 
192
   * \param value Value of the progress in percents. -1 if unknown.
192
   * \param value Value of the progress in percents. -1 if unknown.
193
   * \param rate  Download rate. -1 if unknown.
193
   * \param rate  Current download rate in B/s. -1 if unknown.
194
   */
194
   */
195
  virtual void dwnldProgress(const zypp::Url & uri,
195
  virtual void dwnldProgress(const zypp::Url & uri,
196
                             int value = -1,
196
                             int value = -1,
197
                             int rate = -1) = 0;
197
                             long rate = -1) = 0;
198
  /**
198
  /**
199
   * Reports end of a download.
199
   * Reports end of a download.
200
   * 
200
   * 
201
   * \param uri   Uri of the file to download. 
201
   * \param uri   Uri of the file to download. 
202
   * \param rate  Final download rate. -1 if unknown.
202
   * \param rate  Average download rate at the end. -1 if unknown.
203
   * \param error Error flag - did the download finish with error?
203
   * \param error Error flag - did the download finish with error?
204
   */
204
   */
205
  virtual void dwnldProgressEnd(const zypp::Url & uri,
205
  virtual void dwnldProgressEnd(const zypp::Url & uri,
206
                                int rate = -1,
206
                                long rate = -1,
207
                                bool error = false) = 0;
207
                                bool error = false) = 0;
208
  //@}
208
  //@}
209
209
(-)src/output/OutXML.h (-2 / +2 lines)
Lines 32-40 Link Here
32
  virtual void dwnldProgressStart(const zypp::Url & uri);
32
  virtual void dwnldProgressStart(const zypp::Url & uri);
33
  virtual void dwnldProgress(const zypp::Url & uri,
33
  virtual void dwnldProgress(const zypp::Url & uri,
34
                             int value = -1,
34
                             int value = -1,
35
                             int rate = -1);
35
                             long rate = -1);
36
  virtual void dwnldProgressEnd(const zypp::Url & uri,
36
  virtual void dwnldProgressEnd(const zypp::Url & uri,
37
                                int rate = -1,
37
                                long rate = -1,
38
                                bool error = false);
38
                                bool error = false);
39
39
40
  virtual void prompt(PromptId id,
40
  virtual void prompt(PromptId id,
(-)src/zypper-media-callbacks.h (-7 / +22 lines)
Lines 11-21 Link Here
11
#define ZMART_MEDIA_CALLBACKS_H
11
#define ZMART_MEDIA_CALLBACKS_H
12
12
13
#include <stdlib.h>
13
#include <stdlib.h>
14
#include <iostream>
14
#include <ctime>
15
15
16
#include <boost/format.hpp>
16
#include <boost/format.hpp>
17
17
18
#include "zypp/base/Logger.h"
19
#include "zypp/ZYppCallbacks.h"
18
#include "zypp/ZYppCallbacks.h"
20
#include "zypp/Pathname.h"
19
#include "zypp/Pathname.h"
21
#include "zypp/KeyRing.h"
20
#include "zypp/KeyRing.h"
Lines 69-75 Link Here
69
  };
68
  };
70
69
71
  // progress for downloading a file
70
  // progress for downloading a file
72
  struct DownloadProgressReportReceiver : public zypp::callback::ReceiveReport<zypp::media::DownloadProgressReport>
71
  struct DownloadProgressReportReceiver
72
    : public zypp::callback::ReceiveReport<zypp::media::DownloadProgressReport>
73
  {
73
  {
74
    DownloadProgressReportReceiver()
74
    DownloadProgressReportReceiver()
75
      : _gopts(Zypper::instance()->globalOpts()), _be_quiet(false)
75
      : _gopts(Zypper::instance()->globalOpts()), _be_quiet(false)
Lines 77-82 Link Here
77
77
78
    virtual void start( const zypp::Url & uri, zypp::Pathname localfile )
78
    virtual void start( const zypp::Url & uri, zypp::Pathname localfile )
79
    {
79
    {
80
      _last_reported = time(NULL);
81
      _last_drate_avg = -1;
82
80
      Out & out = Zypper::instance()->out();
83
      Out & out = Zypper::instance()->out();
81
84
82
      if (out.verbosity() < Out::HIGH &&
85
      if (out.verbosity() < Out::HIGH &&
Lines 98-109 Link Here
98
    }
101
    }
99
102
100
    //! \todo return false on SIGINT
103
    //! \todo return false on SIGINT
101
    virtual bool progress(int value, const zypp::Url & uri)
104
    virtual bool progress(int value, const zypp::Url & uri, double drate_avg, double drate_now)
102
    {
105
    {
103
      if (_be_quiet)
106
      if (_be_quiet)
104
        return true;
107
        return true;
105
108
106
      Zypper::instance()->out().dwnldProgress(uri, value); //! \todo add transfer rate
109
//      std::cout << "avg: " << drate_avg << " current: " << drate_now << std::endl;
110
111
      // don't report more often than 1 second
112
      time_t now = time(NULL);
113
      if (now > _last_reported)
114
        _last_reported = now;
115
      else
116
        return true;
117
118
      Zypper::instance()->out().dwnldProgress(uri, value, (long) drate_now);
119
      _last_drate_avg = drate_avg;
107
      return true;
120
      return true;
108
    }
121
    }
109
122
Lines 112-118 Link Here
112
    problem( const zypp::Url & uri, DownloadProgressReport::Error error, const std::string & description )
125
    problem( const zypp::Url & uri, DownloadProgressReport::Error error, const std::string & description )
113
    {
126
    {
114
      if (_be_quiet)
127
      if (_be_quiet)
115
        Zypper::instance()->out().dwnldProgressEnd(uri, true);
128
        Zypper::instance()->out().dwnldProgressEnd(uri, _last_drate_avg, true);
116
      Zypper::instance()->out().error(zcb_error2str(error, description));
129
      Zypper::instance()->out().error(zcb_error2str(error, description));
117
130
118
      return (Action) read_action_ari(PROMPT_ARI_MEDIA_PROBLEM, DownloadProgressReport::ABORT);
131
      return (Action) read_action_ari(PROMPT_ARI_MEDIA_PROBLEM, DownloadProgressReport::ABORT);
Lines 124-135 Link Here
124
      if (_be_quiet)
137
      if (_be_quiet)
125
        return;
138
        return;
126
139
127
      Zypper::instance()->out().dwnldProgressEnd(uri);
140
      Zypper::instance()->out().dwnldProgressEnd(uri, _last_drate_avg);
128
    }
141
    }
129
142
130
  private:
143
  private:
131
    const GlobalOptions & _gopts;
144
    const GlobalOptions & _gopts;
132
    bool _be_quiet;
145
    bool _be_quiet;
146
    time_t _last_reported;
147
    double _last_drate_avg;
133
  };
148
  };
134
149
135
150

Return to bug 168935