- gSettings global removed
authorJan Kupec <jkupec@suse.cz>
Mon, 26 Nov 2007 17:42:42 +0000 (17:42 +0000)
committerJan Kupec <jkupec@suse.cz>
Mon, 26 Nov 2007 17:42:42 +0000 (17:42 +0000)
16 files changed:
src/zypper-callbacks.cc
src/zypper-info.cc
src/zypper-info.h
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-repos.h
src/zypper-rpm-callbacks.h
src/zypper-search.cc
src/zypper-search.h
src/zypper.cc
src/zypper.h

index 99978fc..150fd16 100644 (file)
@@ -15,7 +15,7 @@ using namespace boost;
 void display_progress ( const std::string &id, ostream & out, const string& s, int percent) {
   static AliveCursor cursor;
 
-  if (gSettings.machine_readable)
+  if (Zypper::instance()->globalOpts().machine_readable)
   {
     cout << "<progress id=\"" << id << "\" type=\"percentage\" value=\"" << percent << "\" name=\"" << s << "\"/>" << endl;
     return;
@@ -36,7 +36,7 @@ void display_progress ( const std::string &id, ostream & out, const string& s, i
 void display_tick ( const std::string &id, ostream & out, const string& s) {
   static AliveCursor cursor;
 
-  if (gSettings.machine_readable)
+  if (Zypper::instance()->globalOpts().machine_readable)
   {
     cout << "<progress id=\"" << id << "\" type=\"tick\" value=\"" << -1 << "\" name=\"" << s << "\"/>" << endl;
     return;
@@ -52,7 +52,7 @@ void display_tick ( const std::string &id, ostream & out, const string& s) {
 void display_done ( const std::string &id, ostream & out, const string& s) {
   static AliveCursor cursor;
 
-  if (gSettings.machine_readable)
+  if (Zypper::instance()->globalOpts().machine_readable)
   {
     cout << "<progress id=\"" << id << "\" type=\"done\" name=\"" << s << "\"/>" << endl;
     return;
@@ -67,7 +67,7 @@ void display_done ( const std::string &id, ostream & out, const string& s) {
 
 void display_done (const std::string &id, ostream & out) {
 
-  if (gSettings.machine_readable)
+  if (Zypper::instance()->globalOpts().machine_readable)
   {
     display_done( id, cout, "");
     return;
@@ -91,7 +91,7 @@ int read_action_ari (int default_action) {
   }
 
   // non-interactive mode
-  if (gSettings.non_interactive) {
+  if (Zypper::instance()->globalOpts().non_interactive) {
       char c;
       switch (default_action) {
          case 0: c = 'a'; break;
@@ -128,15 +128,16 @@ int read_action_ari (int default_action) {
 
 bool read_bool_answer(const string & question, bool default_answer)
 {
-  if (!gSettings.machine_readable)
+  const GlobalOptions & gopts = Zypper::instance()->globalOpts();
+  if (!gopts.machine_readable)
     cout << CLEARLN << question
     << " [" << _("yes") << "/" << _("no") << "]: "
     << flush;
 
   // non-interactive mode: print the answer for convenience and return default
-  if (gSettings.non_interactive)
+  if (gopts.non_interactive)
   {
-    if (!gSettings.machine_readable)
+    if (!gopts.machine_readable)
       cout << (default_answer ? _("yes") : _("no")) << endl;
     MIL << "answer (default): " << (default_answer ? 'y' : 'n') << endl;
     return default_answer;
@@ -184,7 +185,7 @@ void report_zypp_exception(const zypp::Exception & e)
 {
   if (e.historySize())
   {
-    if (gSettings.verbosity > VERBOSITY_NORMAL)
+    if (Zypper::instance()->globalOpts().verbosity > VERBOSITY_NORMAL)
     {
       // print the whole history
       cerr << e.historyAsString();
index 5d60640..ef6c2e6 100644 (file)
@@ -18,22 +18,26 @@ using namespace zypp;
 using boost::format;
 
 extern ZYpp::Ptr God;
-extern GlobalOptions gSettings;
+
 
 /**
  * 
  */
-void printInfo(const ZypperCommand & command, const vector<string> & arguments) {
+void printInfo(const Zypper & zypper)
+{
   Resolvable::Kind kind;
-  if (command == ZypperCommand::INFO) kind =  ResTraits<Package>::kind;
-  else if (command == ZypperCommand::RUG_PATCH_INFO) kind = ResTraits<Patch>::kind;
+  if (zypper.command() == ZypperCommand::INFO)
+    kind =  ResTraits<Package>::kind;
+  else if (zypper.command() == ZypperCommand::RUG_PATCH_INFO)
+    kind = ResTraits<Patch>::kind;
 
   ResPool pool = God->pool();
 
   cout << endl;
 
-  for(vector<string>::const_iterator nameit = arguments.begin();
-      nameit != arguments.end(); ++nameit ) {
+  for(vector<string>::const_iterator nameit = zypper.arguments().begin();
+      nameit != zypper.arguments().end(); ++nameit )
+  {
 
     // find the resolvable among installed 
     PoolItem installed;
@@ -63,10 +67,10 @@ void printInfo(const ZypperCommand & command, const vector<string> & arguments)
 
       cout << endl << endl;
 
-      if (command == ZypperCommand::INFO)
-        printPkgInfo(installer.item,installed);
-      else if (command == ZypperCommand::RUG_PATCH_INFO)
-        printPatchInfo(installer.item,installed);
+      if (zypper.command() == ZypperCommand::INFO)
+        printPkgInfo(zypper, installer.item,installed);
+      else if (zypper.command() == ZypperCommand::RUG_PATCH_INFO)
+        printPatchInfo(zypper, installer.item,installed);
     }
   }
 }
@@ -91,9 +95,10 @@ Copy and modify /usr/share/vim/current/gvimrc to ~/.gvimrc if needed.
 </pre>
  *
  */
-void printPkgInfo(const PoolItem & pool_item, const PoolItem & ins_pool_item) {
-
-  cout << (gSettings.is_rug_compatible ? _("Catalog: ") : _("Repository: "))
+void printPkgInfo(const Zypper & zypper,
+                  const PoolItem & pool_item, const PoolItem & ins_pool_item)
+{
+  cout << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: "))
        << pool_item.resolvable()->repository().info().name() << endl;
   cout << _("Name: ") << pool_item.resolvable()->name() << endl;
   cout << _("Version: ") << pool_item.resolvable()->edition().asString() << endl;
@@ -141,7 +146,7 @@ atom: xv = 3.10a-1091.2
 </pre>
  * 
  */
-void printPatchInfo(const PoolItem & pool_item, const PoolItem & ins_pool_item) {
+void printPatchInfo(const Zypper & zypper, const PoolItem & pool_item, const PoolItem & ins_pool_item) {
   cout << _("Name: ") << pool_item.resolvable()->name() << endl;
   cout << _("Version: ") << pool_item.resolvable()->edition().asString() << endl;
   cout << _("Arch: ") << pool_item.resolvable()->arch().asString() << endl;
@@ -163,7 +168,7 @@ void printPatchInfo(const PoolItem & pool_item, const PoolItem & ins_pool_item)
   cout << _("Created On: ") << patch->timestamp().asString() << endl;
   cout << _("Reboot Required: ") << (patch->reboot_needed() ? _("Yes") : _("No")) << endl;
 
-  if (!gSettings.is_rug_compatible)
+  if (!zypper.globalOpts().is_rug_compatible)
     cout << _("Package Manager Restart Required") << ": ";
   else
     cout << _("Restart Required: ");
index 0a70223..7ae0b87 100644 (file)
@@ -1,14 +1,18 @@
 #ifndef ZYPPERINFO_H_
 #define ZYPPERINFO_H_
 
-#include <string>
-#include <vector>
-
 #include "zypp/PoolItem.h"
 
-#include "zypper-command.h"
+#include "zypper.h"
+
+void printInfo(const Zypper & zypper);
+
+void printPkgInfo(const Zypper & zypper,
+                  const zypp::PoolItem & pool_item,
+                  const zypp::PoolItem & ins_pool_item);
+
+void printPatchInfo(const Zypper & zypper,
+                    const zypp::PoolItem & pool_item,
+                    const zypp::PoolItem & ins_pool_item);
 
-void printInfo(const ZypperCommand & command, const std::vector<std::string> & arguments);
-void printPkgInfo(const zypp::PoolItem & pool_item,  const zypp::PoolItem & ins_pool_item);
-void printPatchInfo(const zypp::PoolItem & pool_item, const zypp::PoolItem & ins_pool_item);
 #endif /*ZYPPERINFO_H_*/
index 59c4547..d5275fe 100644 (file)
@@ -32,9 +32,11 @@ namespace zypp {
     ///////////////////////////////////////////////////////////////////
     struct KeyRingReceive : public zypp::callback::ReceiveReport<zypp::KeyRingReport>
     {
+      KeyRingReceive() : _gopts(Zypper::instance()->globalOpts()) {}
+
       virtual bool askUserToAcceptUnsignedFile( const std::string &file )
       {
-        if (gSettings.no_gpg_checks)
+        if (_gopts.no_gpg_checks)
         {
           MIL << "Accepting unsigned file (" << file << ")" << endl;
           cout_v << boost::format(_("Warning: Accepting an unsigned file %s.")) % file;
@@ -59,7 +61,7 @@ namespace zypp {
 
       virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id )
       {
-        if (gSettings.no_gpg_checks)
+        if (_gopts.no_gpg_checks)
         {
           MIL << "Accepting file signed with an unknown key (" << file << "," << id << ")" << endl;
           cout_n << boost::format(
@@ -79,7 +81,7 @@ namespace zypp {
        const std::string& keyid = key.id(), keyname = key.name(),
          fingerprint = key.fingerprint();
 
-        if (gSettings.no_gpg_checks)
+        if (_gopts.no_gpg_checks)
         {
           MIL << boost::format("Automatically trusting key id %s, %s, fingerprint %s")
               % keyid % keyname % fingerprint << endl;
@@ -100,7 +102,7 @@ namespace zypp {
        const std::string& keyid = key.id(), keyname = key.name(),
          fingerprint = key.fingerprint();
 
-        if (gSettings.no_gpg_checks)
+        if (_gopts.no_gpg_checks)
         {
           MIL << boost::format(
               "Ignoring failed signature verification for %s"
@@ -126,15 +128,20 @@ namespace zypp {
             % file % keyid % keyname % fingerprint);
         return read_bool_answer(question, false);
       }
+
+    private:
+      const GlobalOptions & _gopts;
     };
 
     struct DigestReceive : public zypp::callback::ReceiveReport<zypp::DigestReport>
     {
+      DigestReceive() : _gopts(Zypper::instance()->globalOpts()) {}
+
       virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
       {
        std::string question = boost::str(boost::format(
            _("No digest for file %s.")) % file) + " " + _("Continue?");
-        return read_bool_answer(question, gSettings.no_gpg_checks);
+        return read_bool_answer(question, _gopts.no_gpg_checks);
       }
 
       virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
@@ -142,12 +149,12 @@ namespace zypp {
         std::string question = boost::str(boost::format(
             _("Unknown digest %s for file %s.")) %name % file) + " " +
             _("Continue?");
-        return read_bool_answer(question, gSettings.no_gpg_checks);
+        return read_bool_answer(question, _gopts.no_gpg_checks);
       }
 
       virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
       {
-        if (gSettings.no_gpg_checks)
+        if (_gopts.no_gpg_checks)
         {
           WAR << boost::format(
               "Ignoring failed digest verification for %s (expected %s, found %s).")
@@ -163,6 +170,9 @@ namespace zypp {
            % file.basename() % requested % found) + " " + _("Continue?");
         return read_bool_answer(question, false);
       }
+
+    private:
+      const GlobalOptions & _gopts;
     };
 
     ///////////////////////////////////////////////////////////////////
index 6c6dab7..378d44b 100644 (file)
@@ -40,6 +40,5 @@ int main(int argc, char **argv)
     logfile = ZYPPER_LOG;
   zypp::base::LogControl::instance().logfile( logfile );
 
-  Zypper zypper;
-  return zypper.main(argc, argv);
+  return Zypper::instance()->main(argc, argv);
 }
index 4e329dd..b61f113 100644 (file)
@@ -31,7 +31,7 @@
  * \see Output Macros
  * \see GlobalOptions::verbosity
  */
-#define COND_STREAM(STREAM,LEVEL) ((gSettings.verbosity >= LEVEL) ? STREAM : no_stream)
+#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
index a2a5567..55c9558 100644 (file)
@@ -71,17 +71,20 @@ namespace ZmartRecipients
   // progress for downloading a file
   struct DownloadProgressReportReceiver : public zypp::callback::ReceiveReport<zypp::media::DownloadProgressReport>
   {
+    DownloadProgressReportReceiver() : _gopts(Zypper::instance()->globalOpts())
+    {}
+
     virtual void start( const zypp::Url & file, zypp::Pathname localfile )
     {
-      if (gSettings.verbosity < VERBOSITY_NORMAL)
+      if (_gopts.verbosity < VERBOSITY_NORMAL)
         return;
-      else if (gSettings.verbosity == VERBOSITY_MEDIUM || gData.show_media_progress_hack)
+      else if (_gopts.verbosity == VERBOSITY_MEDIUM || gData.show_media_progress_hack)
       {
         cout << CLEARLN << _("Downloading: ")
           << zypp::Pathname(file.getPathName()).basename()
           << std::endl;
       }
-      else if (gSettings.verbosity >= VERBOSITY_HIGH)
+      else if (_gopts.verbosity >= VERBOSITY_HIGH)
       {
         cout  << CLEARLN << _("Downloading: ") << file << std::endl;
       }
@@ -89,7 +92,7 @@ namespace ZmartRecipients
 
     virtual bool progress(int value, const zypp::Url & /*file*/)
     {
-      if (gSettings.verbosity < VERBOSITY_NORMAL)
+      if (_gopts.verbosity < VERBOSITY_NORMAL)
         return true;
       if (gData.show_media_progress_hack)
         display_progress ("download", cout, "Downloading", value);
@@ -101,7 +104,7 @@ namespace ZmartRecipients
     // not used anywhere in libzypp 3.20.0
     virtual DownloadProgressReport::Action problem( const zypp::Url & /*file*/, DownloadProgressReport::Error error, const std::string & description )
     {
-      if (gSettings.verbosity >= VERBOSITY_NORMAL)
+      if (_gopts.verbosity >= VERBOSITY_NORMAL)
       {
         if (gData.show_media_progress_hack)
           display_done ("download", cout_n);
@@ -115,7 +118,7 @@ namespace ZmartRecipients
     // used only to finish, errors will be reported in media change callback (libzypp 3.20.0)
     virtual void finish( const zypp::Url & /*file*/, Error error, const std::string & konreason )
     {
-      if (gSettings.verbosity < VERBOSITY_NORMAL)
+      if (_gopts.verbosity < VERBOSITY_NORMAL)
         return;
       else if (gData.show_media_progress_hack)
         display_done ("download", cout);
@@ -124,15 +127,19 @@ namespace ZmartRecipients
       // don't display errors here, they will be reported in media change callback
       // display_error (error, konreason);
     }
+    
+  private:
+    const GlobalOptions & _gopts;
   };
 
+
   struct AuthenticationReportReceiver : public zypp::callback::ReceiveReport<zypp::media::AuthenticationReport>
   {
     virtual bool prompt(const zypp::Url & url,
                         const std::string & description,
                         zypp::media::AuthData & auth_data)
     {
-      if (gSettings.non_interactive)
+      if (Zypper::instance()->globalOpts().non_interactive)
       {
         MIL << "Non-interactive mode: aborting" << std::endl;
         cout_vv << description << std::endl;
index ba5bf5d..bc06bdb 100644 (file)
@@ -37,15 +37,14 @@ using namespace boost;
 
 extern ZYpp::Ptr God;
 extern RuntimeData gData;
-extern GlobalOptions gSettings;
 
 
-void cond_init_target () {
+void cond_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;
-    God->initializeTarget(gSettings.root_dir);
+    God->initializeTarget(zypper.globalOpts().root_dir);
     done = true;
   }
 }
@@ -407,7 +406,8 @@ ostream& operator << (ostream & stm, ios::iostate state)
 }
 
 //! @return true to retry solving now, false to cancel, indeterminate to continue
-tribool show_problem (const ResolverProblem & prob, ProblemSolutionList & todo)
+tribool show_problem (Zypper & zypper,
+                      const ResolverProblem & prob, ProblemSolutionList & todo)
 {
   ostream& stm = cerr;
   string det;
@@ -430,7 +430,7 @@ tribool show_problem (const ResolverProblem & prob, ProblemSolutionList & todo)
       stm << "  " << det << endl;
   }
 
-  if (gSettings.non_interactive)
+  if (zypper.globalOpts().non_interactive)
     return false;
 
   int reply;
@@ -472,7 +472,7 @@ tribool show_problem (const ResolverProblem & prob, ProblemSolutionList & todo)
 }
 
 // return true to retry solving, false to cancel transaction
-bool show_problems ()
+bool show_problems(Zypper & zypper)
 {
   bool retry = true;
   ostream& stm = cerr;
@@ -504,7 +504,7 @@ bool show_problems ()
   // now list all problems with solution proposals
   for (i = b; i != e; ++i) {
     stm << endl;
-    tribool stopnow = show_problem (*(*i), todo);
+    tribool stopnow = show_problem(zypper, *(*i), todo);
     if (! indeterminate (stopnow)) {
       retry = stopnow == true;
       break;
@@ -522,7 +522,8 @@ bool show_problems ()
 typedef map<KindOf<Resolvable>,set<ResObject::constPtr> > KindToResObjectSet;
 
 void show_summary_resolvable_list(const string & label,
-                                  KindToResObjectSet::const_iterator it)
+                                  KindToResObjectSet::const_iterator it,
+                                  int verbosity)
 {
   cout << endl << label << endl;
 
@@ -543,7 +544,7 @@ void show_summary_resolvable_list(const string & label,
   {
     ResObject::constPtr res(*resit);
 
-    if (gSettings.verbosity == VERBOSITY_NORMAL)
+    if (verbosity == VERBOSITY_NORMAL)
     {
       // watch the terminal widht
       if (cols_written == 0)
@@ -560,7 +561,7 @@ void show_summary_resolvable_list(const string & label,
       cout << INDENT;
 
     // resolvable name
-    cout << res->name() << (gSettings.verbosity ? "" : " ");
+    cout << res->name() << (verbosity ? "" : " ");
     // plus edition and architecture for verbose output
     cout_v << "-" << res->edition() << "." << res->arch();
     // plus repo providing this package
@@ -570,7 +571,7 @@ void show_summary_resolvable_list(const string & label,
     cout_v << endl;
   }
 
-  if (gSettings.verbosity == VERBOSITY_NORMAL)
+  if (verbosity == VERBOSITY_NORMAL)
     cout << endl;
 }
 
@@ -581,7 +582,7 @@ void show_summary_resolvable_list(const string & label,
  *  ZYPPER_EXIT_INF_REBOOT_NEEDED - if one of patches to be installed needs machine reboot,
  *  ZYPPER_EXIT_INF_RESTART_NEEDED - if one of patches to be installed needs package manager restart
  */
-int show_summary()
+int show_summary(Zypper & zypper)
 {
   int retv = -1; // nothing to do;
 
@@ -631,7 +632,7 @@ int show_summary()
 
   if (retv == -1)
   {
-    if (gSettings.machine_readable)
+    if (zypper.globalOpts().machine_readable)
       cout << "<message type=\"warning\">" << _("Nothing to do.") << "</message>" << endl;
     else
       cout << _("Nothing to do.") << endl;
@@ -640,7 +641,7 @@ int show_summary()
   }
 
   // no output for machines for now
-  if (gSettings.machine_readable)
+  if (zypper.globalOpts().machine_readable)
     return retv;
 
   KindToResObjectSet toinstall;
@@ -708,7 +709,7 @@ int show_summary()
         it->second.size()
     )) % kind_to_string_localized(it->first, it->second.size()));
 
-    show_summary_resolvable_list(title, it);
+    show_summary_resolvable_list(title, it, zypper.globalOpts().verbosity);
   }
 
   for (KindToResObjectSet::const_iterator it = todowngrade.begin();
@@ -722,7 +723,7 @@ int show_summary()
         it->second.size()
     )) % kind_to_string_localized(it->first, it->second.size()));
 
-    show_summary_resolvable_list(title, it);
+    show_summary_resolvable_list(title, it, zypper.globalOpts().verbosity);
   }
 
   for (KindToResObjectSet::const_iterator it = toinstall.begin();
@@ -736,7 +737,7 @@ int show_summary()
         it->second.size()
     )) % kind_to_string_localized(it->first, it->second.size()));
 
-    show_summary_resolvable_list(title, it);
+    show_summary_resolvable_list(title, it, zypper.globalOpts().verbosity);
   }
 
   for (KindToResObjectSet::const_iterator it = toremove.begin();
@@ -750,7 +751,7 @@ int show_summary()
         it->second.size()
     )) % kind_to_string_localized(it->first, it->second.size()));
 
-    show_summary_resolvable_list(title, it);
+    show_summary_resolvable_list(title, it, zypper.globalOpts().verbosity);
   }
 
   cout << endl;
@@ -828,12 +829,12 @@ void establish ()
   dump_pool ();
 }
 
-bool resolve()
+bool resolve(const Zypper & zypper)
 {
   establish ();
   cout_v << _("Resolving dependencies...") << endl;
   God->resolver()->setForceResolve(
-      gSettings.is_rug_compatible ? true : copts.count("force-resolution") );
+      zypper.globalOpts().is_rug_compatible ? true : copts.count("force-resolution") );
   return God->resolver()->resolvePool();
 }
 
@@ -898,13 +899,13 @@ void dump_pool ()
 }
 
 // patches
-void show_patches()
+void show_patches(const Zypper & zypper)
 {
   MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl;
 
   Table tbl;
   TableHeader th;
-  th << (gSettings.is_rug_compatible ? _("Catalog: ") : _("Repository: "))
+  th << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: "))
      << _("Name") << _("Version") << _("Category") << _("Status");
   tbl << th;
 
@@ -1017,14 +1018,14 @@ bool xml_list_patches ()
 
 // ----------------------------------------------------------------------------
 
-void list_patch_updates(bool best_effort)
+void list_patch_updates(const Zypper & zypper, bool best_effort)
 {
   Table tbl;
   Table pm_tbl;        // only those that affect packagemanager: they have priority
   TableHeader th;
   unsigned cols;
 
-  th << (gSettings.is_rug_compatible ? _("Catalog: ") : _("Repository: "))
+  th << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: "))
      << _("Name") << _("Version") << _("Category") << _("Status");
   cols = 5;
   tbl << th;
@@ -1155,11 +1156,11 @@ find_updates( const ResObject::Kind &kind, Candidates &candidates )
 
 // ----------------------------------------------------------------------------
 
-void list_updates( const ResObject::Kind &kind, bool best_effort )
+void list_updates(const Zypper & zypper, const ResObject::Kind &kind, bool best_effort )
 {
   bool k_is_patch = kind == ResTraits<Patch>::kind;
   if (k_is_patch)
-    list_patch_updates( best_effort );
+    list_patch_updates(zypper, best_effort );
   else {
     Table tbl;
 
@@ -1173,9 +1174,9 @@ void list_updates( const ResObject::Kind &kind, bool best_effort )
     // TranslatorExplanation S stands for Status
     th << _("S");
     if (!hide_repo) {
-      th << (gSettings.is_rug_compatible ? _("Catalog: ") : _("Repository: "));
+      th << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: "));
     }
-    if (gSettings.is_rug_compatible) {
+    if (zypper.globalOpts().is_rug_compatible) {
       th << _("Bundle");
     }
     name_col = th.cols();
@@ -1200,7 +1201,7 @@ void list_updates( const ResObject::Kind &kind, bool best_effort )
       if (!hide_repo) {
        tr << res->repository().info().name();
       }
-      if (gSettings.is_rug_compatible)
+      if (zypper.globalOpts().is_rug_compatible)
        tr << "";               // Bundle
       tr << res->name ();
 
@@ -1380,27 +1381,29 @@ void mark_updates( const ResObject::Kind &kind, bool skip_interactive, bool best
  *  ZYPPER_EXIT_INF_REBOOT_NEEDED - if one of patches to be installed needs machine reboot,
  *  ZYPPER_EXIT_INF_RESTART_NEEDED - if one of patches to be installed needs package manager restart
  */
-int solve_and_commit () {
+void solve_and_commit (Zypper & zypper)
+{
   while (true) {
-    bool success = resolve();
+    bool success = resolve(zypper);
     if (success)
       break;
 
-    success = show_problems ();
+    success = show_problems(zypper);
     if (! success) {
       // TODO cancel transaction?
-      return ZYPPER_EXIT_ERR_ZYPP; // #242736
+      zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP); // #242736
+      return;
     }
   }
 
 
   // returns -1, 0, ZYPPER_EXIT_INF_REBOOT_NEEDED, or ZYPPER_EXIT_INF_RESTART_NEEDED
-  int retv = show_summary();
+  int retv = show_summary(zypper);
   bool was_installed = false;
   if (retv >= 0) { // there are resolvables to install/uninstall
     if (read_bool_answer(_("Continue?"), true)) {
 
-      if (!confirm_licenses()) return ZYPPER_EXIT_OK;
+      if (!confirm_licenses(zypper)) return;
 
       cerr_v << _("committing") << endl;
 
@@ -1424,14 +1427,16 @@ int solve_and_commit () {
         report_problem(e,
             _("Problem downloading the package file from the repository:"),
             _("Please, see the above error message to for a hint."));
-        return ZYPPER_EXIT_ERR_ZYPP;
+        zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+        return;
       }
       catch ( const zypp::repo::RepoException & e ) {
         ZYPP_CAUGHT(e);
         report_problem(e,
             _("Problem downloading the package file from the repository:"),
             _("Please, see the above error message to for a hint."));
-        return ZYPPER_EXIT_ERR_ZYPP;
+        zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+        return;
       }
       catch ( const zypp::FileCheckException & e ) {
         ZYPP_CAUGHT(e);
@@ -1442,7 +1447,8 @@ int solve_and_commit () {
             "- refresh the repositories using 'zypper refresh'\n"
             "- use another installation medium (if e.g. damaged)\n"
             "- use another repository"));
-        return ZYPPER_EXIT_ERR_ZYPP;
+        zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+        return;
       }
       catch ( const Exception & excpt_r ) {
         ZYPP_CAUGHT( excpt_r );
@@ -1457,7 +1463,7 @@ int solve_and_commit () {
   {
     if (retv == ZYPPER_EXIT_INF_REBOOT_NEEDED)
     {
-      if (gSettings.machine_readable)
+      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
@@ -1466,14 +1472,14 @@ int solve_and_commit () {
     }
     else if (retv == ZYPPER_EXIT_INF_RESTART_NEEDED)
     {
-      if (!gSettings.machine_readable)
+      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;
     }
   }
 
-  return retv;
+  zypper.setExitCode(retv);
 }
 
 // TODO confirm licenses
@@ -1481,7 +1487,7 @@ int solve_and_commit () {
 //  ask for [y/n/r] with 'r' for read the license text
 //  (opened throu more or less, etc...)
 // - after negative answer, call solve_and_commit() again
-bool confirm_licenses()
+bool confirm_licenses(Zypper & zypper)
 {
   bool confirmed = true;
 
@@ -1490,10 +1496,10 @@ bool confirm_licenses()
     if (it->status().isToBeInstalled() &&
         !it->resolvable()->licenseToConfirm().empty())
     {
-      if (gSettings.license_auto_agree)
+      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 (!gSettings.machine_readable)
+                         if (!zypper.globalOpts().machine_readable)
                cout << format(_("Automatically agreeing with %s %s license."))
                    % it->resolvable()->name()
                    % kind_to_string_localized(it->resolvable()->kind(),1)
@@ -1513,11 +1519,11 @@ bool confirm_licenses()
       string question = _("In order to install this package, you must agree"
         " to terms of the above license. Continue?");
 
-      if (!read_bool_answer(question, gSettings.license_auto_agree))
+      if (!read_bool_answer(question, zypper.cmdOpts().license_auto_agree))
       {
         confirmed = false;
 
-        if (gSettings.non_interactive)
+        if (zypper.globalOpts().non_interactive)
         {
           //! \todo do this with _PL()
           cout << endl <<
index 773edbc..691ad2e 100644 (file)
@@ -19,7 +19,7 @@
 /**
  * Initialize rpm database on target, if not already initialized. 
  */
-void cond_init_target();
+void cond_init_target(Zypper & zypper);
 
 /// Parse a capability string. On error print a message and return noCap
 zypp::Capability safe_parse_cap (const Zypper & zypper,
@@ -40,13 +40,13 @@ void mark_by_capability (const Zypper & zypper,
                         const zypp::ResObject::Kind &kind,
                         const std::string &capstr );
 
-int show_summary();
+int show_summary(Zypper & zypper);
 //std::string calculate_token();
 
-void establish ();
-bool resolve();
-void dump_pool ();
-void show_patches();
+void establish();
+bool resolve(const Zypper & zypper);
+void dump_pool();
+void show_patches(const Zypper & zypper);
 bool xml_list_patches();
 void xml_list_updates();
 
@@ -65,7 +65,9 @@ void patch_check();
  * \param kind  resolvable type
  * \param best_effort
  */
-void list_updates( const zypp::ResObject::Kind &kind, bool best_effort );
+void list_updates(const Zypper & zypper,
+                  const zypp::ResObject::Kind &kind,
+                  bool best_effort);
 
 /**
  * \param kind  resolvable type
@@ -83,7 +85,7 @@ void mark_updates( const zypp::ResObject::Kind &kind, bool skip_interactive, boo
  *         or ZYPPER_EXIT_OK or ZYPPER_EXIT_ERR_ZYPP on zypp erorr. 
  *  
  */
-int solve_and_commit ();
+void solve_and_commit(Zypper & zypper);
 
 /**
  * Loops through resolvables, checking if there is license to confirm. When
@@ -92,7 +94,7 @@ int solve_and_commit ();
  * 
  * \returns true if all licenses have been confirmed, false otherwise.  
  */
-bool confirm_licenses();
+bool confirm_licenses(Zypper & zypper);
 
 // copied from yast2-pkg-bindings:PkgModuleFunctions::DoProvideNameKind
 struct ProvideProcess
index 426239d..73cff86 100644 (file)
@@ -33,7 +33,6 @@ using namespace zypp::parser;
 
 extern ZYpp::Ptr God;
 extern RuntimeData gData;
-extern GlobalOptions gSettings;
 
 
 static bool refresh_raw_metadata(const Zypper & zypper,
@@ -47,7 +46,7 @@ static bool refresh_raw_metadata(const Zypper & zypper,
 
   try
   {
-    RepoManager manager(gSettings.rm_options);
+    RepoManager manager(zypper.globalOpts().rm_options);
 
     if (!force_download)
     {
@@ -153,14 +152,14 @@ bool build_cache_callback(const ProgressData & pd)
   return true;
 }
 */
-static bool build_cache(const RepoInfo &repo, bool force_build)
+static bool build_cache(Zypper & zypper, const RepoInfo &repo, bool force_build)
 {
   if (force_build)
     cout << _("Forcing building of repository cache") << endl;
 
   try
   {
-    RepoManager manager(gSettings.rm_options);
+    RepoManager manager(zypper.globalOpts().rm_options);
     manager.buildCache(repo, force_build ?
       RepoManager::BuildForced : RepoManager::BuildIfNeeded);
   }
@@ -208,8 +207,8 @@ static bool build_cache(const RepoInfo &repo, bool force_build)
 static void do_init_repos(Zypper & zypper)
 {
   // load gpg keys
-  cond_init_target ();
-  RepoManager manager(gSettings.rm_options);
+  cond_init_target(zypper);
+  RepoManager manager(zypper.globalOpts().rm_options);
 
   string specific_repo = copts.count("repo") ? copts["repo"].front() : "";
 
@@ -260,7 +259,8 @@ static void do_init_repos(Zypper & zypper)
       // handle root user differently
       if (geteuid() == 0)
       {
-        if (refresh_raw_metadata(zypper, repo, false) || build_cache(repo, false))
+        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;
@@ -303,7 +303,7 @@ void init_repos(Zypper & zypper)
   if (done)
     return;
 
-  if ( !gSettings.disable_system_sources )
+  if ( !zypper.globalOpts().disable_system_sources )
   {
     do_init_repos(zypper);
   }
@@ -354,14 +354,15 @@ static void print_rug_sources_list(const std::list<zypp::RepoInfo> &repos)
 
 // ----------------------------------------------------------------------------
 
-static void print_repo_list( const std::list<zypp::RepoInfo> &repos )
+static void print_repo_list(const Zypper & zypper,
+                            const std::list<zypp::RepoInfo> &repos )
 {
   Table tbl;
 
   // header
   TableHeader th;
   th << "#" << _("Enabled") << _("Refresh") << _("Type") << _("Alias") << _("Name");
-  if (gSettings.verbosity > VERBOSITY_NORMAL)
+  if (zypper.globalOpts().verbosity > VERBOSITY_NORMAL)
     th << "URI";
   tbl << th;
 
@@ -371,7 +372,7 @@ static void print_repo_list( const std::list<zypp::RepoInfo> &repos )
        it !=  repos.end(); ++it)
   {
     RepoInfo repo = *it;
-    TableRow tr (gSettings.verbosity > VERBOSITY_NORMAL ? 6 : 7);
+    TableRow tr (zypper.globalOpts().verbosity > VERBOSITY_NORMAL ? 6 : 7);
 
     // number
     tr << str::numstring (i);
@@ -386,7 +387,7 @@ static void print_repo_list( const std::list<zypp::RepoInfo> &repos )
     // name
     tr << repo.name();
     // url
-    if (gSettings.verbosity > VERBOSITY_NORMAL)
+    if (zypper.globalOpts().verbosity > VERBOSITY_NORMAL)
       tr << (*repo.baseUrlsBegin()).asString(); //! \todo properly handle multiple baseurls
 
     tbl << tr;
@@ -415,9 +416,9 @@ void print_repos_to(const std::list<zypp::RepoInfo> &repos, ostream & out)
 
 // ----------------------------------------------------------------------------
 
-void list_repos()
+void list_repos(Zypper & zypper)
 {
-  RepoManager manager(gSettings.rm_options);
+  RepoManager manager(zypper.globalOpts().rm_options);
   list<RepoInfo> repos;
 
   try
@@ -464,11 +465,11 @@ void list_repos()
     }
   }
   // print repo list the rug's way
-  else if (gSettings.is_rug_compatible)
+  else if (zypper.globalOpts().is_rug_compatible)
     print_rug_sources_list(repos);
   // print repo list as table
   else
-    print_repo_list(repos);
+    print_repo_list(zypper, repos);
 }
 
 // ----------------------------------------------------------------------------
@@ -484,11 +485,11 @@ void safe_lexical_cast (Source s, Target &tr) {
 
 // ----------------------------------------------------------------------------
 
-int refresh_repos(const Zypper & zypper, vector<string> & arguments)
+int refresh_repos(Zypper & zypper, vector<string> & arguments)
 {
   // need gpg keys when downloading (#304672)
-  cond_init_target();
-  RepoManager manager(gSettings.rm_options);
+  cond_init_target(zypper);
+  RepoManager manager(zypper.globalOpts().rm_options);
   list<RepoInfo> repos;
   try
   {
@@ -598,7 +599,7 @@ int refresh_repos(const Zypper & zypper, vector<string> & arguments)
 
       MIL << "calling buildCache" << (force_build ? ", forced" : "") << endl;
 
-      error = build_cache(repo, force_build);
+      error = build_cache(zypper, repo, force_build);
     }
 
     if (error)
@@ -676,9 +677,9 @@ std::string timestamp ()
 // ----------------------------------------------------------------------------
 
 static
-int add_repo(const Zypper & zypper, RepoInfo & repo)
+int add_repo(Zypper & zypper, RepoInfo & repo)
 {
-  RepoManager manager(gSettings.rm_options);
+  RepoManager manager(zypper.globalOpts().rm_options);
 
   bool is_cd = true;
   for(RepoInfo::urls_const_iterator it = repo.baseUrlsBegin();
@@ -745,7 +746,7 @@ int add_repo(const Zypper & zypper, RepoInfo & repo)
   cout_n << ":";
   cout << endl;
 
-  if (gSettings.is_rug_compatible)
+  if (zypper.globalOpts().is_rug_compatible)
   {
     cout_n << ( repo.enabled() ? "[x]" : "[ ]" );
     cout_n << ( repo.autorefresh() ? "* " : "  " );
@@ -767,7 +768,7 @@ int add_repo(const Zypper & zypper, RepoInfo & repo)
     cout_n << format(_("Reading data from '%s' media")) % repo.name() << endl;
     bool error = refresh_raw_metadata(zypper, repo, false);
     if (!error)
-      error = build_cache(repo, false);
+      error = build_cache(zypper, repo, false);
     if (error)
     {
       cerr << format(_("Problem reading data from '%s' media")) % repo.name() << endl;
@@ -781,7 +782,7 @@ int add_repo(const Zypper & zypper, RepoInfo & repo)
 
 // ----------------------------------------------------------------------------
 
-int add_repo_by_url( const Zypper & zypper,
+int add_repo_by_url( Zypper & zypper,
                      const zypp::Url & url, const string & alias,
                      const string & type,
                      tribool enabled, tribool autorefresh)
@@ -789,7 +790,7 @@ int add_repo_by_url( const Zypper & zypper,
   MIL << "going to add repository by url (alias=" << alias << ", url=" << url
       << ")" << endl;
 
-  RepoManager manager(gSettings.rm_options);
+  RepoManager manager(zypper.globalOpts().rm_options);
   RepoInfo repo;
 
   if ( ! type.empty() )
@@ -809,7 +810,7 @@ int add_repo_by_url( const Zypper & zypper,
 // ----------------------------------------------------------------------------
 
 //! \todo handle zypp exceptions
-int add_repo_from_file(const Zypper & zypper,
+int add_repo_from_file( Zypper & zypper,
                        const std::string & repo_file_url,
                        tribool enabled, tribool autorefresh)
 {
@@ -818,7 +819,7 @@ int add_repo_from_file(const Zypper & zypper,
   if (!url.isValid())
     return ZYPPER_EXIT_ERR_INVALID_ARGS;
 
-  RepoManager manager(gSettings.rm_options);
+  RepoManager manager(zypper.globalOpts().rm_options);
   list<RepoInfo> repos;
 
   // read the repo file
@@ -895,9 +896,9 @@ bool looks_like_url (const string& s) {
   return false;
 }
 */
-static bool do_remove_repo(const RepoInfo & repoinfo)
+static bool do_remove_repo(Zypper & zypper, const RepoInfo & repoinfo)
 {
-  RepoManager manager(gSettings.rm_options);
+  RepoManager manager(zypper.globalOpts().rm_options);
   bool found = true;
   try
   {
@@ -916,23 +917,22 @@ static bool do_remove_repo(const RepoInfo & repoinfo)
 
 // ----------------------------------------------------------------------------
 
-bool remove_repo( const std::string &alias )
+bool remove_repo(Zypper & zypper, const std::string &alias )
 {
-  RepoManager manager(gSettings.rm_options);
   RepoInfo info;
   info.setAlias(alias);
 
-  return do_remove_repo(info);
+  return do_remove_repo(zypper, info);
 }
 
-bool remove_repo(const Url & url, const url::ViewOption & urlview)
+bool remove_repo(Zypper & zypper, const Url & url, const url::ViewOption & urlview)
 {
-  RepoManager manager(gSettings.rm_options);
+  RepoManager manager(zypper.globalOpts().rm_options);
   bool found = true;
   try
   {
     RepoInfo info = manager.getRepositoryInfo(url, urlview);
-    found = do_remove_repo(info);
+    found = do_remove_repo(zypper, info);
   }
   catch (const repo::RepoNotFoundException & ex)
   {
@@ -944,9 +944,10 @@ bool remove_repo(const Url & url, const url::ViewOption & urlview)
 
 // ----------------------------------------------------------------------------
 
-void rename_repo(const std::string & alias, const std::string & newalias)
+void rename_repo(Zypper & zypper,
+                 const std::string & alias, const std::string & newalias)
 {
-  RepoManager manager(gSettings.rm_options);
+  RepoManager manager(zypper.globalOpts().rm_options);
 
   try
   {
@@ -974,7 +975,7 @@ void rename_repo(const std::string & alias, const std::string & newalias)
 
 // ----------------------------------------------------------------------------
 
-void modify_repo(const string & alias)
+void modify_repo(Zypper & zypper, const string & alias)
 {
   // tell whether currenlty processed options are contradicting each other
   // bool contradiction = false;
@@ -1020,7 +1021,7 @@ void modify_repo(const string & alias)
 
   try
   {
-    RepoManager manager(gSettings.rm_options);
+    RepoManager manager(zypper.globalOpts().rm_options);
     RepoInfo repo(manager.getRepositoryInfo(alias));
 
     if (!indeterminate(enable))
@@ -1051,18 +1052,18 @@ void modify_repo(const string & alias)
 
 // ---------------------------------------------------------------------------
 
-void cond_load_resolvables(const Zypper & zypper, bool to_pool)
+void cond_load_resolvables(Zypper & zypper, bool to_pool)
 {
   load_repo_resolvables(zypper, to_pool);
-  if (!gSettings.disable_system_resolvables && to_pool)
-    load_target_resolvables();
+  if (!zypper.globalOpts().disable_system_resolvables && to_pool)
+    load_target_resolvables(zypper);
 }
 
 // ---------------------------------------------------------------------------
 
-void load_repo_resolvables(const Zypper & zypper, bool to_pool)
+void load_repo_resolvables(Zypper & zypper, bool to_pool)
 {
-  RepoManager manager(gSettings.rm_options);
+  RepoManager manager(zypper.globalOpts().rm_options);
 
   for (std::list<RepoInfo>::iterator it = gData.repos.begin();
        it !=  gData.repos.end(); ++it)
@@ -1088,7 +1089,7 @@ void load_repo_resolvables(const Zypper & zypper, bool to_pool)
       {
         cout_v << format(_("Repository '%s' not cached. Caching..."))
                          % repo.name() << endl;
-        error = build_cache(repo, false);
+        error = build_cache(zypper, repo, false);
       }
 
       if (error)
@@ -1122,15 +1123,15 @@ void load_repo_resolvables(const Zypper & zypper, bool to_pool)
 
 // ---------------------------------------------------------------------------
 
-void load_target_resolvables(bool to_pool)
+void load_target_resolvables(Zypper & zypper, bool to_pool)
 {
-  if (!gSettings.machine_readable)
+  if (!zypper.globalOpts().machine_readable)
     cout_n << _("Reading RPM database...");
   MIL << "Going to read RPM database" << endl;
 
   ResStore tgt_resolvables(God->target()->resolvables());
 
-  if (!gSettings.machine_readable)
+  if (!zypper.globalOpts().machine_readable)
   {
     cout_v << "   " <<  format(_("(%s resolvables)")) % tgt_resolvables.size();
     cout_n << endl;
index a270671..92d123d 100644 (file)
@@ -20,12 +20,12 @@ void init_repos(Zypper & zypper);
 /**
  * List defined repositories.
  */
-void list_repos();
+void list_repos(Zypper & zypper);
 
 /**
  * Refresh all enabled repositories.
  */
-int refresh_repos(const Zypper & zypper, std::vector<std::string> & arguments);
+int refresh_repos(Zypper & zypper, std::vector<std::string> & arguments);
 
 
 /**
@@ -39,7 +39,7 @@ int refresh_repos(const Zypper & zypper, std::vector<std::string> & arguments);
  * \return ZYPPER_EXIT_ERR_ZYPP on unexpected zypp exception,
  *         ZYPPER_EXIT_OK otherwise
  */
-int add_repo_by_url(const Zypper & zypper,
+int add_repo_by_url(Zypper & zypper,
                     const zypp::Url & url,
                     const std::string & alias,
                     const std::string & type = "",
@@ -57,7 +57,7 @@ int add_repo_by_url(const Zypper & zypper,
  * \return ZYPPER_EXIT_ERR_ZYPP on unexpected zypp exception,
  *         ZYPPER_EXIT_OK otherwise
  */
-int add_repo_from_file(const Zypper & zypper,
+int add_repo_from_file(Zypper & zypper,
                        const std::string & repo_file_url,
                        boost::tribool enabled = boost::indeterminate,
                        boost::tribool autorefresh = boost::indeterminate);
@@ -65,21 +65,23 @@ int add_repo_from_file(const Zypper & zypper,
 /**
  * Delte repository specified by \a alias.
  */
-bool remove_repo( const std::string &alias );
+bool remove_repo(Zypper & zypper, const std::string &alias );
 
-bool remove_repo( const zypp::Url & url, const zypp::url::ViewOption & urlview );
+bool remove_repo(Zypper & zypper,
+                 const zypp::Url & url, const zypp::url::ViewOption & urlview);
 
 /**
  * Rename repository specified by \a alias to \a newalias.
  */
-void rename_repo(const std::string & alias, const std::string & newalias);
+void rename_repo(Zypper & zypper,
+                 const std::string & alias, const std::string & newalias);
 
 /**
  * Modify repository properties.
  * 
  * \param alias repository alias
  */
-void modify_repo(const std::string & alias);
+void modify_repo(Zypper & zypper, const std::string & alias);
 
 
 /**
@@ -92,7 +94,7 @@ void modify_repo(const std::string & alias);
  * \see load_repo_resolvables(bool)
  * \see load_target_resolvables(bool)
  */
-void cond_load_resolvables(const Zypper & zypper, bool to_pool = true);
+void cond_load_resolvables(Zypper & zypper, bool to_pool = true);
 
 /**
  * Reads resolvables from the RPM database (installed resolvables) into the pool.
@@ -101,7 +103,7 @@ void cond_load_resolvables(const Zypper & zypper, bool to_pool = true);
  *        <tt>false</tt> they will be stored \ref gData.target_resolvables
  *        (global ResStore variable).
  */
-void load_target_resolvables(bool to_pool = true);
+void load_target_resolvables(Zypper & zypper, bool to_pool = true);
 
 /**
  * Reads resolvables from the repository sqlite cache. 
@@ -110,7 +112,7 @@ void load_target_resolvables(bool to_pool = true);
  *        <tt>false</tt> they will be stored in \ref gData.repo_resolvables
  *        (global ResStore vector).
  */
-void load_repo_resolvables(const Zypper & zypper, bool to_pool = true);
+void load_repo_resolvables(Zypper & zypper, bool to_pool = true);
 
 
 /**
index a2b8257..0f9028f 100644 (file)
@@ -20,6 +20,7 @@
 #include "zypp/Package.h"
 //#include "zypp/target/rpm/RpmCallbacks.h"
 
+#include "zypper.h"
 #include "zypper-callbacks.h"
 #include "AliveCursor.h"
 
@@ -35,7 +36,8 @@ struct MessageResolvableReportReceiver : public zypp::callback::ReceiveReport<zy
 {
   virtual void show( zypp::Message::constPtr message )
   {
-    if ( !gSettings.machine_readable )
+    
+    if ( !Zypper::instance()->globalOpts().machine_readable )
     {
       cout_v << message << endl; // [message]important-msg-1.0-1
       cout_n << message->text() << endl;
index 32ae4a6..64e0d6b 100644 (file)
@@ -30,7 +30,7 @@ ZyppSearchOptions::ZyppSearchOptions()
   // check for disabled repos and limit list of repos accordingly.
   //   "-r/--repo" will override this
   try {
-    RepoManager manager(gSettings.rm_options);
+    RepoManager manager(Zypper::instance()->globalOpts().rm_options);
     std::list<zypp::RepoInfo> known_repos = manager.knownRepositories();
     std::list<zypp::RepoInfo>::const_iterator it_r;
     for (it_r = known_repos.begin(); it_r != known_repos.end(); ++it_r)
@@ -78,7 +78,8 @@ ZyppSearch::ZyppSearch (
     const ZyppSearchOptions & options,
     const vector<string> qstrings
     ) :
-    _zypp(zypp), _options(options), _qstrings(qstrings), _query( gSettings.rm_options.repoCachePath ) {
+    _zypp(zypp), _options(options), _qstrings(qstrings),
+    _query( Zypper::instance()->globalOpts().rm_options.repoCachePath ) {
 
 #if 0  // we don't search the pool but iterate on the cache directly, hence no repos needed
   // no repos warning
index 8af1f85..3384b21 100644 (file)
@@ -26,7 +26,6 @@
 #include "zypper-getopt.h"
 #include "zypper-tabulator.h"
 
-extern GlobalOptions gSettings;
 
 /**
  * Represents zypper search options.
@@ -279,18 +278,19 @@ struct FillTable
   , _icache( &icache )
   , _query( query )
   , _options( options )
+  , _gopts(Zypper::instance()->globalOpts())
   {
     TableHeader header;
 
     // TranslatorExplanation S as Status
     header << _("S");
 
-    if (gSettings.is_rug_compatible)
+    if (_gopts.is_rug_compatible)
       header << _("Catalog");
     else
       header << _("Repository");
 
-    if (gSettings.is_rug_compatible)
+    if (_gopts.is_rug_compatible)
       // TranslatorExplanation This is Bundle in as used in rug.
       header << _("Bundle");
     else
@@ -316,7 +316,7 @@ struct FillTable
         row << "i"
            << pool_item.resolvable()->repository().info().name()
             // TODO what about rug's Bundle?
-            << (gSettings.is_rug_compatible ?
+            << (_gopts.is_rug_compatible ?
                 "" : kind_to_string_localized(pool_item.resolvable()->kind(), 1))
             << pool_item.resolvable()->name()
             << pool_item.resolvable()->edition().asString()
@@ -358,7 +358,7 @@ struct FillTable
     // add other fields to the result table
     row << alias
         // TODO what about rug's Bundle?
-        << (gSettings.is_rug_compatible ?
+        << (_gopts.is_rug_compatible ?
             "" : kind_to_string_localized(res->kind, 1))
         << res->name
         << res->edition.asString()
@@ -380,6 +380,8 @@ struct FillTable
 
   // the search options, contains i.e. the list of kinds to show
   const ZyppSearchOptions & _options;
+
+  const GlobalOptions & _gopts;
 };
 
 
index 102cb4d..ca8fdc9 100644 (file)
@@ -47,9 +47,9 @@ using namespace boost;
 
 ZYpp::Ptr God = NULL;
 RuntimeData gData;
-GlobalOptions gSettings;
 parsed_opts copts; // command options
 
+IMPL_PTR_TYPE(Zypper);
 
 Zypper::Zypper()
   : _argc(0), _argv(NULL),
@@ -66,6 +66,16 @@ Zypper::~Zypper()
   MIL << "Bye!" << endl;
 }
 
+Zypper_Ptr Zypper::instance()
+{
+  static Zypper_Ptr _instance;
+  
+  if (!_instance)
+    _instance = new Zypper();
+
+  return _instance;
+}
+
 
 int Zypper::main(int argc, char ** argv)
 {
@@ -157,7 +167,7 @@ void Zypper::processGlobalOptions()
   parsed_opts::const_iterator it;
 
   if (gopts.count("rug-compatible"))
-    gSettings.is_rug_compatible = true;
+    _gopts.is_rug_compatible = true;
 
   // Help is parsed by setting the help flag for a command, which may be empty
   // $0 -h,--help
@@ -169,26 +179,26 @@ void Zypper::processGlobalOptions()
     setRunningHelp(true);
 
   if (gopts.count("quiet")) {
-    gSettings.verbosity = -1;
-    DBG << "Verbosity " << gSettings.verbosity << endl;
+    _gopts.verbosity = -1;
+    DBG << "Verbosity " << _gopts.verbosity << endl;
   }
 
   if ((it = gopts.find("verbose")) != gopts.end()) {
-    gSettings.verbosity += it->second.size(); 
+    _gopts.verbosity += it->second.size(); 
 
-//    gSettings.verbosity += gopts["verbose"].size();
-    cout << format(_("Verbosity: %d")) % gSettings.verbosity << endl;
-    DBG << "Verbosity " << gSettings.verbosity << endl;
+//    _gopts.verbosity += gopts["verbose"].size();
+    cout << format(_("Verbosity: %d")) % _gopts.verbosity << endl;
+    DBG << "Verbosity " << _gopts.verbosity << endl;
   }
 
   if (gopts.count("non-interactive")) {
-    gSettings.non_interactive = true;
+    _gopts.non_interactive = true;
     cout_n << _("Entering non-interactive mode.") << endl;
     MIL << "Entering non-interactive mode" << endl;
   }
 
   if (gopts.count("no-gpg-checks")) {
-    gSettings.no_gpg_checks = true;
+    _gopts.no_gpg_checks = true;
     cout_n << _("Entering no-gpg-checks mode.") << endl;
     MIL << "Entering no-gpg-checks mode" << endl;
   }
@@ -203,8 +213,8 @@ void Zypper::processGlobalOptions()
   }
 
   if ((it = gopts.find("root")) != gopts.end()) {
-    gSettings.root_dir = it->second.front();
-    Pathname tmp(gSettings.root_dir);
+    _gopts.root_dir = it->second.front();
+    Pathname tmp(_gopts.root_dir);
     if (!tmp.absolute())
     {
       cerr << _("The path specified in the --root option must be absolute.") << endl;
@@ -212,34 +222,34 @@ void Zypper::processGlobalOptions()
       return;
     }
 
-    DBG << "root dir = " << gSettings.root_dir << endl;
-    gSettings.rm_options.knownReposPath = gSettings.root_dir
-      + gSettings.rm_options.knownReposPath;
-    gSettings.rm_options.repoCachePath = gSettings.root_dir
-      + gSettings.rm_options.repoCachePath;
-    gSettings.rm_options.repoRawCachePath = gSettings.root_dir
-      + gSettings.rm_options.repoRawCachePath;
+    DBG << "root dir = " << _gopts.root_dir << endl;
+    _gopts.rm_options.knownReposPath = _gopts.root_dir
+      + _gopts.rm_options.knownReposPath;
+    _gopts.rm_options.repoCachePath = _gopts.root_dir
+      + _gopts.rm_options.repoCachePath;
+    _gopts.rm_options.repoRawCachePath = _gopts.root_dir
+      + _gopts.rm_options.repoRawCachePath;
   }
 
   if ((it = gopts.find("reposd-dir")) != gopts.end()) {
-    gSettings.rm_options.knownReposPath = it->second.front();
+    _gopts.rm_options.knownReposPath = it->second.front();
   }
 
   if ((it = gopts.find("cache-dir")) != gopts.end()) {
-    gSettings.rm_options.repoCachePath = it->second.front();
+    _gopts.rm_options.repoCachePath = it->second.front();
   }
 
   if ((it = gopts.find("raw-cache-dir")) != gopts.end()) {
-    gSettings.rm_options.repoRawCachePath = it->second.front();
+    _gopts.rm_options.repoRawCachePath = it->second.front();
   }
 
-  DBG << "repos.d dir = " << gSettings.rm_options.knownReposPath << endl;
-  DBG << "cache dir = " << gSettings.rm_options.repoCachePath << endl;
-  DBG << "raw cache dir = " << gSettings.rm_options.repoRawCachePath << endl;
+  DBG << "repos.d dir = " << _gopts.rm_options.knownReposPath << endl;
+  DBG << "cache dir = " << _gopts.rm_options.repoCachePath << endl;
+  DBG << "raw cache dir = " << _gopts.rm_options.repoRawCachePath << endl;
 
   if (gopts.count("terse")) 
   {
-    gSettings.machine_readable = true;
+    _gopts.machine_readable = true;
     cout << "<?xml version='1.0'?>" << endl;
     cout << "<stream>" << endl;
   }
@@ -251,7 +261,7 @@ void Zypper::processGlobalOptions()
     cout_n <<
         _("Repositories disabled, using the database of installed packages only.")
         << endl;
-    gSettings.disable_system_sources = true;
+    _gopts.disable_system_sources = true;
   }
   else
   {
@@ -262,7 +272,7 @@ void Zypper::processGlobalOptions()
   {
     MIL << "System resolvables disabled" << endl;
     cout_v << _("Ignoring installed resolvables...") << endl;
-    gSettings.disable_system_resolvables = true;
+    _gopts.disable_system_resolvables = true;
   }
 /*
   if (gopts.count("source"))
@@ -274,7 +284,7 @@ void Zypper::processGlobalOptions()
       if (!url.isValid())
       setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
       return;
-      gSettings.additional_sources.push_back(url); 
+      _gopts.additional_sources.push_back(url); 
     }
   }
 */
@@ -443,7 +453,7 @@ void Zypper::safeDoCommand()
         report_a_bug(cerr);
   }
 
-  if ( gSettings.machine_readable )
+  if ( globalOpts().machine_readable )
     cout << "</stream>" << endl;
 }
 
@@ -1039,7 +1049,7 @@ void Zypper::processCommandOptions()
           " package management running. All such applications must be closed before"
           " using this command.");
   
-      if ( gSettings.machine_readable )
+      if ( globalOpts().machine_readable )
         cout << "<message type=\"error\">" << msg  << "</message>" <<  endl;
       else
         cerr << msg << endl;
@@ -1078,7 +1088,7 @@ void Zypper::doCommand()
     if (runningHelp()) { cout << _command_help << endl; return; }
     // if (runningHelp()) display_command_help()
 
-    list_repos();
+    list_repos(*this);
     return;
   }
 
@@ -1147,7 +1157,7 @@ void Zypper::doCommand()
       warn_if_zmd();
 
       // load gpg keys
-      cond_init_target ();
+      cond_init_target(*this);
 
       setExitCode(add_repo_by_url(*this,
           url, _arguments[1]/*alias*/, type, enabled, refresh));
@@ -1200,7 +1210,7 @@ void Zypper::doCommand()
 
     warn_if_zmd ();
 
-    bool found = remove_repo(_arguments[0]);
+    bool found = remove_repo(*this, _arguments[0]);
     if (found)
     {
       setExitCode(ZYPPER_EXIT_OK);
@@ -1233,7 +1243,7 @@ void Zypper::doCommand()
       if (copts.count("loose-query"))
         urlview = urlview - url::ViewOptions::WITH_QUERY_STR;
 
-      found = remove_repo(url, urlview);
+      found = remove_repo(*this, url, urlview);
     }
     else
       found = false;
@@ -1283,11 +1293,11 @@ void Zypper::doCommand()
       return;
     }
 
-//    cond_init_target ();
+//    cond_init_target(*this);
     warn_if_zmd ();
     try {
       // also stores it
-      rename_repo(_arguments[0], _arguments[1]);
+      rename_repo(*this, _arguments[0], _arguments[1]);
     }
     catch ( const Exception & excpt_r )
     {
@@ -1335,7 +1345,7 @@ void Zypper::doCommand()
       return;
     }
 
-    modify_repo(_arguments[0]);
+    modify_repo(*this, _arguments[0]);
   }
 
   // --------------------------( refresh )------------------------------------
@@ -1384,7 +1394,7 @@ void Zypper::doCommand()
 
     if (copts.count("auto-agree-with-licenses")
         || copts.count("agree-to-third-party-licenses"))
-      gSettings.license_auto_agree = true;
+      _cmdopts.license_auto_agree = true;
 
     // check root user
     if (geteuid() != 0)
@@ -1397,7 +1407,7 @@ void Zypper::doCommand()
     // rug compatibility code
     // switch on non-interactive mode if no-confirm specified
     if (copts.count("no-confirm"))
-      gSettings.non_interactive = true;
+      _gopts.non_interactive = true;
 
 
     // read resolvable type
@@ -1415,7 +1425,7 @@ void Zypper::doCommand()
 
     //! \todo support temporary additional repos
     /*
-    for ( std::list<Url>::const_iterator it = gSettings.additional_sources.begin(); it != gSettings.additional_sources.end(); ++it )
+    for ( std::list<Url>::const_iterator it = globalOpts().additional_sources.begin(); it != globalOpts().additional_sources.end(); ++it )
     {
       include_source_by_url( *it );
     }
@@ -1428,7 +1438,7 @@ void Zypper::doCommand()
           " Nothing can be installed.") << endl;
     }
 
-    cond_init_target ();
+    cond_init_target(*this);
     cond_load_resolvables(*this);
 
     bool install_not_remove = command() == ZypperCommand::INSTALL;
@@ -1458,11 +1468,9 @@ void Zypper::doCommand()
     }
     else
     {
-      setExitCode(solve_and_commit());
-      return;
+      solve_and_commit(*this);
     }
 
-    setExitCode(ZYPPER_EXIT_OK);
     return;
   }
 
@@ -1488,7 +1496,7 @@ void Zypper::doCommand()
     if (exitCode() != ZYPPER_EXIT_OK)
       return;
 
-    cond_init_target();
+    cond_init_target(*this);
     // load only repo resolvables, we don't need the installed ones
     load_repo_resolvables(*this, false /* don't load to pool */);
 
@@ -1509,7 +1517,7 @@ void Zypper::doCommand()
       return;
     }
 
-    if (gSettings.disable_system_resolvables || copts.count("uninstalled-only"))
+    if (globalOpts().disable_system_resolvables || copts.count("uninstalled-only"))
       options.setInstalledFilter(ZyppSearchOptions::UNINSTALLED_ONLY);
 
     if (copts.count("installed-only")) options.setInstalledFilter(ZyppSearchOptions::INSTALLED_ONLY);
@@ -1532,7 +1540,7 @@ void Zypper::doCommand()
         options.addKind( kind );
       }
     }
-    else if (gSettings.is_rug_compatible) {
+    else if (globalOpts().is_rug_compatible) {
       options.clearKinds();
       options.addKind( ResTraits<Package>::kind );
     }
@@ -1551,7 +1559,7 @@ void Zypper::doCommand()
     if (exitCode() != ZYPPER_EXIT_OK)
       return;
 
-    cond_init_target();         // calls ZYpp::initializeTarget("/");
+    cond_init_target(*this);
     
     establish();
 
@@ -1597,7 +1605,7 @@ void Zypper::doCommand()
       return;
     }
 
-    cond_init_target ();
+    cond_init_target(*this);
 
     init_repos(*this);
     if (exitCode() != ZYPPER_EXIT_OK)
@@ -1645,14 +1653,14 @@ void Zypper::doCommand()
       return;
     }
 
-    cond_init_target ();
+    cond_init_target(*this);
     init_repos(*this);
     if (exitCode() != ZYPPER_EXIT_OK)
       return;
     cond_load_resolvables(*this);
-    establish ();
-    show_patches ();
-    setExitCode(ZYPPER_EXIT_OK);
+    establish();
+    show_patches(*this);
+
     return;
   }
 
@@ -1675,7 +1683,7 @@ void Zypper::doCommand()
     }
 
     string skind = copts.count("type")?  copts["type"].front() :
-      gSettings.is_rug_compatible? "package" : "patch";
+      globalOpts().is_rug_compatible? "package" : "patch";
     kind = string_to_kind (skind);
     if (kind == ResObject::Kind ()) {
       cerr << format(_("Unknown resolvable type: %s")) % skind << endl;
@@ -1685,20 +1693,20 @@ void Zypper::doCommand()
 
     bool best_effort = copts.count( "best-effort" ); 
 
-    if (gSettings.is_rug_compatible && best_effort) {
+    if (globalOpts().is_rug_compatible && best_effort) {
        best_effort = false;
        // 'rug' is the name of a program and must not be translated
        // 'best-effort' is a program parameter and can not be translated
        cerr << _("Running as 'rug', can't do 'best-effort' approach to update.") << endl;
     }
-    cond_init_target ();
+    cond_init_target(*this);
     init_repos(*this);
     if (exitCode() != ZYPPER_EXIT_OK)
       return;
     cond_load_resolvables(*this);
     establish ();
 
-    list_updates( kind, best_effort );
+    list_updates(*this, kind, best_effort );
 
     setExitCode(ZYPPER_EXIT_OK);
     return;
@@ -1715,7 +1723,7 @@ void Zypper::doCommand()
       return;
     }
 
-    cond_init_target ();
+    cond_init_target(*this);
     init_repos(*this);
     if (exitCode() != ZYPPER_EXIT_OK)
       return;
@@ -1762,14 +1770,14 @@ void Zypper::doCommand()
     // rug compatibility code
     // switch on non-interactive mode if no-confirm specified
     if (copts.count("no-confirm"))
-      gSettings.non_interactive = true;
+      _gopts.non_interactive = true;
 
     if (copts.count("auto-agree-with-licenses")
         || copts.count("agree-to-third-party-licenses"))
-      gSettings.license_auto_agree = true;
+      _cmdopts.license_auto_agree = true;
 
     string skind = copts.count("type")?  copts["type"].front() :
-      gSettings.is_rug_compatible? "package" : "patch";
+      globalOpts().is_rug_compatible? "package" : "patch";
     kind = string_to_kind (skind);
     if (kind == ResObject::Kind ()) {
        cerr << format(_("Unknown resolvable type: %s")) % skind << endl;
@@ -1779,20 +1787,20 @@ void Zypper::doCommand()
 
     bool best_effort = copts.count( "best-effort" ); 
 
-    if (gSettings.is_rug_compatible && best_effort) {
+    if (globalOpts().is_rug_compatible && best_effort) {
        best_effort = false;
        // 'rug' is the name of a program and must not be translated
        // 'best-effort' is a program parameter and can not be translated
        cerr << _("Running as 'rug', can't do 'best-effort' approach to update.") << endl;
     }
-    cond_init_target ();
+    cond_init_target(*this);
     init_repos(*this);
     if (exitCode() != ZYPPER_EXIT_OK)
       return;
     cond_load_resolvables(*this);
     establish ();
 
-    bool skip_interactive = copts.count("skip-interactive") || gSettings.non_interactive;
+    bool skip_interactive = copts.count("skip-interactive") || globalOpts().non_interactive;
     mark_updates( kind, skip_interactive, best_effort );
 
 
@@ -1809,11 +1817,9 @@ void Zypper::doCommand()
     // ZYPPER_EXIT_INF_REBOOT_NEEDED, or ZYPPER_EXIT_INF_RESTART_NEEDED
     else
     {
-      setExitCode(solve_and_commit());
-      return;
+      solve_and_commit(*this);
     }
 
-    setExitCode(ZYPPER_EXIT_OK);
     return; 
   }
 
@@ -1844,9 +1850,9 @@ void Zypper::doCommand()
     }
 
     if (copts.count("auto-agree-with-licenses"))
-      gSettings.license_auto_agree = true;
+      _cmdopts.license_auto_agree = true;
 
-    cond_init_target ();
+    cond_init_target(*this);
     init_repos(*this);
     if (exitCode() != ZYPPER_EXIT_OK)
       return;
@@ -1868,11 +1874,9 @@ void Zypper::doCommand()
     // ZYPPER_EXIT_INF_REBOOT_NEEDED, or ZYPPER_EXIT_INF_RESTART_NEEDED
     else
     {
-      setExitCode(solve_and_commit());
-      return;
+      solve_and_commit(*this);
     }
 
-    setExitCode(ZYPPER_EXIT_OK);
     return; 
   }
 
@@ -1897,14 +1901,14 @@ void Zypper::doCommand()
       return;
     }
 
-    cond_init_target ();
+    cond_init_target(*this);
     init_repos(*this);
     if (exitCode() != ZYPPER_EXIT_OK)
       return;
     cond_load_resolvables(*this);
     establish ();
 
-    printInfo(command(),_arguments);
+    printInfo(*this);
 
     setExitCode(ZYPPER_EXIT_OK);
     return;
index 00fb72b..387b20e 100644 (file)
@@ -4,6 +4,10 @@
 #include <string>
 #include <vector>
 
+#include "zypp/base/ReferenceCounted.h"
+#include "zypp/base/NonCopyable.h"
+#include "zypp/base/PtrTypes.h"
+
 #include "zypp/ResStore.h"
 #include "zypp/RepoInfo.h"
 #include "zypp/RepoManager.h"
@@ -24,7 +28,6 @@ struct GlobalOptions
   is_rug_compatible(false),
   non_interactive(false),
   no_gpg_checks(false),
-  license_auto_agree(false),
   machine_readable(false),
   root_dir("/")
   {}
@@ -47,27 +50,39 @@ struct GlobalOptions
   bool is_rug_compatible;
   bool non_interactive;
   bool no_gpg_checks;
-  bool license_auto_agree; // TODO move to commandOptions
   bool machine_readable;
   std::string root_dir;
   zypp::RepoManagerOptions rm_options;
 };
 
 
-class Zypper
+struct CommandOptions
 {
-public:
+  CommandOptions()
+    :
+  license_auto_agree(false)
+  {}
 
-  Zypper();
-  ~Zypper();
+  bool license_auto_agree;
+};
+
+
+DEFINE_PTR_TYPE(Zypper);
+
+class Zypper : public zypp::base::ReferenceCounted, private zypp::base::NonCopyable
+{
+public:
+  static Zypper_Ptr instance(); 
 
   int main(int argc, char ** argv);
 
   // setters & getters
   const GlobalOptions & globalOpts() const { return _gopts; }
+  const CommandOptions & cmdOpts() const { return _cmdopts; }
   const parsed_opts & cOpts() const { return _copts; }
   const ZypperCommand & command() const { return _command; }
   const std::string & commandHelp() const { return _command_help; }
+  const std::vector<std::string> & arguments() const { return _arguments; }
   int exitCode() const { return _exit_code; }
   void setExitCode(int exit) { _exit_code = exit; } 
   bool runningShell() const { return _running_shell; }
@@ -77,6 +92,9 @@ public:
   char ** argv() { return _running_shell ? _sh_argv : _argv; } 
 
 private:
+  Zypper();
+  ~Zypper();
+
   void processGlobalOptions();
   void processCommandOptions();
   void commandShell();
@@ -93,6 +111,7 @@ private:
   char ** _argv;
 
   GlobalOptions _gopts;
+  CommandOptions _cmdopts;
   parsed_opts   _copts;
   ZypperCommand _command;
   std::vector<std::string> _arguments;
@@ -104,9 +123,9 @@ private:
 
   int _sh_argc;
   char **_sh_argv;
-
 };
 
+
 struct RuntimeData
 {
   RuntimeData()
@@ -126,7 +145,6 @@ struct RuntimeData
 };
 
 extern RuntimeData gData;
-extern GlobalOptions gSettings;
 extern std::ostream no_stream;
 
 #endif /*ZYPPER_H*/