- removed obsolete cout_v, cerr_v macros
authorJan Kupec <jkupec@suse.cz>
Fri, 22 Feb 2008 13:06:11 +0000 (13:06 +0000)
committerJan Kupec <jkupec@suse.cz>
Fri, 22 Feb 2008 13:06:11 +0000 (13:06 +0000)
src/output/OutNormal.cc
src/zypper-keyring-callbacks.h
src/zypper-main.cc
src/zypper-main.h
src/zypper-media-callbacks.h
src/zypper-misc.cc
src/zypper-misc.h
src/zypper-repos.cc
src/zypper-search.h
src/zypper-utils.cc

index e0b5a52..c5b52b8 100644 (file)
@@ -47,7 +47,7 @@ void OutNormal::warning(const std::string & msg, Verbosity verbosity, Type mask)
 {
   if (infoWarningFilter(verbosity, mask))
     return;
-  info(msg, verbosity, mask);
+  info(_("Warning: ") + msg, verbosity, mask);
 }
 
 void OutNormal::error(const std::string & problem_desc, const std::string & hint)
index 09eb4ee..41e5a6e 100644 (file)
@@ -38,7 +38,9 @@ namespace zypp {
         if (_gopts.no_gpg_checks)
         {
           MIL << "Accepting unsigned file (" << file << ")" << endl;
-          cout_v << boost::format(_("Warning: Accepting an unsigned file %s.")) % file;
+          Zypper::instance()->out().warning(boost::str(
+            boost::format(_("Warning: Accepting an unsigned file %s.")) % file),
+            Out::HIGH);
           return true;
         }
 
@@ -63,9 +65,9 @@ namespace zypp {
         if (_gopts.no_gpg_checks)
         {
           MIL << "Accepting file signed with an unknown key (" << file << "," << id << ")" << endl;
-          cout_n << boost::format(
+          Zypper::instance()->out().warning(boost::str(boost::format(
               _("Warning: Accepting file %s signed with an unknown key %s."))
-              % file % id;
+              % file % id));
           return true;
         }
 
@@ -84,9 +86,9 @@ namespace zypp {
         {
           MIL << boost::format("Automatically trusting key id %s, %s, fingerprint %s")
               % keyid % keyname % fingerprint << endl;
-          cout_n << boost::format(
+          Zypper::instance()->out().info(boost::str(boost::format(
               _("Automatically trusting key id %s, %s, fingerprint %s"))
-              % keyid % keyname % fingerprint << endl;
+              % keyid % keyname % fingerprint));
           return true;
         }
 
@@ -107,23 +109,21 @@ namespace zypp {
               "Ignoring failed signature verification for %s"
               " with public key id %s, %s, fingerprint %s")
               % file % keyid % keyname % fingerprint << endl;
-          cerr << boost::format(
+          Zypper::instance()->out().warning(boost::str(boost::format(
               _("Warning: Ignoring failed signature verification for %s"
-                " with public key id %s, %s, fingerprint %s!") +
-               string("\n") +
-               _("Double-check this is not caused by some malicious"
+                " with public key id %s, %s, fingerprint %s!\n"
+                "Double-check this is not caused by some malicious"
                 " changes in the file!"))
-              %file % keyid % keyname % fingerprint << endl;
+              %file % keyid % keyname % fingerprint),
+              Out::QUIET);
           return true;
         }
 
         std::string question = boost::str(boost::format(
             _("Signature verification failed for %s"
-              " with public key id %s, %s, fingerprint %s.") +
-             string("\n") +
-             _("Warning: This might be caused by a malicious change in the file!") +
-             string("\n") +
-             _("Continuing is risky! Continue anyway?"))
+              " with public key id %s, %s, fingerprint %s.\n"
+              "Warning: This might be caused by a malicious change in the file!\n"
+              "Continuing is risky! Continue anyway?"))
             % file % keyid % keyname % fingerprint);
         return read_bool_answer(PROMPT_YN_GPG_CHECK_FAILED_IGNORE, question, false);
       }
@@ -158,9 +158,10 @@ namespace zypp {
           WAR << boost::format(
               "Ignoring failed digest verification for %s (expected %s, found %s).")
               % file % requested % found << endl;
-          cerr << boost::format(
+          Zypper::instance()->out().warning(boost::str(boost::format(
               _("Ignoring failed digest verification for %s (expected %s, found %s)."))
-              % file % requested % found << endl;
+              % file % requested % found),
+              Out::QUIET);
           return true;
         }
 
index 378d44b..ddd6d3f 100644 (file)
@@ -13,8 +13,6 @@
 
 using namespace std;
 
-ostream no_stream(NULL);
-
 RpmCallbacks rpm_callbacks;
 SourceCallbacks source_callbacks;
 MediaCallbacks media_callbacks;
index 03d3443..618c31d 100644 (file)
 #define ZYPPER_EXIT_INF_RESTART_NEEDED     103 // restart of package manager itself needed
 #define ZYPPER_EXIT_INF_CAP_NOT_FOUND      104 // given capability not found (for install/remove)
 
-
-#define VERBOSITY_NORMAL 0
-#define VERBOSITY_MEDIUM 1
-#define VERBOSITY_HIGH 2
-
-/**
- * Macro to filter output above the current verbosity level.
- *
- * \see Output Macros
- * \see GlobalOptions::verbosity
- */
-#define COND_STREAM(STREAM,LEVEL) ((Zypper::instance()->globalOpts().verbosity >= LEVEL) ? STREAM : no_stream)
-
-/** \name Output Macros
- * Alway use these macros to produce output so that the verbosity options
- * like -v or --quiet are respected. Use standard cout and cerr only in
- * cases where it is desirable to ignore them (e.g. help texts (when -h is
- * used) or brief error messages must always be displayed, even if --quiet
- * has been specified).
- */
-//!@{
-//! normal output
-#define cout_n COND_STREAM(cout, VERBOSITY_NORMAL)
-//! verbose output
-#define cout_v COND_STREAM(cout, VERBOSITY_MEDIUM)
-//! verbose error output
-#define cerr_v COND_STREAM(cerr, VERBOSITY_MEDIUM)
-//! debug info output
-#define cout_vv COND_STREAM(cout, VERBOSITY_HIGH)
-//! debug error output (details)
-#define cerr_vv COND_STREAM(cerr, VERBOSITY_HIGH)
-//!@}
-
 // undefine _ and _PL macros from libzypp
 #ifdef _
 #undef _
index eb46f6a..b8a057f 100644 (file)
@@ -46,8 +46,8 @@ namespace ZmartRecipients
     {
       if (is_changeable_media(url))
       {
-        cerr << endl; // may be in the middle of RepoReport or ProgressReport
-        cerr << description << endl;
+        //cerr << endl; // may be in the middle of RepoReport or ProgressReport \todo check this
+        Zypper::instance()->out().error(description);
   
         std::string request = boost::str(boost::format(
             // TranslatorExplanation translate letters 'y' and 'n' to whathever is appropriate for your language.
index ece8ef2..6f8c03e 100644 (file)
@@ -71,14 +71,14 @@ ResObject::Kind string_to_kind (const string &skind)
 // copied from yast2-pkg-bindings:PkgModuleFunctions::DoProvideNameKind
 bool ProvideProcess::operator()( const PoolItem& provider )
 {
-  cerr_vv << "Considering " << provider << endl;
+  DBG << "Considering " << provider << endl;
   // 1. compatible arch
   // 2. best arch
   // 3. best edition
 
   // check the version if it's specified
   if (!version.empty() && version != provider->edition().asString()) {
-    cerr_vv << format ("Skipping version %s (requested: %s)")
+    DBG << format ("Skipping version %s (requested: %s)")
       % provider->edition().asString() % version << endl;
     return true;
   }
@@ -87,25 +87,25 @@ bool ProvideProcess::operator()( const PoolItem& provider )
     // deselect the item if it's already selected,
     // only one item should be selected
     if (provider.status().isToBeInstalled()) {
-      cerr_vv << "  Deselecting" << endl;
+      DBG << "  Deselecting" << endl;
       provider.status().resetTransact(whoWantsIt);
     }
 
     // regarding items which are installable only
     if (!provider->arch().compatibleWith( _architecture )) {
-      cerr_vv << format ("provider %s has incompatible arch '%s'")
+      DBG << format ("provider %s has incompatible arch '%s'")
         % provider->name() % provider->arch().asString() << endl;
     }
     else if (!item) {
-      cerr_vv << "  First match" << endl;
+      DBG << "  First match" << endl;
       item = provider;
     }
     else if (item->arch().compare( provider->arch() ) < 0) {
-      cerr_vv << "  Better arch" << endl;
+      DBG << "  Better arch" << endl;
       item = provider;
     }
     else if (item->edition().compare( provider->edition() ) < 0) {
-      cerr_vv << "  Better edition" << endl;
+      DBG << "  Better edition" << endl;
       item = provider;
     }
   }
@@ -172,7 +172,7 @@ struct NewerVersionGetter
 };
 
 // on error print a message and return noCap
-Capability safe_parse_cap (const Zypper & zypper,
+Capability safe_parse_cap (Zypper & zypper,
                            const ResObject::Kind &kind, const string & capstr)
 {
   Capability cap;
@@ -180,17 +180,17 @@ Capability safe_parse_cap (const Zypper & zypper,
     // expect named caps as NAME[OP<EDITION>]
     // transform to NAME[ OP <EDITION>] (add spaces)
     string new_capstr = capstr;
-    cout_vv << "capstr: " << capstr << endl;
+    DBG << "capstr: " << capstr << endl;
     string::size_type op_pos = capstr.find_first_of("<>=");
     if (op_pos != string::npos)
     {
       new_capstr.insert(op_pos, " ");
-      cout_vv << "new capstr: " << new_capstr << endl;
+      DBG << "new capstr: " << new_capstr << endl;
       op_pos = new_capstr.find_first_not_of("<>=", op_pos + 1);
       if (op_pos != string::npos && new_capstr.size() > op_pos)
       {
         new_capstr.insert(op_pos, " ");
-        cout_vv << "new capstr: " << new_capstr << endl;
+        DBG << "new capstr: " << new_capstr << endl;
       }
     }
     // if we are about to install stuff and
@@ -221,7 +221,7 @@ Capability safe_parse_cap (const Zypper & zypper,
         // newer version found
         if (nvg.found)
         {
-          cout_vv << "installed resolvable named " << capstr
+          DBG << "installed resolvable named " << capstr
             << " found, changing capability to " << new_capstr << endl;
           new_capstr = capstr + " > " + vg.edition.asString();
         }
@@ -232,7 +232,8 @@ Capability safe_parse_cap (const Zypper & zypper,
   catch (const Exception& e) {
     //! \todo check this handling (should we fail or set a special exit code?)
     ZYPP_CAUGHT(e);
-    cerr << format (_("Cannot parse capability '%s'.")) % capstr << endl;
+    zypper.out().error(boost::str(
+      format(_("Cannot parse capability '%s'.")) % capstr));
   }
   return cap;
 }
@@ -246,16 +247,17 @@ void mark_for_install(Zypper & zypper,
 {
   // name and kind match:
   ProvideProcess installer (ZConfig::instance().systemArchitecture(), "" /*version*/);
-  cout_vv << "Iterating over [" << kind << "]" << name << endl;
+  DBG << "Iterating over [" << kind << "]" << name << endl;
   invokeOnEach(
       God->pool().byIdentBegin(kind, name),
       God->pool().byIdentEnd(kind, name),
       zypp::functor::functorRef<bool,const zypp::PoolItem&> (installer));
 
-  cout_vv << "... done" << endl;
+  DBG << "... done" << endl;
   if (!installer.item) {
     // TranslatorExplanation e.g. "package 'pornview' not found"
-    cerr << format(_("%s '%s' not found")) % kind_to_string_localized(kind,1) % name << endl;
+    zypper.out().warning(boost::str(
+      format(_("%s '%s' not found")) % kind_to_string_localized(kind,1) % name));
     WAR << format("%s '%s' not found") % kind % name << endl;
     zypper.setExitCode(ZYPPER_EXIT_INF_CAP_NOT_FOUND);
     return;
@@ -272,18 +274,25 @@ void mark_for_install(Zypper & zypper,
       installer.item.status().setTransact( true, zypp::ResStatus::USER );
     }
 
-    cout_n << format(_("skipping %s '%s' (the newest version already installed)")) % kind_to_string_localized(kind,1) % name << endl;
+    zypper.out().info(boost::str(format(
+      _("skipping %s '%s' (the newest version already installed)"))
+      % kind_to_string_localized(kind,1) % name));
   }
   else {
 
-    // TODO don't use setToBeInstalled for this purpose but higher level solver API
+    //! \todo don't use setToBeInstalled for this purpose but higher level solver API
     bool result = installer.item.status().setToBeInstalled( zypp::ResStatus::USER );
     if (!result)
     {
       // this is because the resolvable is installed and we are forcing.
       installer.item.status().setTransact( true, zypp::ResStatus::USER );
-      //cerr << format(_("Failed to add '%s' to the list of packages to be installed.")) % name << endl;
-      //ERR << "Could not set " << name << " as to-be-installed" << endl;
+      if (!copts.count("force"))
+      {
+        zypper.out().error(boost::str(
+          format(_("Failed to add '%s' to the list of packages to be installed."))
+          % name));
+        ERR << "Could not set " << name << " as to-be-installed" << endl;
+      }
     }
   }
 }
@@ -298,12 +307,12 @@ struct DeleteProcess
   bool operator() ( const PoolItem& provider )
   {
     found = true;
-    cout_vv << "Marking for deletion: " << provider << endl;
+    DBG << "Marking for deletion: " << provider << endl;
     bool result = provider.status().setToBeUninstalled( zypp::ResStatus::USER );
     if (!result) {
-      cerr << format(
+      Zypper::instance()->out().error(boost::str(format(
           _("Failed to add '%s' to the list of packages to be removed."))
-          % provider.resolvable()->name() << endl;
+          % provider.resolvable()->name()));
       ERR << "Could not set " << provider.resolvable()->name()
           << " as to-be-uninstalled" << endl;
     }
@@ -320,16 +329,17 @@ void mark_for_uninstall(Zypper & zypper,
   // name and kind match:
 
   DeleteProcess deleter;
-  cerr_vv << "Iterating over " << name << endl;
+  DBG << "Iterating over " << name << endl;
   invokeOnEach( pool.byIdentBegin( kind, name ),
                pool.byIdentEnd( kind, name ),
                resfilter::ByInstalled(),
                zypp::functor::functorRef<bool,const zypp::PoolItem&> (deleter)
                );
-  cerr_vv << "... done" << endl;
+  DBG << "... done" << endl;
   if (!deleter.found) {
     // TranslatorExplanation e.g. "package 'pornview' not found"
-    cerr << format(_("%s '%s' not found")) % kind_to_string_localized(kind,1) % name << endl;
+    zypper.out().error(boost::str(
+      format(_("%s '%s' not found")) % kind_to_string_localized(kind,1) % name));
     zypper.setExitCode(ZYPPER_EXIT_INF_CAP_NOT_FOUND);
     return;
   }
@@ -360,7 +370,7 @@ bool mark_by_name_edition (...)
 
 */
 
-void mark_by_capability (const Zypper & zypper,
+void mark_by_capability (Zypper & zypper,
                          bool install_not_remove,
                         const ResObject::Kind &kind,
                         const string &capstr )
@@ -368,15 +378,15 @@ void mark_by_capability (const Zypper & zypper,
   Capability cap = safe_parse_cap (zypper, kind, capstr);
 
   if (!cap.empty()) {
-    cout_vv << "Capability: " << cap << endl;
+    DBG << "Capability: " << cap << endl;
 
     Resolver_Ptr resolver = zypp::getZYpp()->resolver();
     if (install_not_remove) {
-      cerr_vv << "Adding requirement " << cap << endl;
+      DBG << "Adding requirement " << cap << endl;
       resolver->addRequire (cap);
     }
     else {
-      cerr_vv << "Adding conflict " << cap << endl;
+      DBG << "Adding conflict " << cap << endl;
       resolver->addConflict (cap);
     }
   }
@@ -439,6 +449,7 @@ ostream& operator << (ostream & stm, ios::iostate state)
 tribool show_problem (Zypper & zypper,
                       const ResolverProblem & prob, ProblemSolutionList & todo)
 {
+  //! \todo use Out
   ostream& stm = cerr;
   string det;
   stm << _("Problem: ") << prob.description () << endl;
@@ -507,7 +518,6 @@ tribool show_problem (Zypper & zypper,
 bool show_problems(Zypper & zypper)
 {
   bool retry = true;
-  ostream& stm = cerr;
   Resolver_Ptr resolver = zypp::getZYpp()->resolver();
   ResolverProblemList rproblems = resolver->problems ();
   ResolverProblemList::iterator
@@ -517,12 +527,12 @@ bool show_problems(Zypper & zypper)
   ProblemSolutionList todo;
 
   // display the number of problems
-  if (rproblems.size() > 1) {
-    stm << format (_("%s Problems:")) % rproblems.size() << endl;
-  }
-  else if (rproblems.empty()) {
+  if (rproblems.size() > 1)
+    zypper.out().info(boost::str(format(_("%s Problems:")) % rproblems.size()));
+  else if (rproblems.empty())
+  {
     // should not happen! If solve() failed at least one problem must be set!
-    stm << _("Specified capability not found") << endl;
+    zypper.out().error(_("Specified capability not found"));
     zypper.setExitCode(ZYPPER_EXIT_INF_CAP_NOT_FOUND);
     return false;
   }
@@ -531,13 +541,14 @@ bool show_problems(Zypper & zypper)
   //! \todo handle resolver problems caused by --capability mode arguments specially to give proper output (bnc #337007)
   if (rproblems.size() > 1)
   {
-    for (i = b; i != e; ++i) {
-      stm << _("Problem: ") << (*i)->description () << endl;
-    }
+    for (i = b; i != e; ++i)
+      zypper.out().info(boost::str(
+        format(_("Problem: %s")) % (*i)->description()));
   }
   // now list all problems with solution proposals
-  for (i = b; i != e; ++i) {
-    stm << endl;
+  for (i = b; i != e; ++i)
+  {
+    zypper.out().info("", Out::NORMAL, Out::TYPE_NORMAL); // visual separator
     tribool stopnow = show_problem(zypper, *(*i), todo);
     if (! indeterminate (stopnow)) {
       retry = stopnow == true;
@@ -547,7 +558,7 @@ bool show_problems(Zypper & zypper)
 
   if (retry)
   {
-    cout_n << _("Resolving dependencies...") << endl;
+    zypper.out().info(_("Resolving dependencies..."));
     resolver->applySolutions (todo);
   }
   return retry;
@@ -559,7 +570,9 @@ void show_summary_resolvable_list(const string & label,
                                   KindToResObjectSet::const_iterator it,
                                   int verbosity)
 {
-  cout << endl << label << endl;
+  Out & out = Zypper::instance()->out();
+  ostringstream s;
+  s << endl << label << endl;
 
   // get terminal width from COLUMNS env. var.
   unsigned cols = 0, cols_written = 0;
@@ -578,35 +591,37 @@ void show_summary_resolvable_list(const string & label,
   {
     ResObject::constPtr res(*resit);
 
-    if (verbosity == VERBOSITY_NORMAL)
+    if (out.verbosity() == Out::NORMAL)
     {
       // watch the terminal widht
       if (cols_written == 0)
-        cout << INDENT;
+        s << INDENT;
       else if (cols_written + res->name().size() + 1  > cols)
       {
-        cout << endl;
+        s << endl;
         cols_written = 0;
       }
 
       cols_written += res->name().size();
     }
     else
-      cout << INDENT;
+      s << INDENT;
 
     // resolvable name
-    cout << res->name() << (verbosity ? "" : " ");
+    s << res->name() << (out.verbosity() > Out::NORMAL ? "" : " ");
     // plus edition and architecture for verbose output
-    cout_v << "-" << res->edition() << "." << res->arch();
+    //cout_v << "-" << res->edition() << "." << res->arch();
     // plus repo providing this package
-    if (!res->repoInfo().alias().empty())
-      cout_v << "  (" << res->repoInfo().name() << ")";
+    //if (!res->repoInfo().alias().empty())
+      //cout_v << "  (" << res->repoInfo().name() << ")";
     // new line after each package in the verbose mode
-    cout_v << endl;
+    //cout_v << endl;
   }
 
-  if (verbosity == VERBOSITY_NORMAL)
-    cout << endl;
+  if (out.verbosity() == Out::NORMAL)
+    s << endl;
+
+  out.info(s.str(), Out::QUIET); //! \todo special output needed for this
 }
 
 
@@ -666,15 +681,11 @@ int show_summary(Zypper & zypper)
 
   if (retv == -1)
   {
-    if (zypper.globalOpts().machine_readable)
-      cout << "<message type=\"warning\">" << _("Nothing to do.") << "</message>" << endl;
-    else
-      cout << _("Nothing to do.") << endl;
-
+    zypper.out().info(_("Nothing to do."));
     return retv;
   }
 
-  // no output for machines for now
+  //! \todo no output for machines for now
   if (zypper.globalOpts().machine_readable)
     return retv;
 
@@ -788,31 +799,32 @@ int show_summary(Zypper & zypper)
     show_summary_resolvable_list(title, it, zypper.globalOpts().verbosity);
   }
 
-  cout << endl;
+  zypper.out().info("", Out::NORMAL, Out::TYPE_NORMAL); // visual separator
 
+  ostringstream s;
   if (download_size > 0)
   {
-    cout_n << format(_("Overall download size: %s.")) % download_size;
-    cout_n << " ";
+    s << format(_("Overall download size: %s.")) % download_size;
+    s << " ";
   }
   if (new_installed_size > 0)
     // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
-    cout_n << format(_("After the operation, additional %s will be used."))
+    s << format(_("After the operation, additional %s will be used."))
         % new_installed_size.asString(0,1,1);
   //! \todo uncomment the following for bug #309112
   /*
   else if (new_installed_size == 0)
-    cout_n << _("No additional space will be used or freed after the operation.");*/
+    s << _("No additional space will be used or freed after the operation.");*/
   else
   {
     // get the absolute size
     ByteCount abs;
     abs = (-new_installed_size);
     // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
-    cout_n << format(_("After the operation, %s will be freed."))
+    s << format(_("After the operation, %s will be freed."))
         % abs.asString(0,1,1);
   }
-  cout_n << endl;
+  zypper.out().info(s.str());
 
   return retv;
 }
@@ -875,14 +887,16 @@ bool resolve(Zypper & zypper)
       force_resolution = false;
     else
     {
-      cerr << format(_("Invalid value '%s' of the %s parameter"))
-          % value % "force-resolution" << endl;
-      cerr << format(_("Valid values are '%s' and '%s'")) % "on" % "off" << endl;
+      zypper.out().error(
+        boost::str(format(_("Invalid value '%s' of the %s parameter"))
+          % value % "force-resolution"),
+        boost::str(format(_("Valid values are '%s' and '%s'")) % "on" % "off"));
     }
 
     if (count > 1)
-      cout << format(_("Considering only the first value of the %s parameter, ignoring the rest"))
-          % "force-resolution" << endl;
+      zypper.out().warning(boost::str(format(
+        _("Considering only the first value of the %s parameter, ignoring the rest"))
+          % "force-resolution"));
   }
 
   // if --force-resolution was not specified on the command line, force
@@ -898,11 +912,12 @@ bool resolve(Zypper & zypper)
   }
 
   DBG << "force resolution: " << force_resolution << endl;
-  cout_v << _("Force resolution:") << " " <<
-      (force_resolution ? _("Yes") : _("No")) << endl;
+  ostringstream s;
+  s << _("Force resolution:") << " " << (force_resolution ? _("Yes") : _("No"));
+  zypper.out().info(s.str(), Out::HIGH);
   God->resolver()->setForceResolve( force_resolution );
 
-  cout_v << _("Resolving dependencies...") << endl;
+  zypper.out().info(_("Resolving dependencies..."), Out::HIGH);
   DBG << "Calling the solver..." << endl;
   return God->resolver()->resolvePool();
 }
@@ -911,7 +926,7 @@ void patch_check ()
 {
   Out & out = Zypper::instance()->out();
 
-  cout_vv << "patch check" << endl;
+  DBG << "patch check" << endl;
   gData.patches_count = gData.security_patches_count = 0;
 
   ResPool::byKind_iterator
@@ -1010,7 +1025,7 @@ void show_patches(Zypper & zypper)
   tbl.sort (1);                        // Name
 
   if (tbl.empty())
-    cout_n << _("No needed patches found.") << endl;
+    zypper.out().info(_("No needed patches found."));
   else
     // display the result, even if --quiet specified
     cout << tbl;
@@ -1096,7 +1111,7 @@ bool xml_list_patches ()
 
 // ----------------------------------------------------------------------------
 
-void list_patch_updates(const Zypper & zypper, bool best_effort)
+void list_patch_updates(Zypper & zypper, bool best_effort)
 {
   Table tbl;
   Table pm_tbl;        // only those that affect packagemanager: they have priority
@@ -1136,19 +1151,19 @@ void list_patch_updates(const Zypper & zypper, bool best_effort)
 
   // those that affect the package manager go first
   // (TODO: user option for this?)
-  if (!pm_tbl.empty ()) {
-    if (!tbl.empty ()) {
-      cerr << _("WARNING: These are only the updates affecting the updater itself.\n"
-               "There are others available too.\n") << flush;
-
-    }
+  if (!pm_tbl.empty ())
+  {
+    if (!tbl.empty ())
+      zypper.out().warning(
+        _("These are only the updates affecting the updater itself.\n"
+          "There are others available too.\n"));
     tbl = pm_tbl;
   }
 
   tbl.sort (1);                // Name
 
   if (tbl.empty())
-    cout_n << _("No updates found.") << endl;
+    zypper.out().info(_("No updates found."));
   else
     cout << tbl;
 }
@@ -1214,7 +1229,7 @@ find_updates( const ResObject::Kind &kind, Candidates &candidates )
   ResPool::byKind_iterator
     it = pool.byKindBegin (kind),
     e  = pool.byKindEnd (kind);
-  cerr_vv << "Finding update candidates" << endl;
+  DBG << "Finding update candidates" << endl;
   for (; it != e; ++it)
   {
     if (it->status().isUninstalled())
@@ -1224,15 +1239,15 @@ find_updates( const ResObject::Kind &kind, Candidates &candidates )
     if (!candidate.resolvable())
       continue;
 
-    cerr_vv << "item " << *it << endl;
-    cerr_vv << "cand " << candidate << endl;
+    DBG << "item " << *it << endl;
+    DBG << "cand " << candidate << endl;
     candidates.insert (candidate);
   }
 }
 
 // ----------------------------------------------------------------------------
 
-void list_updates(const Zypper & zypper, const ResObject::Kind &kind, bool best_effort )
+void list_updates(Zypper & zypper, const ResObject::Kind &kind, bool best_effort )
 {
   bool k_is_patch = kind == ResTraits<Patch>::kind;
   if (k_is_patch)
@@ -1292,7 +1307,7 @@ void list_updates(const Zypper & zypper, const ResObject::Kind &kind, bool best_
     tbl.sort( name_col );
 
     if (tbl.empty())
-      cout_n << _("No updates found.") << endl;
+      zypper.out().info(_("No updates found."));
     else
       cout << tbl;
   }
@@ -1302,7 +1317,7 @@ void list_updates(const Zypper & zypper, const ResObject::Kind &kind, bool best_
 bool mark_item_install (const PoolItem& pi) {
   bool result = pi.status().setToBeInstalled( zypp::ResStatus::USER );
   if (!result) {
-    cerr_vv << "Marking " << pi << "for installation failed" << endl;
+    DBG << "Marking " << pi << "for installation failed" << endl;
   }
   return result;
 }
@@ -1350,7 +1365,8 @@ bool require_item_update (const PoolItem& pi) {
   }
   catch (const Exception& e) {
     ZYPP_CAUGHT(e);
-    cerr << "Cannot parse '" << installed->name() << " < " << installed->edition() << "'" << endl;
+    Zypper::instance()->out().error(boost::str(format(
+      _("Cannot parse '%s < %s'")) % installed->name() % installed->edition()));
   }
 
   return true;
@@ -1412,8 +1428,9 @@ void mark_patch_updates( bool skip_interactive )
              // Skipping a patch because it is marked as interactive or has
              // license to confirm and --skip-interactive is requested.
              // TranslatorExplanation %s is the name of a patch
-             cerr << format (_("WARNING: %s is interactive, skipped."))
-               % res << endl;
+             Zypper::instance()->out().warning(boost::str(format(
+                 _("WARNING: %s is interactive, skipped."))
+                 % res));
            }
            else {
              nothing_found = false;
@@ -1483,33 +1500,37 @@ void solve_and_commit (Zypper & zypper)
         //! \todo fix the media reporting correctly
         gData.show_media_progress_hack = true;
 
-        cerr_v << _("committing"); MIL << "committing...";
+        ostringstream s;
+        s << _("committing"); MIL << "committing...";
 
         ZYppCommitResult result;
         if (copts.count("dry-run"))
         {
-          cerr_v << " " << _("(dry run)") << endl; MIL << "(dry run)";
+          s << " " << _("(dry run)") << endl; MIL << "(dry run)";
+          zypper.out().info(s.str(), Out::HIGH);
 
           result = God->commit(ZYppCommitPolicy().dryRun(true));
         }
         else
         {
-          cerr_v << endl; // endl after 'committing'
+          zypper.out().info(s.str(), Out::HIGH);
 
           result = God->commit(
             ZYppCommitPolicy().syncPoolAfterCommit(zypper.runningShell()));
 
           was_installed = true;
         }
+        
 
         MIL << endl << "DONE" << endl;
 
         gData.show_media_progress_hack = false;
-
+        
         if (!result._errors.empty())
           retv = ZYPPER_EXIT_ERR_ZYPP;
 
-        cerr_v << result << std::endl;
+        s.clear(); s << result;
+        zypper.out().info(s.str(), Out::HIGH);
       }
       catch ( const media::MediaException & e ) {
         ZYPP_CAUGHT(e);
@@ -1552,21 +1573,15 @@ void solve_and_commit (Zypper & zypper)
   else if (was_installed)
   {
     if (retv == ZYPPER_EXIT_INF_REBOOT_NEEDED)
-    {
-      if (zypper.globalOpts().machine_readable)
-        cout << "<message type=\"warning\">" << _("One of installed patches requires reboot of"
-            " your machine. Please do it as soon as possible.") << "</message>" << endl;
-      else
-        cout << _("WARNING: One of installed patches requires a reboot of"
-            " your machine. Please do it as soon as possible.") << endl;
-    }
+      zypper.out().warning(
+        _("One of installed patches requires reboot of"
+          " your machine. Please do it as soon as possible."));
     else if (retv == ZYPPER_EXIT_INF_RESTART_NEEDED)
-    {
-      if (!zypper.globalOpts().machine_readable)
-        cout << _("WARNING: One of installed patches affects the package"
-            " manager itself, thus it requires its restart before executing"
-            " any further operations.") << endl;
-    }
+      zypper.out().warning(
+        _("One of installed patches affects the package"
+          " manager itself, thus it requires its restart before executing"
+          " any further operations."),
+        Out::NORMAL, Out::TYPE_NORMAL);
   }
 
   if (zypper.exitCode() == ZYPPER_EXIT_OK) // don't overwrite previously set exit code
@@ -1589,12 +1604,11 @@ bool confirm_licenses(Zypper & zypper)
     {
       if (zypper.cmdOpts().license_auto_agree)
       {
-        // TranslatorExplanation The first %s is name of the resolvable, the second is its kind (e.g. 'zypper package')
-                         if (!zypper.globalOpts().machine_readable)
-               cout << format(_("Automatically agreeing with %s %s license."))
-                   % it->resolvable()->name()
-                   % kind_to_string_localized(it->resolvable()->kind(),1)
-                   << endl;
+       zypper.out().info(boost::str(
+            // TranslatorExplanation The first %s is name of the resolvable, the second is its kind (e.g. 'zypper package')
+           format(_("Automatically agreeing with %s %s license."))
+            % it->resolvable()->name()
+            % kind_to_string_localized(it->resolvable()->kind(),1)));
 
         MIL << format("Automatically agreeing with %s %s license.")
             % it->resolvable()->name() % it->resolvable()->kind().asString()
@@ -1603,40 +1617,43 @@ bool confirm_licenses(Zypper & zypper)
         continue;
       }
 
-      cout << format(_("%s %s license:")) % it->resolvable()->name()
-                % kind_to_string_localized(it->resolvable()->kind(), 1)
-        << it->resolvable()->licenseToConfirm() << endl;
+      // license text
+      ostringstream s;
+      s << format(_("%s %s license:")) % it->resolvable()->name()
+          % kind_to_string_localized(it->resolvable()->kind(), 1)
+        << it->resolvable()->licenseToConfirm();
+      zypper.out().info(s.str(), Out::QUIET);
 
+      // lincense prompt
       string question = _("In order to install this package, you must agree"
         " to terms of the above license. Continue?");
-
       if (!read_bool_answer(PROMPT_YN_LICENSE_AGREE, question, zypper.cmdOpts().license_auto_agree))
       {
         confirmed = false;
 
         if (zypper.globalOpts().non_interactive)
         {
-          //! \todo do this with _PL()
-          cout << endl <<
-             _("Aborting installation due to the need for"
-              " license(s) confirmation.") << " ";
-          // TranslatorExplanation Don't translate the '--auto-agree-with-licenses',
-          // it is a command line option
-          cout << _("Please restart the operation in interactive"
-              " mode and confirm your agreement with required license(s),"
-              " or use the --auto-agree-with-licenses option.")
-            << endl;
+          zypper.out().info(
+            _("Aborting installation due to the need for license confirmation."),
+            Out::QUIET);
+          zypper.out().info(boost::str(format(
+            // translators: %sanslate the '--auto-agree-with-licenses',
+            // it is a command line option
+            _("Please restart the operation in interactive"
+              " mode and confirm your agreement with required licenses,"
+              " or use the %s option.")) % "--auto-agree-with-licenses"),
+            Out::QUIET);
+
           MIL << "License(s) NOT confirmed (non-interactive without auto confirmation)" << endl;
         }
         else
         {
-          cout << endl;
-            // TranslatorExplanation e.g. "... with flash package license."
-          cout << format(
+          zypper.out().info(boost::str(format(
+              // translators: e.g. "... with flash package license."
               _("Aborting installation due to user disagreement with %s %s license."))
                 % it->resolvable()->name()
-                % kind_to_string_localized(it->resolvable()->kind(), 1)
-              << endl;
+                % kind_to_string_localized(it->resolvable()->kind(), 1)),
+              Out::QUIET);
             MIL << "License(s) NOT confirmed (interactive)" << endl;
         }
 
@@ -1659,26 +1676,26 @@ SrcPackage::constPtr source_find( const string & arg )
     SrcPackage::constPtr srcpkg;
 
     ResPool pool(God->pool());
-    cout_vv << "looking source for : " << arg << endl;
+    DBG << "looking source for : " << arg << endl;
     for_( srcit, pool.byIdentBegin<SrcPackage>(arg), 
               pool.byIdentEnd<SrcPackage>(arg) )
     {
-      cout_vv << *srcit << endl;
+      DBG << *srcit << endl;
       if ( ! srcit->status().isInstalled() )
       {
         SrcPackage::constPtr _srcpkg = asKind<SrcPackage>(srcit->resolvable());
-        cout_vv << "Considering srcpakcage " << srcpkg->name() << "-" << srcpkg->edition() << ": ";
+        DBG << "Considering srcpakcage " << srcpkg->name() << "-" << srcpkg->edition() << ": ";
         if (_srcpkg)
         {
           if (_srcpkg->edition() < srcpkg->edition())
-            cout_vv << "newer edition (" << srcpkg->edition() << " > " << _srcpkg->edition() << ")" << endl;
+            DBG << "newer edition (" << srcpkg->edition() << " > " << _srcpkg->edition() << ")" << endl;
           else
-            cout_vv << "is older than the current candidate";
+            DBG << "is older than the current candidate";
         }
         else
-          cout_vv << "first candindate";
+          DBG << "first candindate";
   
-        cout_vv << endl;
+        DBG << endl;
   
         _srcpkg.swap(srcpkg);
       }
@@ -1704,21 +1721,21 @@ int build_deps_install(std::vector<std::string> & arguments)
 
     if (srcpkg)
     {
-      cout << format(_("Installing source package %s-%s dependencies"))
-          % srcpkg->name() % srcpkg->edition() << endl;
-      
+      Zypper::instance()->out().info(boost::str(format(
+          _("Installing source package %s-%s dependencies"))
+          % srcpkg->name() % srcpkg->edition()));
+
       // add all src requires to pool
       for_( itc, srcpkg->dep(Dep::REQUIRES).begin(), srcpkg->dep(Dep::REQUIRES).end() )
       {
         God->resolver()->addRequire(*itc);
       }
-
-      ret = ZYPPER_EXIT_ERR_ZYPP;
-
     }
     else
     {
-      cerr << format(_("Source package '%s' not found.")) % (*it) << endl;
+      Zypper::instance()->out().error(boost::str(format(
+          _("Source package '%s' not found.")) % (*it)));
+      ret = ZYPPER_EXIT_INF_CAP_NOT_FOUND;
     }
   }
 
@@ -1744,29 +1761,32 @@ int source_install(std::vector<std::string> & arguments)
 
     if (srcpkg)
     {
-      cout << format(_("Installing source package %s-%s"))
-          % srcpkg->name() % srcpkg->edition() << endl;
+      Zypper::instance()->out().info(boost::str(format(
+          _("Installing source package %s-%s"))
+          % srcpkg->name() % srcpkg->edition()));
       MIL << "Going to install srcpackage: " << srcpkg << endl;
 
       try
       {
         God->installSrcPackage(srcpkg);
 
-        cout << format(_("Source package %s-%s successfully installed."))
-            % srcpkg->name() % srcpkg->edition() << endl;
+        Zypper::instance()->out().info(boost::str(format(
+            _("Source package %s-%s successfully installed."))
+            % srcpkg->name() % srcpkg->edition()));
       }
       catch (const Exception & ex)
       {
         ZYPP_CAUGHT(ex);
-        cerr << format(_("Problem installing source package %s-%s:"))
-            % srcpkg->name() % srcpkg->edition() << endl;
-        cerr << ex.asUserString() << endl;
+        Zypper::instance()->out().error(ex,
+          boost::str(format(_("Problem installing source package %s-%s:"))
+            % srcpkg->name() % srcpkg->edition()));
 
         ret = ZYPPER_EXIT_ERR_ZYPP;
       }
     }
     else
-      cerr << format(_("Source package '%s' not found.")) % (*it) << endl;
+      Zypper::instance()->out().error(boost::str(format(
+          _("Source package '%s' not found.")) % (*it)));
   }
 
   return ret;
index d77ac9b..ed1492f 100644 (file)
@@ -17,7 +17,7 @@
 #include "zypper-tabulator.h"
 
 /// Parse a capability string. On error print a message and return noCap
-zypp::Capability safe_parse_cap (const Zypper & zypper,
+zypp::Capability safe_parse_cap (Zypper & zypper,
                                  const zypp::ResObject::Kind &kind,
                                 const std::string &capstr);
 
@@ -35,7 +35,7 @@ void mark_by_name (Zypper & zypper,
                   const zypp::ResObject::Kind &kind,
                   const std::string &name);
 
-void mark_by_capability (const Zypper & zypper,
+void mark_by_capability (Zypper & zypper,
                          bool install_not_remove,
                         const zypp::ResObject::Kind &kind,
                         const std::string &capstr);
@@ -71,7 +71,7 @@ void patch_check();
  * \param kind  resolvable type
  * \param best_effort
  */
-void list_updates(const Zypper & zypper,
+void list_updates(Zypper & zypper,
                   const zypp::ResObject::Kind &kind,
                   bool best_effort);
 
index 09b952a..0178c68 100644 (file)
@@ -380,9 +380,10 @@ static void do_init_repos(Zypper & zypper)
         if (refresh_raw_metadata(zypper, repo, false)
             || build_cache(zypper, repo, false))
         {
-          cerr << format(_("Disabling repository '%s' because of the above error."))
-              % repo.name() << endl;
-          ERR << format("Disabling repository '%s' because of the above error.")
+          zypper.out().warning(boost::str(format(
+              _("Disabling repository '%s' because of the above error."))
+              % repo.name()), Out::QUIET);
+          WAR << format("Disabling repository '%s' because of the above error.")
               % repo.name() << endl;
 
           it->setEnabled(false);
@@ -397,15 +398,12 @@ static void do_init_repos(Zypper & zypper)
         // user
         catch (const Exception & ex)
         {
-          cout << format(_(
+          zypper.out().info(boost::str(format(_(
               "Repository '%s' is out-of-date. You can run 'zypper refresh'"
-              " as root to update it.")) % repo.name()
-            << endl;
+              " as root to update it.")) % repo.name()));
 
-          string nonroot =
-            "We're running as non-root, skipping refresh of " + repo.name();
-          MIL << nonroot << endl;
-          cout_vv << nonroot << endl;
+          MIL << "We're running as non-root, skipping refresh of " << repo.name()
+              << endl;
         }
       }
     }
@@ -418,9 +416,10 @@ static void do_init_repos(Zypper & zypper)
       {
         if (build_cache(zypper, repo, false))
         {
-          cerr << format(_("Disabling repository '%s' because of the above error."))
-              % repo.name() << endl;
-          ERR << format("Disabling repository '%s' because of the above error.")
+          zypper.out().warning(boost::str(format(
+              _("Disabling repository '%s' because of the above error."))
+              % repo.name()), Out::QUIET);
+          WAR << format("Disabling repository '%s' because of the above error.")
               % repo.name() << endl;
 
           it->setEnabled(false);
@@ -429,24 +428,22 @@ static void do_init_repos(Zypper & zypper)
       // non-root user
       else
       {
-        // if error is returned, it means zypp attempted to build the sqlite
+        // if error is returned, it means zypp attempted to build the meta-data
         // cache for the repo and failed because writing is not allowed for
-        // non-root Thus, just display refresh hint for non-root user.
+        // non-root. Thus, just display refresh hint for non-root user.
         if (build_cache(zypper, repo, false))
         {
-          cout << format(_(
-              "The cache database needs to be built for the '%s' repository."
-              " You can run 'zypper refresh' as root to do this.")) % repo.name()
-            << endl;
+          zypper.out().warning(boost::str(format(_(
+              "The meta-data cache needs to be built for the '%s' repository."
+              " You can run 'zypper refresh' as root to do this."))
+              % repo.name()), Out::QUIET);
 
-          string nonroot =
-            "We're running as non-root, skipping building of " + repo.name() + "cache";
-          MIL << nonroot << endl;
-          cout_vv << nonroot << endl;
+          MIL <<  "We're running as non-root, skipping building of "
+            << repo.name() + "cache" << endl;
 
-          cerr << format(_("Disabling repository '%s'."))
-              % repo.name() << endl << endl;
-          ERR << "Disabling repository '" << repo.name() << "'" << endl;
+          zypper.out().info(boost::str(format(_("Disabling repository '%s'."))
+              % repo.name()));
+          WAR << "Disabling repository '" << repo.name() << "'" << endl;
           it->setEnabled(false);
         }
       }
@@ -471,11 +468,12 @@ void init_repos(Zypper & zypper)
 
 // ----------------------------------------------------------------------------
 
-void init_target (Zypper & zypper) {
+void init_target (Zypper & zypper)
+{
   static bool done = false;
-  //! \todo do this so that it works in zypper shell
-  if (!done) {
-    cout_v << _("Initializing Target") << endl;
+  if (!done)
+  {
+    zypper.out().info(_("Initializing Target"), Out::HIGH);
 
     try
     {
@@ -541,7 +539,7 @@ static void print_rug_sources_list(const std::list<zypp::RepoInfo> &repos)
 
 // ----------------------------------------------------------------------------
 
-static void print_repo_list(const Zypper & zypper,
+static void print_repo_list(Zypper & zypper,
                             const std::list<zypp::RepoInfo> &repos )
 {
   Table tbl;
@@ -549,7 +547,7 @@ static void print_repo_list(const Zypper & zypper,
   // header
   TableHeader th;
   th << "#" << _("Enabled") << _("Refresh") << _("Type") << _("Alias") << _("Name");
-  if (zypper.globalOpts().verbosity > VERBOSITY_NORMAL)
+  if (zypper.out().verbosity() > Out::NORMAL)
     th << "URI";
   tbl << th;
 
@@ -559,7 +557,7 @@ static void print_repo_list(const Zypper & zypper,
        it !=  repos.end(); ++it)
   {
     RepoInfo repo = *it;
-    TableRow tr (zypper.globalOpts().verbosity > VERBOSITY_NORMAL ? 6 : 7);
+    TableRow tr (zypper.out().verbosity() > Out::NORMAL ? 6 : 7);
 
     // number
     tr << str::numstring (i);
@@ -574,7 +572,7 @@ static void print_repo_list(const Zypper & zypper,
     // name
     tr << repo.name();
     // url
-    if (zypper.globalOpts().verbosity > VERBOSITY_NORMAL)
+    if (zypper.out().verbosity() > Out::NORMAL)
       tr << (*repo.baseUrlsBegin()).asString(); //! \todo properly handle multiple baseurls
 
     tbl << tr;
@@ -582,9 +580,8 @@ static void print_repo_list(const Zypper & zypper,
   }
 
   if (tbl.empty())
-    cout_n << _("No repositories defined."
-        " Use the 'zypper addrepo' command to add one or more repositories.")
-         << endl;
+    zypper.out().info(_("No repositories defined."
+        " Use the 'zypper addrepo' command to add one or more repositories."));
   else
     cout << tbl;
 }
@@ -615,8 +612,7 @@ void list_repos(Zypper & zypper)
   catch ( const Exception &e )
   {
     ZYPP_CAUGHT(e);
-    cerr << _("Error reading repositories:") << endl
-         << e.asUserString() << endl;
+    zypper.out().error(e, _("Error reading repositories:"));
     exit(ZYPPER_EXIT_ERR_ZYPP);
   }
 
@@ -643,17 +639,19 @@ void list_repos(Zypper & zypper)
       std::ofstream stream(file.c_str());
       if (!stream)
       {
-        cerr << format(_("Can't open %s for writing. Maybe you don't have write permissions?"))
-            % file.asString() << endl;
+        zypper.out().error(boost::str(format(
+            _("Can't open %s for writing."))
+            % file.asString()),
+          _("Maybe you do not have write permissions?"));
         exit(ZYPPER_EXIT_ERR_INVALID_ARGS);
       }
       else
       {
         print_repos_to(repos, stream);
-        cout << format(
+        zypper.out().info(boost::str(format(
             _("Repositories have been successfully exported to %s."))
-            % (file.absolute() ? file.asString() : file.asString().substr(2))
-          << endl;
+            % (file.absolute() ? file.asString() : file.asString().substr(2))),
+          Out::QUIET);
       }
     }
   }
@@ -860,11 +858,12 @@ void clean_repos(Zypper & zypper)
     get_repos(zypper, tmp1->second.begin(), tmp1->second.end(), specified, not_found);
   report_unknown_repos(zypper.out(), not_found);
 
-  cout_v << _("Specified repositories: ");
+  ostringstream s;
+  s << _("Specified repositories: ");
   for (list<RepoInfo>::const_iterator it = specified.begin();
       it != specified.end(); ++it)
-    cout_v << it->alias() << " ";
-  cout_v << endl;
+    s << it->alias() << " ";
+  zypper.out().info(s.str(), Out::HIGH);
 
   // should we clean packages or metadata ?
   bool clean_metadata = (copts.find("metadata") != copts.end());
@@ -876,8 +875,8 @@ void clean_repos(Zypper & zypper)
     clean_packages = true;
   }
   
-  cout_vv << "Metadata will be cleaned: " << clean_metadata << endl;
-  cout_vv << "Packages will be cleaned: " << clean_packages << endl;
+  DBG << "Metadata will be cleaned: " << clean_metadata << endl;
+  DBG << "Packages will be cleaned: " << clean_packages << endl;
 
   unsigned error_count = 0;
   unsigned enabled_repo_count = repos.size();
@@ -913,12 +912,17 @@ void clean_repos(Zypper & zypper)
       try {
         if( clean_metadata )
        {
-           cout_v << "Cleaning metadata for '" << repo.alias () << "'" << endl;
+           zypper.out().info(boost::str(format(
+               _("Cleaning metadata for '%s'.")) % repo.alias ()),
+             Out::HIGH);
            manager.cleanMetadata(repo);
        }
         if( clean_packages )
        {
-           cout_v << "Cleaning packages for '" << repo.alias () << "'" << endl;
+          zypper.out().info(boost::str(format(
+              // translators: meaning the cached rpm files
+              _("Cleaning packages for '%s'.")) % repo.alias ()),
+            Out::HIGH);
            manager.cleanPackages(repo);
        }
       } catch(...) {
@@ -927,9 +931,10 @@ void clean_repos(Zypper & zypper)
 
       if (error)
       {
-        cerr << format(_("Skipping repository '%s' because of the above error."))
-            % repo.name() << endl;
-        ERR << format("Skipping repository '%s' because of the above error.")
+        zypper.out().error(boost::str(format(
+            _("Cannot clean repository '%s' because of an error."))
+            % repo.name()));
+        ERR << format("Cannot clean repository '%s' because of an error.")
             % repo.name() << endl;
         error_count++;
       }
@@ -940,20 +945,21 @@ void clean_repos(Zypper & zypper)
 
   if (error_count == enabled_repo_count)
   {
-    cerr << _("Could not clean the repositories because of errors.") << endl;
+    zypper.out().error(_("Could not clean the repositories because of errors."));
     zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
     return;
   }
   else if (error_count)
   {
-    cerr << _("Some of the repositories have not been cleaned up because of an error.") << endl;
+    zypper.out().error(
+      _("Some of the repositories have not been cleaned up because of an error."));
     zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
     return;
   }
   else if (!specified.empty())
-    cout << _("Specified repositories have been cleaned up.") << endl;
+    zypper.out().info(_("Specified repositories have been cleaned up."));
   else
-    cout << _("All repositories have been cleaned up.") << endl;
+    zypper.out().info(_("All repositories have been cleaned up."));
 }
 
 // ----------------------------------------------------------------------------
@@ -991,7 +997,9 @@ void add_repo(Zypper & zypper, RepoInfo & repo)
   }
   if (is_cd)
   {
-    cout_v << _("This is a changeable read-only media (CD/DVD), disabling autorefresh.") << endl;
+    zypper.out().info(
+      _("This is a changeable read-only media (CD/DVD), disabling autorefresh."),
+      Out::QUIET);
     repo.setAutorefresh(false);
   }
 
@@ -1010,8 +1018,9 @@ void add_repo(Zypper & zypper, RepoInfo & repo)
   catch (const RepoAlreadyExistsException & e)
   {
     ZYPP_CAUGHT(e);
-    cerr << format(_("Repository named '%s' already exists. Please use another alias."))
-        % repo.alias() << endl;
+    zypper.out().error(boost::str(format(
+        _("Repository named '%s' already exists. Please use another alias."))
+        % repo.alias()));
     ERR << "Repository named '" << repo.alias() << "' already exists." << endl;
     zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
     return;
@@ -1019,12 +1028,17 @@ void add_repo(Zypper & zypper, RepoInfo & repo)
   catch (const RepoUnknownTypeException & e)
   {
     ZYPP_CAUGHT(e);
-    cerr << _("Can't find a valid repository at given location:") << endl;
-    cerr << _("Could not determine the type of the repository."
+
+    ostringstream s;
+    s << _("Could not determine the type of the repository."
         " Please check if the defined URLs (see below) point to a valid repository:");
     for(RepoInfo::urls_const_iterator uit = repo.baseUrlsBegin();
         uit != repo.baseUrlsEnd(); ++uit)
-      cerr << (*uit) << endl;
+      s << (*uit) << endl;
+
+    zypper.out().error(e,
+      _("Can't find a valid repository at given location:"), s.str());
+
     zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
     return;
   }
@@ -1046,42 +1060,44 @@ void add_repo(Zypper & zypper, RepoInfo & repo)
     return;
   }
 
-  cout << format(_("Repository '%s' successfully added")) % repo.name();
-  cout_n << ":";
-  cout << endl;
+  ostringstream s;
+  s << format(_("Repository '%s' successfully added")) % repo.name();
 
   if (zypper.globalOpts().is_rug_compatible)
   {
-    cout_n << ( repo.enabled() ? "[x]" : "[ ]" );
-    cout_n << ( repo.autorefresh() ? "* " : "  " );
-    cout_n << repo.name() << " (" << *repo.baseUrlsBegin() << ")" << endl;
+    s << ( repo.enabled() ? "[x]" : "[ ]" );
+    s << ( repo.autorefresh() ? "* " : "  " );
+    s << repo.name() << " (" << *repo.baseUrlsBegin() << ")" << endl;
   }
   else
   {
     // TranslatorExplanation used as e.g. "Enabled: Yes"
-    cout_n << _("Enabled") << ": " << (repo.enabled() ? _("Yes") : _("No")) << endl;
+    s << _("Enabled") << ": " << (repo.enabled() ? _("Yes") : _("No")) << endl;
     // TranslatorExplanation used as e.g. "Autorefresh: Yes"
-    cout_n << _("Autorefresh") << ": " << (repo.autorefresh() ? _("Yes") : _("No")) << endl;
+    s << _("Autorefresh") << ": " << (repo.autorefresh() ? _("Yes") : _("No")) << endl;
 
-    cout_n << "URL:";
+    s << "URL:";
     for (RepoInfo::urls_const_iterator uit = repo.baseUrlsBegin();
         uit != repo.baseUrlsEnd(); uit++)
-      cout_n << " " << *uit;
-    cout_n << endl;
+      s << " " << *uit;
+    s << endl;
   }
+  zypper.out().info(s.str());
 
   MIL << "Repository successfully added: " << repo << endl;
 
   if(is_cd)
   {
-    cout_n << format(_("Reading data from '%s' media")) % repo.name() << endl;
+    zypper.out().info(boost::str(
+      format(_("Reading data from '%s' media")) % repo.name()));
     bool error = refresh_raw_metadata(zypper, repo, false);
     if (!error)
       error = build_cache(zypper, repo, false);
     if (error)
     {
-      cerr << format(_("Problem reading data from '%s' media")) % repo.name() << endl;
-      cerr << _("Please check if your installation media is valid and readable.") << endl;
+      zypper.out().error(boost::str(
+        format(_("Problem reading data from '%s' media")) % repo.name()),
+        _("Please check if your installation media is valid and readable."));
       zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
       return;
     }
@@ -1172,13 +1188,15 @@ void add_repo_from_file( Zypper & zypper,
 
     if(repo.alias().empty())
     {
-      cerr << _("A repository with no alias defined found in the file, skipping.") << endl;
+      zypper.out().warning(
+        _("Repository with no alias defined found in the file, skipping."));
       continue;
     }
 
     if(repo.baseUrlsEmpty())
     {
-      cerr << format(_("Repository '%s' has no URL defined, skipping.")) % repo.name() << endl;
+      zypper.out().warning(boost::str(format(
+        _("Repository '%s' has no URL defined, skipping.")) % repo.name()));
       continue;
     }
 
@@ -1212,7 +1230,8 @@ bool remove_repo(Zypper & zypper, const RepoInfo & repoinfo)
   try
   {
     manager.removeRepository(repoinfo);
-    cout << format(_("Repository '%s' has been removed.")) % repoinfo.name() << endl;
+    zypper.out().info(boost::str(
+      format(_("Repository '%s' has been removed.")) % repoinfo.name()));
     MIL << format("Repository '%s' has been removed.") % repoinfo.name() << endl;
   }
   catch (const repo::RepoNotFoundException & ex)
@@ -1268,25 +1287,27 @@ void rename_repo(Zypper & zypper,
     repo.setAlias(newalias);
     manager.modifyRepository(alias, repo);
 
-    cout << format(_("Repository '%s' renamed to '%s'")) % alias % repo.alias() << endl;
+    zypper.out().info(boost::str(format(
+      _("Repository '%s' renamed to '%s'.")) % alias % repo.alias()));
     MIL << format("Repository '%s' renamed to '%s'") % alias % repo.alias() << endl;
   }
   catch (const RepoNotFoundException & ex)
   {
-    cerr << format(_("Repository '%s' not found.")) % alias << endl;
+    zypper.out().error(boost::str(format(
+      _("Repository '%s' not found.")) % alias));
     ERR << "Repo " << alias << " not found" << endl;
   }
   catch (const RepoAlreadyExistsException & ex)
   {
-    cerr << format(_(
-        "Repository named '%s' already exists. Please use another alias."))
-      % newalias << endl;
+    zypper.out().error(boost::str(format(
+       _("Repository named '%s' already exists. Please use another alias."))
+      % newalias));
   }
   catch (const Exception & ex)
   {
-    cerr << _("Error while modifying the repository:") << endl;
-    cerr << ex.asUserString() << endl;
-    cerr << format(_("Leaving repository '%s' unchanged.")) % alias << endl;
+    zypper.out().error(ex,
+      _("Error while modifying the repository:"),
+      boost::str(format(_("Leaving repository '%s' unchanged.")) % alias));
 
     ERR << "Error while modifying the repository:" << ex.asUserString() << endl;
   }
@@ -1298,8 +1319,8 @@ void modify_repo(Zypper & zypper, const string & alias)
 {
   // tell whether currenlty processed options are contradicting each other
   // bool contradiction = false;
-  // TranslatorExplanation speaking of two mutually contradicting command line options
   string msg_contradition =
+    // translators: speaking of two mutually contradicting command line options
     _("%s used together with %s, which contradict each other."
       " This property will be left unchanged.");
 
@@ -1311,7 +1332,8 @@ void modify_repo(Zypper & zypper, const string & alias)
   {
     if (enable)
     {
-      cerr << format(msg_contradition) % "--enable" % "--disable" << endl;
+      zypper.out().warning(boost::str(format(msg_contradition)
+          % "--enable" % "--disable"), Out::QUIET);
 
       enable = indeterminate;
     }
@@ -1328,8 +1350,8 @@ void modify_repo(Zypper & zypper, const string & alias)
   {
     if (autoref)
     {
-      cerr << format(msg_contradition)
-        % "--refresh" % "--no-refresh" << endl;
+      zypper.out().warning(boost::str(format(msg_contradition)
+          % "--refresh" % "--no-refresh"));
 
       autoref = indeterminate;
     }
@@ -1351,19 +1373,21 @@ void modify_repo(Zypper & zypper, const string & alias)
 
     manager.modifyRepository(alias, repo);
 
-    cout << format(_("Repository %s has been sucessfully modified.")) % alias << endl;
+    zypper.out().info(boost::str(format(
+      _("Repository %s has been sucessfully modified.")) % alias));
     MIL << format("Repository %s modified:") % alias << repo << endl;
   }
   catch (const RepoNotFoundException & ex)
   {
-    cerr << format(_("Repository %s not found.")) % alias << endl;
+    zypper.out().error(
+      boost::str(format(_("Repository %s not found.")) % alias));
     ERR << "Repo " << alias << " not found" << endl;
   }
   catch (const Exception & ex)
   {
-    cerr << _("Error while modifying the repository:") << endl;
-    cerr << ex.asUserString();
-    cerr << format(_("Leaving repository %s unchanged.")) % alias << endl;
+    zypper.out().error(ex,
+      _("Error while modifying the repository:"),
+      boost::str(format(_("Leaving repository %s unchanged.")) % alias));
 
     ERR << "Error while modifying the repository:" << ex.asUserString() << endl;
   }
@@ -1410,28 +1434,29 @@ void load_repo_resolvables(Zypper & zypper)
       // if there is no metadata locally
       if ( manager.metadataStatus(repo).empty() )
       {
-        cout_v << format(_("Retrieving repository '%s' data..."))
-                         % repo.name() << endl;
+        zypper.out().info(boost::str(
+          format(_("Retrieving repository '%s' data...")) % repo.name()));
         error = refresh_raw_metadata(zypper, repo, false);
       }
 
       if (!error && !manager.isCached(repo))
       {
-        cout_v << format(_("Repository '%s' not cached. Caching..."))
-                         % repo.name() << endl;
+        zypper.out().info(boost::str(
+          format(_("Repository '%s' not cached. Caching...")) % repo.name()));
         error = build_cache(zypper, repo, false);
       }
 
       if (error)
       {
-        cerr << format(_("Problem loading data from '%s'")) % repo.name() << endl;
-        cerr << format(_("Resolvables from '%s' not loaded because of error."))
-            % repo.name() << endl;
+        ostringstream s;
+        s << format(_("Problem loading data from '%s'")) % repo.name() << endl;
+        s << format(_("Resolvables from '%s' not loaded because of error."))
+            % repo.name();
+        zypper.out().error(s.str());
         continue;
       }
 
       manager.loadFromCache(repo);
-      //cout_v << " " << format(_("(%d resolvables found)")) % store.size() << endl;
     }
     catch (const Exception & e)
     {
@@ -1439,8 +1464,8 @@ void load_repo_resolvables(Zypper & zypper)
       zypper.out().error(e,
           boost::str(format(_("Problem loading data from '%s'")) % repo.name()),
           _("Try 'zypper refresh', or even remove /var/cache/zypp/zypp.db before doing so."));
-      cerr << format(_("Resolvables from '%s' not loaded because of error."))
-                      % repo.name() << endl;
+      zypper.out().info(boost::str(format(
+        _("Resolvables from '%s' not loaded because of error.")) % repo.name()));
     }
   }
 }
@@ -1453,18 +1478,6 @@ void load_target_resolvables(Zypper & zypper)
   MIL << "Going to read RPM database" << endl;
 
   God->target()->load();
-
-  if (!zypper.globalOpts().machine_readable)
-  {
-    //cout_v << "   " <<  format(_("(%s resolvables)")) % tgt_resolvables.size();
-    cout_n << endl;
-  }
-  //DBG << tgt_resolvables.size() << " resolvables read";
-
-  //if (to_pool)
-  //  God->addResolvables(tgt_resolvables, true /*installed*/);
-  //else
-  //  gData.target_resolvables = tgt_resolvables;
 }
 
 // ---------------------------------------------------------------------------
@@ -1544,9 +1557,9 @@ void warn_if_zmd()
 {
   if (system ("pgrep -lx zmd") == 0)
   { // list name, exact match
-    cout_n << _("ZENworks Management Daemon is running.\n"
+    Zypper::instance()->out().info(_("ZENworks Management Daemon is running.\n"
               "WARNING: this command will not synchronize changes.\n"
-              "Use rug or yast2 for that.\n");
+              "Use rug or yast2 for that."));
     USR << ("ZMD is running. Tell the user this will get"
         " ZMD and libzypp out of sync.") << endl;
   }
index 55b7fb7..7b3426b 100644 (file)
@@ -65,7 +65,6 @@ struct FillTable
 
   bool operator()(const zypp::ResObject::Ptr &item) const
   {
-    //std::cout << "result" << std::endl;
     TableRow row;
 
     // add other fields to the result table
index 6f2b8fb..8426739 100644 (file)
@@ -165,8 +165,10 @@ Url make_url (const string & url_s)
   }
   catch ( const Exception & excpt_r ) {
     ZYPP_CAUGHT( excpt_r );
-    cerr << _("Given URL is invalid") << ": " << urlstr
-         << " (" << excpt_r.asUserString() << ")" << endl;
+    ostringstream s;
+    s << _("Given URL is invalid") << ": " << urlstr
+      << " (" << excpt_r.asUserString() << ")";
+    Zypper::instance()->out().error(s.str());
   }
   return u;
 }
@@ -215,8 +217,9 @@ Pathname cache_rpm(const string & rpm_uri_str, const string & cache_dir)
 
     if (error)
     {
-      cerr << _("Problem copying the specified RPM file to the cache directory.")
-        << endl << _("Perhaps you are running out of disk space.") << endl; 
+      Zypper::instance()->out().error(
+        _("Problem copying the specified RPM file to the cache directory."),
+        _("Perhaps you are running out of disk space.")); 
       return Pathname();
     }
     return cachedrpmpath / localrpmpath.basename();