From eaab7e0bcf2af92bbe50d82edfb53314b6a5e232 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 2 Aug 2007 16:30:35 +0000 Subject: [PATCH] xml output in terse mode --- src/zypper-callbacks.cc | 21 ++++++++++++++++---- src/zypper-callbacks.h | 11 ++++++----- src/zypper-media-callbacks.h | 6 +++--- src/zypper-rpm-callbacks.h | 45 ++++++++++++++++++++++++++----------------- src/zypper-source-callbacks.h | 33 ++++++++++++++++--------------- src/zypper.cc | 8 +++++++- 6 files changed, 77 insertions(+), 47 deletions(-) diff --git a/src/zypper-callbacks.cc b/src/zypper-callbacks.cc index 05c2b33..a46ce3a 100644 --- a/src/zypper-callbacks.cc +++ b/src/zypper-callbacks.cc @@ -6,11 +6,14 @@ 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 << "" << endl; return; + } if ( percent == 100 ) out << CLEARLN << cursor.done() << " " << s; @@ -24,11 +27,14 @@ void display_progress (ostream & out, const string& s, int percent) { // ---------------------------------------------------------------------------- -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 << "" << endl; return; + } cursor++; out << CLEARLN << cursor << " " << s; @@ -37,11 +43,14 @@ void display_tick (ostream & out, const string& 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 << "" << endl; return; + } out << CLEARLN << cursor.done() << " " << s; out << flush; @@ -50,10 +59,14 @@ void display_done (ostream & out, const string& s) { // ---------------------------------------------------------------------------- -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; } diff --git a/src/zypper-callbacks.h b/src/zypper-callbacks.h index 40baca6..500c081 100644 --- a/src/zypper-callbacks.h +++ b/src/zypper-callbacks.h @@ -25,15 +25,16 @@ enum Error { 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 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") diff --git a/src/zypper-media-callbacks.h b/src/zypper-media-callbacks.h index 5913f32..f853569 100644 --- a/src/zypper-media-callbacks.h +++ b/src/zypper-media-callbacks.h @@ -64,20 +64,20 @@ namespace ZmartRecipients 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); } }; diff --git a/src/zypper-rpm-callbacks.h b/src/zypper-rpm-callbacks.h index 6bdec6b..9eced08 100644 --- a/src/zypper-rpm-callbacks.h +++ b/src/zypper-rpm-callbacks.h @@ -35,8 +35,15 @@ struct MessageResolvableReportReceiver : public zypp::callback::ReceiveReporttext() << endl; + if ( !gSettings.machine_readable ) + { + cout_v << message << endl; // [message]important-msg-1.0-1 + cout_n << message->text() << endl; + return; + } + + cout << "" << message->text() << "" << endl; + //! \todo in interactive mode, wait for ENTER? } }; @@ -74,13 +81,13 @@ struct ScriptResolvableReportReceiver : public zypp::callback::ReceiveReportname() % 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; } @@ -150,7 +156,7 @@ struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReportname() % 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) @@ -210,7 +219,7 @@ struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReport #include +#include #include #include #include @@ -79,9 +80,9 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReportname() */, value ); + display_step( "download-resolvable", _("Downloading") /* + resolvable_ptr->name() */, value ); return true; } @@ -207,7 +208,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport" << endl; + cout << "" << endl; + } if (gopts.count("disable-repositories") || gopts.count("disable-system-sources")) @@ -1216,7 +1220,6 @@ int one_command(const ZypperCommand & command, int argc, char **argv) cond_load_resolvables(); establish (); - cout << "" << endl; cout << "" << endl; cout << "" << endl; if (!xml_list_patches ()) // Only list updates if no @@ -1447,6 +1450,9 @@ int main(int argc, char **argv) } } say_goodbye __attribute__ ((__unused__)); + if ( gSettings.machine_readable ) + cout << "" << endl; + // set locale setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); -- 2.7.4