Author: jkupec
Date: Mon Feb 18 11:25:20 2008
New Revision: 8776
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8776&view=rev
Log:
- extending xmlout support
Modified:
trunk/zypper/src/output/Out.cc
trunk/zypper/src/output/Out.h
trunk/zypper/src/output/OutNormal.cc
trunk/zypper/src/output/OutNormal.h
trunk/zypper/src/output/OutXML.cc
trunk/zypper/src/output/OutXML.h
trunk/zypper/src/zypper-callbacks.cc
trunk/zypper/src/zypper-repo-callbacks.h
trunk/zypper/src/zypper-repos.cc
trunk/zypper/src/zypper-utils.cc
trunk/zypper/src/zypper-utils.h
trunk/zypper/src/zypper.cc
Modified: trunk/zypper/src/output/Out.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/Out.cc?rev=8776&r1=8775&r2=8776&view=diff
==============================================================================
--- trunk/zypper/src/output/Out.cc (original)
+++ trunk/zypper/src/output/Out.cc Mon Feb 18 11:25:20 2008
@@ -3,4 +3,11 @@
Out::~Out()
{
-}
\ No newline at end of file
+}
+
+bool Out::progressFilter()
+{
+ if (this->verbosity() < Out::NORMAL)
+ return true;
+ return false;
+}
Modified: trunk/zypper/src/output/Out.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/Out.h?rev=8776&r1=8775&r2=8776&view=diff
==============================================================================
--- trunk/zypper/src/output/Out.h (original)
+++ trunk/zypper/src/output/Out.h Mon Feb 18 11:25:20 2008
@@ -15,10 +15,14 @@
class Out : private zypp::base::NonCopyable
{
public:
+ /** Verbosity levels. */
typedef enum
{
+ /** Only important messages (no progress or status, only the result). */
QUIET = 0,
+ /** */
NORMAL = 1,
+ /** More detailed description of the operations. */
HIGH = 2,
DEBUG = 3
} Verbosity;
@@ -35,19 +39,63 @@
virtual ~Out();
public:
+ /**
+ * Show an info message.
+ *
+ * \param msg The message to be displayed.
+ * \param verbosity Minimal level o verbosity in which the message will be
+ * shown. Out::QUIET means the message will be always be
+ * displayed. Out::HIGH means the message will be displayed
+ * only if the current verbosity level is HIGH (-v) or DEBUG
+ * (-vv).
+ * \param mask Determines the types of output for which is this message
+ * intended. By default, the message will be shown in all
+ * types of output.
+ */
virtual void info(const std::string & msg, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL) = 0;
+
+ /**
+ * Show warning.
+ *
+ * \param msg The warning message to be displayed.
+ * \param verbosity Minimal level o verbosity in which the message will be
+ * shown. Out::QUIET means the message will be always be
+ * displayed. Out::HIGH means the message will be displayed
+ * only if the current verbosity level is HIGH (-v) or DEBUG
+ * (-vv).
+ * \param mask Determines the types of output for which is this message
+ * intended. By default, the message will be shown in all
+ * types of output.
+ */
virtual void warning(const std::string & msg, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL) = 0;
+
+ /**
+ * Show an error message and an optional hint.
+ *
+ * \param problem_desc
+ * \param hint
+ */
virtual void error(const std::string & problem_desc, const std::string & hint = "") = 0;
+
+ /**
+ *
+ */
virtual void error(const zypp::Exception & e,
const std::string & problem_desc,
const std::string & hint = "") = 0;
+
// virtual void table()
// virtual void text()
// progress
- virtual void progressStart() = 0;
- virtual void progress() = 0;
- virtual void progressEnd() = 0;
+ virtual void progressStart(const std::string & id,
+ const std::string & label,
+ bool is_tick = false) = 0;
+ virtual void progress(const std::string & id,
+ const std::string & label,
+ int value = -1) = 0;
+ virtual void progressEnd(const std::string & id,
+ const std::string & label) = 0;
// progress with download rate
virtual void dwnldProgressStart() = 0;
@@ -70,6 +118,14 @@
*/
virtual bool mine(Type type) = 0;
+ /**
+ * Determine whether to show progress.
+ *
+ * \return <tt>true</tt> if the progress should be filtered out,
+ * <tt>false</tt> if it should be shown.
+ */
+ virtual bool progressFilter();
+
private:
Verbosity _verbosity;
Type _type;
Modified: trunk/zypper/src/output/OutNormal.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/OutNormal.cc?rev=8776&r1=8775&r2=8776&view=diff
==============================================================================
--- trunk/zypper/src/output/OutNormal.cc (original)
+++ trunk/zypper/src/output/OutNormal.cc Mon Feb 18 11:25:20 2008
@@ -1,10 +1,14 @@
#include <iostream>
+#include <sstream>
#include "OutNormal.h"
+#include "../AliveCursor.h"
using std::cout;
using std::cerr;
using std::endl;
+using std::string;
+using std::ostringstream;
OutNormal::~OutNormal()
{
@@ -45,22 +49,114 @@
void OutNormal::error(const std::string & problem_desc, const std::string & hint)
{
cerr << problem_desc;
- if (!hint.empty())
+ if (!hint.empty() && this->verbosity() > Out::QUIET)
cerr << endl << hint;
cerr << endl;
}
+// ----------------------------------------------------------------------------
+
+string OutNormal::reportZyppException(const zypp::Exception & e)
+{
+ ostringstream s;
+ if (e.historySize())
+ {
+ if (this->verbosity() > Out::NORMAL)
+ {
+ // print the whole history
+ s << e.historyAsString();
+ // this exception
+ s << " - " << e.asUserString();
+ }
+ else
+ // print the root cause only
+ s << *(--e.historyEnd());
+ }
+ else
+ s << e.asUserString();
+
+ return s.str();
+}
+
+// ----------------------------------------------------------------------------
+
void OutNormal::error(const zypp::Exception & e,
- const std::string & problem_desc,
- const std::string & hint)
+ const string & problem_desc,
+ const string & hint)
+{
+ // problem
+ cerr << problem_desc << endl;
+
+ // cause
+ cerr << reportZyppException(e) << endl;
+
+ // hint
+ if (!hint.empty())
+ cerr << hint << endl;
+}
+
+// ----------------------------------------------------------------------------
+
+static void display_progress ( const std::string & id, const string & s, int percent)
+{
+ static AliveCursor cursor;
+
+ if ( percent == 100 )
+ cout << CLEARLN << cursor.done() << " " << s;
+ else
+ cout << CLEARLN << cursor++ << " " << s;
+ // dont display percents if invalid
+ if (percent >= 0 && percent <= 100)
+ cout << " [" << percent << "%]";
+ cout << std::flush;
+}
+
+// ----------------------------------------------------------------------------
+
+static void display_tick ( const std::string & id, const string & s)
{
+ static AliveCursor cursor;
+
+ cursor++;
+ cout << CLEARLN << cursor << " " << s;
+ cout << std::flush;
+}
+
+// ----------------------------------------------------------------------------
+
+void OutNormal::progressStart(const std::string & id,
+ const std::string & label,
+ bool is_tick)
+{
+ if (progressFilter())
+ return;
+ if (is_tick)
+ display_tick(id, label);
+ else
+ display_progress(id, label, 0);
}
+void OutNormal::progress(const std::string & id, const string & label, int value)
+{
+ if (progressFilter())
+ return;
+
+ if (value)
+ display_progress(id, label, value);
+ else
+ display_tick(id, label);
+}
+
+void OutNormal::progressEnd(const std::string & id, const string& label)
+{
+ static AliveCursor cursor;
+
+ if (progressFilter())
+ return;
-void OutNormal::progressStart(){}
-void OutNormal::progress(){}
-void OutNormal::progressEnd(){}
+ cout << CLEARLN << cursor.done() << " " << label << std::flush << endl;
+}
void OutNormal::dwnldProgressStart(){}
void OutNormal::dwnldProgress(){}
Modified: trunk/zypper/src/output/OutNormal.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/OutNormal.h?rev=8776&r1=8775&r2=8776&view=diff
==============================================================================
--- trunk/zypper/src/output/OutNormal.h (original)
+++ trunk/zypper/src/output/OutNormal.h Mon Feb 18 11:25:20 2008
@@ -18,9 +18,13 @@
const std::string & hint = "");
// progress
- void progressStart();
- void progress();
- void progressEnd();
+ virtual void progressStart(const std::string & id,
+ const std::string & label,
+ bool is_tick = false);
+ virtual void progress(const std::string & id,
+ const std::string & label,
+ int value = -1);
+ virtual void progressEnd(const std::string & id, const std::string & label);
// progress with download rate
void dwnldProgressStart();
@@ -29,8 +33,10 @@
protected:
virtual bool mine(Type type);
+
private:
bool infoWarningFilter(Verbosity verbosity, Type mask);
+ std::string reportZyppException(const zypp::Exception & e);
};
#endif /*OUTNORMAL_H_*/
Modified: trunk/zypper/src/output/OutXML.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/OutXML.cc?rev=8776&r1=8775&r2=8776&view=diff
==============================================================================
--- trunk/zypper/src/output/OutXML.cc (original)
+++ trunk/zypper/src/output/OutXML.cc Mon Feb 18 11:25:20 2008
@@ -1,10 +1,12 @@
#include <iostream>
+#include <sstream>
#include "OutXML.h"
using std::cout;
using std::endl;
-
+using std::string;
+using std::ostringstream;
OutXML::OutXML(Verbosity verbosity) : Out(verbosity)
{
@@ -34,7 +36,7 @@
return false;
}
-void OutXML::info(const std::string & msg, Verbosity verbosity, Type mask)
+void OutXML::info(const string & msg, Verbosity verbosity, Type mask)
{
if (infoWarningFilter(verbosity, mask))
return;
@@ -42,30 +44,93 @@
cout << "" << msg << "</message>" << endl;
}
-void OutXML::warning(const std::string & msg, Verbosity verbosity, Type mask)
+void OutXML::warning(const string & msg, Verbosity verbosity, Type mask)
{
if (infoWarningFilter(verbosity, mask))
return;
cout << "" << msg << "</message>" << endl;
}
-void OutXML::error(const std::string & problem_desc, const std::string & hint)
+void OutXML::error(const string & problem_desc, const string & hint)
{
cout << "" << problem_desc << "</message>" << endl;
//! \todo hint
}
+string OutXML::reportZyppException(const zypp::Exception & e)
+{
+ ostringstream s;
+ if (e.historySize())
+ {
+ if (this->verbosity() > Out::NORMAL)
+ {
+ // print the whole history
+ s << e.historyAsString();
+ // this exception
+ s << " - " << e.asUserString();
+ }
+ else
+ // print the root cause only
+ s << *(--e.historyEnd());
+ }
+ else
+ s << e.asUserString();
+
+ return s.str();
+}
+
+
void OutXML::error(const zypp::Exception & e,
- const std::string & problem_desc,
- const std::string & hint)
+ const string & problem_desc,
+ const string & hint)
+{
+ ostringstream s;
+
+ // problem
+ s << problem_desc << endl;
+ // cause
+ s << reportZyppException(e) << endl;
+ // hint
+ if (!hint.empty())
+ s << hint << endl;
+
+ cout << "" << s.str() << "</message>" << endl;
+}
+
+void OutXML::progressStart(const string & id,
+ const string & label,
+ bool is_tick)
{
-
+ if (progressFilter())
+ return;
+
+ cout << "