draft defaultLoadSystem method
authorMichael Andres <ma@suse.de>
Thu, 20 Dec 2012 11:35:26 +0000 (12:35 +0100)
committerMichael Andres <ma@suse.de>
Thu, 20 Dec 2012 11:36:40 +0000 (12:36 +0100)
src/Zypper.cc
src/Zypper.h

index fc80b4c..4c9af93 100644 (file)
 #include <zypp/ZYppFactory.h>
 #include <zypp/zypp_detail/ZYppReadOnlyHack.h>
 
-#include <zypp/base/Logger.h>
+#include <zypp/base/LogTools.h>
 #include <zypp/base/Algorithm.h>
 #include <zypp/base/UserRequestException.h>
+#include <zypp/base/DtorReset.h>
 
 #include <zypp/sat/SolvAttr.h>
 #include <zypp/PoolQuery.h>
@@ -310,6 +311,41 @@ void print_command_help_hint(Zypper & zypper)
       % (zypper.runningShell() ? "help <command>" : "zypper help <command>")));
 }
 
+int Zypper::defaultLoadSystem( LoadSystemFlags flags_r )
+{
+  DBG << "FLAGS:" << flags_r << endl;
+  if ( ! flags_r.testFlag( NO_POOL ) )
+  {
+    init_target( *this );
+    if ( exitCode() != ZYPPER_EXIT_OK )
+      return exitCode();
+
+    if ( ! flags_r.testFlag( NO_REPOS ) )
+    {
+      init_repos(*this);
+      if ( exitCode() != ZYPPER_EXIT_OK )
+       return exitCode();
+    }
+
+    DtorReset _tmp( _gopts.disable_system_resolvables );
+    if ( flags_r.testFlag( NO_TARGET ) )
+    {
+      _gopts.disable_system_resolvables = true;
+    }
+    load_resolvables( *this );
+    if ( exitCode() != ZYPPER_EXIT_OK )
+      return exitCode();
+
+    if ( ! ( flags_r && NO_POOL ) )
+    {
+      // have REPOS and TARGET
+      // compute status of PPP
+      resolve(*this);
+    }
+  }
+  return exitCode();
+}
+
 /*
  * parses global options, returns the command
  *
index 0a2af97..aef000f 100644 (file)
@@ -14,6 +14,7 @@
 #include <zypp/base/Exception.h>
 #include <zypp/base/NonCopyable.h>
 #include <zypp/base/PtrTypes.h>
+#include <zypp/base/Flags.h>
 #include <zypp/TriBool.h>
 
 #include <zypp/RepoInfo.h>
@@ -220,6 +221,22 @@ public:
   void cleanup();
 
 public:
+   /** Flags for tuning \ref defaultLoadSystem. */
+  enum _LoadSystemFlags
+  {
+    NO_TARGET          = (1 << 0),             //< don't load target to pool
+    NO_REPOS           = (1 << 1),             //< don't load repos to pool
+    NO_POOL            = NO_TARGET | NO_REPOS  //< no pool at all
+  };
+  ZYPP_DECLARE_FLAGS( LoadSystemFlags, _LoadSystemFlags );
+
+  /** Prepare repos and pool according to \a flags_r.
+   * Defaults to load target and repos and in this case also adjusts
+   * the PPP status by doing an initial solver run.
+   */
+  int defaultLoadSystem( LoadSystemFlags flags_r = LoadSystemFlags() );
+
+public:
   /** Convenience to return properly casted _commandOptions. */
   template<class _Opt>
   shared_ptr<_Opt> commandOptionsAs() const
@@ -283,6 +300,9 @@ private:
   shared_ptr<Options>  _commandOptions;
 };
 
+/** \relates Zypper::LoadSystemFlags */
+ZYPP_DECLARE_OPERATORS_FOR_FLAGS( Zypper::LoadSystemFlags );
+
 void print_main_help(const Zypper & zypper);
 void print_unknown_command_hint(Zypper & zypper);
 void print_command_help_hint(Zypper & zypper);