ref: refs/heads/ma-misc
commit 2e8b05e2e6072fac084035b2d7b233fcee92a1c5
Author: Michael Andres
Date: Thu Jul 23 00:31:41 2009 +0200
New misc::defaultLoadSystem convenience to create the ZYpp instance and load target and enabled repositories.
---
package/libzypp.changes | 6 +++
zypp/CMakeLists.txt | 2 +
zypp/Misc.cc | 111 +++++++++++++++++++++++++++++++++++++++++++++++
zypp/Misc.h | 63 ++++++++++++++++++++++++++
4 files changed, 182 insertions(+), 0 deletions(-)
diff --git a/package/libzypp.changes b/package/libzypp.changes
index f5bbea6..b6aac07 100644
--- a/package/libzypp.changes
+++ b/package/libzypp.changes
@@ -1,4 +1,10 @@
-------------------------------------------------------------------
+Thu Jul 23 00:22:50 CEST 2009 - ma@km13.de
+
+- New misc::defaultLoadSystem: Convenience to create the ZYpp instance
+ and load target and enabled repositories.
+
+-------------------------------------------------------------------
Wed Jul 22 14:57:32 CEST 2009 - ma@suse.de
- New class InstanceId to build strings to identify/retrieve specific
diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt
index 07d12ef..846e3cb 100644
--- a/zypp/CMakeLists.txt
+++ b/zypp/CMakeLists.txt
@@ -32,6 +32,7 @@ SET( zypp_SRCS
Locks.cc
MediaProducts.cc
MediaSetAccess.cc
+ Misc.cc
NameKindProxy.cc
OnMediaLocation.cc
Package.cc
@@ -119,6 +120,7 @@ SET( zypp_HEADERS
ManagedFile.h
MediaProducts.h
MediaSetAccess.h
+ Misc.h
NameKindProxy.h
Vendor.h
OnMediaLocation.h
diff --git a/zypp/Misc.cc b/zypp/Misc.cc
new file mode 100644
index 0000000..8683f6c
--- /dev/null
+++ b/zypp/Misc.cc
@@ -0,0 +1,111 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/Misc.cc
+ *
+*/
+#include <iostream>
+
+#include "zypp/base/LogTools.h"
+#include "zypp/PathInfo.h"
+
+#include "zypp/Misc.h"
+
+#include "zypp/ZYppFactory.h"
+#include "zypp/zypp_detail/ZYppReadOnlyHack.h"
+#include "zypp/Target.h"
+#include "zypp/RepoManager.h"
+#include "zypp/sat/Pool.h"
+
+using std::endl;
+
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::misc"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace misc
+ { /////////////////////////////////////////////////////////////////
+
+ void defaultLoadSystem( const Pathname & sysRoot_r, LoadSystemFlags flags_r )
+ {
+ MIL << str::form( "*** Load system at '%s' (%lx)", sysRoot_r.c_str(), (unsigned long)flags_r ) << endl;
+
+ if ( ! PathInfo( sysRoot_r ).isDir() )
+ ZYPP_THROW( Exception(str::form("sysRoot_r argument needs to be a directory. (%s)", sysRoot_r.c_str())) );
+
+ if ( ZYppFactory::instance().haveZYpp() )
+ ZYPP_THROW( Exception("ZYpp instance is already created. (Call this method earlier.)") );
+
+ if ( flags_r.testFlag( LS_READONLY ) )
+ zypp_readonly_hack::IWantIt ();
+
+ sat::Pool satpool( sat::Pool::instance() );
+
+ if ( 1 )
+ {
+ MIL << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
+ getZYpp()->initializeTarget( sysRoot_r );
+ getZYpp()->target()->load();
+ MIL << satpool.systemRepo() << endl;
+ }
+
+ if ( 1 )
+ {
+ RepoManager repoManager( sysRoot_r );
+ RepoInfoList repos = repoManager.knownRepositories();
+ for_( it, repos.begin(), repos.end() )
+ {
+ RepoInfo & nrepo( *it );
+
+ if ( ! nrepo.enabled() )
+ continue;
+
+ if ( ! flags_r.testFlag( LS_NOREFRESH ) )
+ {
+ if ( repoManager.isCached( nrepo )
+ && ( nrepo.type() == repo::RepoType::RPMPLAINDIR // refreshes always
+ || repoManager.checkIfToRefreshMetadata( nrepo, nrepo.url() ) == RepoManager::REFRESH_NEEDED ) )
+ {
+ MIL << str::form( "*** clean cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
+ repoManager.cleanCache( nrepo );
+ MIL << str::form( "*** refresh repo '%s'\t", nrepo.name().c_str() ) << endl;
+ repoManager.refreshMetadata( nrepo );
+ }
+ }
+
+ if ( ! repoManager.isCached( nrepo ) )
+ {
+ MIL << str::form( "*** build cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
+ repoManager.buildCache( nrepo );
+ }
+
+ MIL << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << std::flush;
+ try
+ {
+ repoManager.loadFromCache( nrepo );
+ MIL << satpool.reposFind( nrepo.alias() ) << endl;
+ }
+ catch ( const Exception & exp )
+ {
+ ERR << "*** load repo failed: " << exp.asString() + "\n" + exp.historyAsString() << endl;
+ ZYPP_RETHROW ( exp );
+ }
+ }
+ }
+ MIL << str::form( "*** Read system at '%s'", sysRoot_r.c_str() ) << endl;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace misc
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/Misc.h b/zypp/Misc.h
new file mode 100644
index 0000000..d8c4c1a
--- /dev/null
+++ b/zypp/Misc.h
@@ -0,0 +1,63 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/Misc.h
+ *
+*/
+#ifndef ZYPP_MISC_H
+#define ZYPP_MISC_H
+
+#include <iosfwd>
+
+#include "zypp/Pathname.h"
+#include "zypp/base/Flags.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace misc
+ { /////////////////////////////////////////////////////////////////
+
+ /**
+ * Bits for tuning \ref defaultLoadSystem.
+ *
+ * Use \ref LoadSystemFlags as a type-safe way of
+ * storing OR-combinations.
+ */
+ enum LoadSystemFlag
+ {
+ LS_READONLY = (1 << 0), //!< // Create readonly ZYpp instance.
+ LS_NOREFRESH = (1 << 1) //!< // Don't refresh existing repos.
+ };
+
+ /** \relates LoadSystemFlag Type-safe way of storing OR-combinations. */
+ ZYPP_DECLARE_FLAGS_AND_OPERATORS( LoadSystemFlags, LoadSystemFlag );
+
+ /**
+ * Create the ZYpp instance and load target and enabled repositories.
+ *
+ * \see LoadSystemFlag for options.
+ *
+ * \throws Exception on error
+ *
+ * \todo properly handle service refreshs
+ */
+ void defaultLoadSystem( const Pathname & sysRoot_r = "/", LoadSystemFlags flags_r = LoadSystemFlags() );
+
+ /** \overload */
+ inline void defaultLoadSystem( LoadSystemFlags flags_r )
+ { defaultLoadSystem( "/", flags_r ); }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace misc
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_MISC_H
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org