using namespace std;
-void display_progress (ostream & out, const string& s, int percent) {
+void display_progress ( const std::string &id, ostream & out, const string& s, int percent) {
static AliveCursor cursor;
if (gSettings.machine_readable)
+ {
+ cout << "<progress id=\"" << id << "\" type=\"percentage\" value=\"" << percent << "\" name=\"" << s << "\"/>" << endl;
return;
+ }
if ( percent == 100 )
out << CLEARLN << cursor.done() << " " << s;
// ----------------------------------------------------------------------------
-void display_tick (ostream & out, const string& s) {
+void display_tick ( const std::string &id, ostream & out, const string& s) {
static AliveCursor cursor;
if (gSettings.machine_readable)
+ {
+ cout << "<progress id=\"" << id << "\" type=\"tick\" value=\"" << -1 << "\" name=\"" << s << "\"/>" << endl;
return;
+ }
cursor++;
out << CLEARLN << cursor << " " << s;
// ----------------------------------------------------------------------------
-void display_done (ostream & out, const string& s) {
+void display_done ( const std::string &id, ostream & out, const string& s) {
static AliveCursor cursor;
if (gSettings.machine_readable)
+ {
+ cout << "<progress id=\"" << id << "\" type=\"done\" name=\"" << s << "\"/>" << endl;
return;
+ }
out << CLEARLN << cursor.done() << " " << s;
out << flush;
// ----------------------------------------------------------------------------
-void display_done (ostream & out) {
+void display_done (const std::string &id, ostream & out) {
if (gSettings.machine_readable)
+ {
+ display_done( id, cout, "");
return;
+ }
+
out << endl;
}
INVALID,
};
*/
-void display_progress (std::ostream & out, const std::string& s, int percent);
-void display_tick (std::ostream & out, const std::string& s);
-void display_done (ostream & out, const std::string& s);
+void display_progress ( const std::string &id, std::ostream & out, const std::string& s, int percent);
+void display_tick ( const std::string &id, std::ostream & out, const std::string& s);
+void display_done ( const std::string &id, ostream & out, const std::string& s);
// newline if normal progress is on single line
-void display_done (ostream & out);
+void display_done ( const std::string &id, ostream & out);
template<typename Error>
void display_error (Error error, const std::string& reason) {
- if (error != 0 /*NO_ERROR*/) {
+ if (error != 0 /*NO_ERROR*/)
+ {
static const char * error_s[] = {
// TranslatorExplanation These are reasons for various failures.
"", _("Not found"), _("I/O error"), _("Invalid object")
virtual bool progress(int value, const zypp::Url & /*file*/)
{
- display_progress (cout_v, "Downloading", value);
+ display_progress ("download", cout_v, "Downloading", value);
return true;
}
virtual DownloadProgressReport::Action problem( const zypp::Url & /*file*/, DownloadProgressReport::Error error, const std::string & description )
{
- display_done (cout_v);
+ display_done ("download", cout_v);
display_error (error, description);
return DownloadProgressReport::ABORT;
}
virtual void finish( const zypp::Url & /*file*/, Error error, const std::string & konreason )
{
- display_done (cout_v);
+ display_done ("download", cout_v);
display_error (error, konreason);
}
};
{
virtual void show( zypp::Message::constPtr message )
{
- cout_v << message << endl; // [message]important-msg-1.0-1
- cout_n << message->text() << endl;
+ if ( !gSettings.machine_readable )
+ {
+ cout_v << message << endl; // [message]important-msg-1.0-1
+ cout_n << message->text() << endl;
+ return;
+ }
+
+ cout << "<message>" << message->text() << "</message>" << endl;
+
//! \todo in interactive mode, wait for ENTER?
}
};
}
/** Report error. */
virtual void problem( const std::string & description ) {
- display_done (cout_n);
+ display_done ( "run-script", cout_n);
cerr << description << endl;
}
/** Report success. */
virtual void finish() {
- display_done (cout_n);
+ display_done ("run-script", cout_n);
}
};
// this is called too often. relax a bit.
static int last = -1;
if (last != value)
- display_progress (cout, _("Reading installed packages"), value);
+ display_progress ( "read-installed-packages", cout, _("Reading installed packages"), value);
last = value;
return true;
}
virtual void finish( Error error, const std::string & reason )
{
- display_done (cout);
+ display_done ("read-installed-packages", cout);
display_error (error, reason);
}
};
{
virtual void start( zypp::Resolvable::constPtr resolvable )
{
- cout << boost::format(_("Removing: %s-%s"))
- % resolvable->name() % resolvable->edition() << endl;
+ display_progress ( "remove-resolvable", cout, _("Removing ") + to_string (resolvable), 0);
}
virtual bool progress(int value, zypp::Resolvable::constPtr resolvable)
{
// TranslatorExplanation This text is a progress display label e.g. "Removing [42%]"
- display_progress (cout, _("Removing ") + to_string (resolvable), value);
+ display_progress ( "remove-resolvable", cout, _("Removing ") + to_string (resolvable), value);
return true;
}
virtual void finish( zypp::Resolvable::constPtr /*resolvable*/, Error error, const std::string & reason )
{
- display_done (cout);
+ display_done ( "remove-resolvable", cout);
display_error (error, reason);
}
};
{
zypp::Resolvable::constPtr _resolvable;
- void display_step( zypp::Resolvable::constPtr /*resolvable*/, int value )
+ void display_step( zypp::Resolvable::constPtr resolvable, int value )
{
// TranslatorExplanation This text is a progress display label e.g. "Installing [42%]"
- display_progress (cout, _("Installing ") /* + to_string (resolvable) */, value);
+ stringstream s;
+ s << (boost::format(_("Installing: %s-%s"))
+ % resolvable->name() % resolvable->edition());
+ display_progress ( "install-resolvable", cout, s.str(), value);
}
virtual void start( zypp::Resolvable::constPtr resolvable )
{
_resolvable = resolvable;
- if (gSettings.machine_readable)
- cout << "Installing: " + resolvable->name() << endl;
- else
- cout << boost::format(_("Installing: %s-%s"))
- % resolvable->name() % resolvable->edition() << endl;
+
+ stringstream s;
+ s << (boost::format(_("Installing: %s-%s"))
+ % resolvable->name() % resolvable->edition());
+ display_progress ( "install-resolvable", cout, s.str(), 0);
}
virtual bool progress(int value, zypp::Resolvable::constPtr resolvable)
virtual void finish( zypp::Resolvable::constPtr /*resolvable*/, Error error, const std::string & reason, RpmLevel level )
{
- display_done (cout);
+ display_done ( "install-resolvable", cout);
if (error != NO_ERROR) {
cerr << level;
}
#include <boost/format.hpp>
#include <zypp/base/Logger.h>
+#include <zypp/base/String.h>
#include <zypp/ZYppCallbacks.h>
#include <zypp/Pathname.h>
#include <zypp/KeyRing.h>
zypp::Pathname _patch;
zypp::ByteCount _patch_size;
- void display_step( const std::string &what, int value )
+ void display_step( const std::string &id, const std::string &what, int value )
{
- display_progress (cout_v, what, value);
+ display_progress ("download-resolvable", cout_v, what, value);
}
// Dowmload delta rpm:
virtual bool progressDeltaDownload( int value )
{
// TranslatorExplanation This text is a progress display label e.g. "Downloading delta [42%]"
- display_step( _("Downloading delta") /*+ _delta.asString()*/, value );
+ display_step( "apply-delta", _("Downloading delta") /*+ _delta.asString()*/, value );
return true;
}
virtual void finishDeltaDownload()
{
- display_done (cout_v);
+ display_done ("download-resolvable", cout_v);
}
// Apply delta rpm:
virtual void progressDeltaApply( int value )
{
// TranslatorExplanation This text is a progress display label e.g. "Applying delta [42%]"
- display_step( _("Applying delta") /* + _delta.asString()*/, value );
+ display_step( "apply-delta", _("Applying delta") /* + _delta.asString()*/, value );
}
virtual void problemDeltaApply( const std::string & description )
virtual void finishDeltaApply()
{
- display_done (cout_v);
+ display_done ("apply-delta", cout_v);
}
// Dowmload patch rpm:
virtual bool progressPatchDownload( int value )
{
// TranslatorExplanation This text is a progress display label e.g. "Applying patch rpm [42%]"
- display_step( _("Applying patch rpm") /* + _patch.asString() */, value );
+ display_step( "apply-delta", _("Applying patch rpm") /* + _patch.asString() */, value );
return true;
}
virtual void finishPatchDownload()
{
- display_done (cout_v);
+ display_done ("apply-delta", cout_v);
}
virtual bool progress(int value, zypp::Resolvable::constPtr /*resolvable_ptr*/)
{
// TranslatorExplanation This text is a progress display label e.g. "Downloading [42%]"
- display_step( _("Downloading") /* + resolvable_ptr->name() */, value );
+ display_step( "download-resolvable", _("Downloading") /* + resolvable_ptr->name() */, value );
return true;
}
virtual void finish( zypp::Resolvable::constPtr /*resolvable_ptr*/, Error error, const std::string & reason )
{
- display_done (cout_v);
+ display_done ("download-resolvable", cout_v);
display_error (error, reason);
}
};
//std::cout << "TICK!" << std::endl;
if ( data.reportAlive() )
{
- display_tick (cout, data.name() );
+ display_tick (zypp::str::numstring(data.numericId()), cout, data.name() );
}
else
{
- display_progress (cout, data.name() , data.val() );
+ display_progress ( zypp::str::numstring(data.numericId()), cout, data.name() , data.val() );
}
virtual void finish( const zypp::ProgressData &data )
{
- display_done(cout, data.name() );
+ display_done(zypp::str::numstring(data.numericId()), cout, data.name() );
}
};
void display_step( int value )
{
- display_progress (cout, "(" + _repo.info().alias() + ") " + _task , value);
+ display_progress ( "repo", cout, "(" + _repo.info().alias() + ") " + _task , value);
}
virtual bool progress( int value )
virtual Action problem( zypp::Repository /*repo*/, Error error, const std::string & description )
{
- display_done (cout);
+ display_done ("repo", cout);
display_error (error, description);
return (Action) read_action_ari (ABORT);
}
if (boost::algorithm::starts_with (task, "Reading patch"))
cout << '\r' << flush;
else
- display_done (cout);
+ display_done ("repo", cout);
display_error (error, reason);
}
// === process options ===
if (gopts.count("terse"))
+ {
gSettings.machine_readable = true;
+ cout << "<?xml version='1.0'?>" << endl;
+ cout << "<stream>" << endl;
+ }
if (gopts.count("disable-repositories") ||
gopts.count("disable-system-sources"))
cond_load_resolvables();
establish ();
- cout << "<?xml version='1.0'?>" << endl;
cout << "<update-status version=\"0.4\">" << endl;
cout << "<update-list>" << endl;
if (!xml_list_patches ()) // Only list updates if no
}
} say_goodbye __attribute__ ((__unused__));
+ if ( gSettings.machine_readable )
+ cout << "</stream>" << endl;
+
// set locale
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);