-#include <libxml/xmlreader.h>
+#include "Tools.h"
-#include <iostream>
-
-#include <zypp/base/LogControl.h>
+#include <zypp/base/PtrTypes.h>
+#include <zypp/base/Exception.h>
#include <zypp/base/LogTools.h>
-#include <zypp/base/Function.h>
-#include <zypp/base/GzStream.h>
-#include <zypp/parser/yum/YUMParser.h>
-#include <zypp/Pathname.h>
+#include <zypp/base/ProvideNumericId.h>
+#include <zypp/AutoDispose.h>
+
+#include "zypp/ZYppFactory.h"
+#include "zypp/ResPoolProxy.h"
+#include <zypp/CapMatchHelper.h>
+
+#include "zypp/ZYppCallbacks.h"
+#include "zypp/NVRAD.h"
+#include "zypp/ResPool.h"
+#include "zypp/ResFilters.h"
+#include "zypp/CapFilters.h"
+#include "zypp/Package.h"
+#include "zypp/Pattern.h"
+#include "zypp/Language.h"
+#include "zypp/Digest.h"
+#include "zypp/PackageKeyword.h"
+#include "zypp/NameKindProxy.h"
+#include "zypp/pool/GetResolvablesToInsDel.h"
+
+#include "zypp/parser/TagParser.h"
+#include "zypp/parser/susetags/PackagesFileReader.h"
+#include "zypp/parser/susetags/PackagesLangFileReader.h"
+#include "zypp/parser/susetags/PatternFileReader.h"
+#include "zypp/parser/susetags/ContentFileReader.h"
+#include "zypp/parser/susetags/RepoIndex.h"
+#include "zypp/parser/susetags/RepoParser.h"
+#include "zypp/cache/CacheStore.h"
+#include "zypp/RepoManager.h"
+#include "zypp/RepoInfo.h"
+
+#include "zypp/ui/PatchContents.h"
+#include "zypp/ResPoolProxy.h"
using namespace std;
using namespace zypp;
-using namespace zypp::parser::yum;
-
-#include "zypp/parser/yum/YUMParser.h"
+using namespace zypp::functor;
+using namespace zypp::ui;
+using zypp::parser::TagParser;
///////////////////////////////////////////////////////////////////
-template<class _Cl>
- void ti( const _Cl & c )
- {
- SEC << __PRETTY_FUNCTION << endl;
- }
+static const Pathname sysRoot( "/Local/GTEST" );
+
///////////////////////////////////////////////////////////////////
-template<class _Parser>
- bool consume( const typename _Parser::value_type & node_r )
+struct Xprint
+{
+ bool operator()( const PoolItem & obj_r )
{
- //DBG << node_r << endl;
+// handle( asKind<Package>( obj_r ) );
+// handle( asKind<Patch>( obj_r ) );
+// handle( asKind<Pattern>( obj_r ) );
+// handle( asKind<Product>( obj_r ) );
return true;
}
-template<class _Parser>
- void parseXmlFile( const Pathname & file_r,
- function<bool(const typename _Parser::value_type &)> consume_r
- = consume<_Parser> )
+ void handle( const Package_constPtr & p )
{
- Measure x( " zparse "+file_r.asString() );
- ifgzstream istr( file_r.asString().c_str() );
- if ( ! istr )
- {
- ZYPP_THROW( Exception( "Bad stream" ) );
- }
+ if ( !p )
+ return;
+ }
- for( _Parser parser( istr, "" ); ! parser.atEnd(); ++parser )
- {
- if ( consume_r && ! consume_r( *parser ) )
- {
- DBG << "abort parseXmlFile " << file_r << endl;
- return;
- }
- }
+ void handle( const Patch_constPtr & p )
+ {
+ if ( !p )
+ return;
}
-bool consumeRepomd( const YUMRepomdParser::value_type & node_r )
-{
- DBG << node_r << endl;
- return true;
-}
+ void handle( const Pattern_constPtr & p )
+ {
+ if ( !p )
+ return;
+ }
-void zparse( const Pathname & repodata_r )
-{
- Measure x( "ZPARSE" );
- parseXmlFile<YUMRepomdParser> ( repodata_r / "repomd.xml", consumeRepomd );
- parseXmlFile<YUMPrimaryParser> ( repodata_r / "primary.xml" );
- parseXmlFile<YUMOtherParser> ( repodata_r / "other.xml" );
- parseXmlFile<YUMFileListParser>( repodata_r / "filelists.xml" );
- //parseXmlFile<YUMPatchesParser> ( repodata_r / "patches.xml" );
-}
+ void handle( const Product_constPtr & p )
+ {
+ if ( !p )
+ return;
+ }
+};
///////////////////////////////////////////////////////////////////
-
-/**
- * processNode:
- * @reader: the xmlReader
- *
- * Dump information about the current node
- */
-static void
-processNode(xmlTextReaderPtr reader) {
- const xmlChar *name, *value;
-
- name = xmlTextReaderConstName(reader);
- if (name == NULL)
- name = BAD_CAST "--";
-
- value = xmlTextReaderConstValue(reader);
- string t;
- if ( value )
- {
- t = (const char *)value;
- }
- return;
- printf("%d %d %s %d %d",
- xmlTextReaderDepth(reader),
- xmlTextReaderNodeType(reader),
- name,
- xmlTextReaderIsEmptyElement(reader),
- xmlTextReaderHasValue(reader));
- if (value == NULL)
- printf("\n");
- else {
- if (xmlStrlen(value) > 40)
- printf(" %.40s...\n", value);
- else
- printf(" %s\n", value);
- }
-}
-
-
-/**
- * streamFile:
- * @filename: the file name to parse
- *
- * Parse and print information about an XML file.
- */
-//template<class _Parser>
-static void
-streamFile(const char *filename) {
- Measure x( string(" lparse ")+filename );
- xmlTextReaderPtr reader;
- int ret;
-
- reader = xmlReaderForFile(filename, NULL, 0);
- if (reader != NULL) {
- ret = xmlTextReaderRead(reader);
- while (ret == 1) {
- processNode(reader);
- ret = xmlTextReaderRead(reader);
- }
- xmlFreeTextReader(reader);
- if (ret != 0) {
- ZYPP_THROW( Exception( string("Failed to parse ") + filename ) );
- }
- } else {
- ZYPP_THROW( Exception( string("Unable to open ") + filename ) );
- }
-}
-
-void lparse( const Pathname & repodata_r )
-{
- Measure x( "LPARSE" );
- /*
- * this initialize the library and check potential ABI mismatches
- * between the version it was compiled for and the actual shared
- * library used.
- */
- LIBXML_TEST_VERSION
-
- streamFile( (repodata_r / "repomd.xml").asString().c_str() );
- streamFile( (repodata_r / "primary.xml").asString().c_str() );
- streamFile( (repodata_r / "other.xml").asString().c_str() );
- streamFile( (repodata_r / "filelists.xml").asString().c_str() );
- //streamFile( (repodata_r / "patches.xml").asString().c_str() );
-
- /*
- * Cleanup function for the XML library.
- */
- xmlCleanupParser();
-
- /*
- * this is to debug memory for regression tests
- */
- xmlMemoryDump();
-}
-
/******************************************************************
**
** FUNCTION NAME : main
*/
int main( int argc, char * argv[] )
{
+ //zypp::base::LogControl::instance().logfile( "log.restrict" );
INT << "===[START]==========================================" << endl;
- ti( YUMRepomdParser() );
- ti( YUMRepomdParser::value_type() );
- return 0;
- Pathname repodata( "/Local/PATCHES/repodata" );
- repodata = "/Local/FACTORY/repodata";
- lparse( repodata );
- zparse( repodata );
+ setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
+
+ RepoManager repoManager( makeRepoManager( sysRoot ) );
+ RepoInfoList repos = repoManager.knownRepositories();
+ SEC << "knownRepositories " << repos << endl;
+
+ if ( repos.empty() )
+ {
+ RepoInfo nrepo;
+ nrepo
+ .setAlias( "factorytest" )
+ .setName( "Test Repo for factory." )
+ .setEnabled( true )
+ .setAutorefresh( false )
+ .addBaseUrl( Url("http://dist.suse.de/install/stable-x86/") );
+
+ repoManager.addRepository( nrepo );
+ repos = repoManager.knownRepositories();
+ }
+
+ for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
+ {
+ RepoInfo & nrepo( *it );
+ if ( ! nrepo.enabled() )
+ continue;
+
+ SEC << "refreshMetadata" << endl;
+ repoManager.refreshMetadata( nrepo );
+ if ( ! repoManager.isCached( nrepo ) || 0 )
+ {
+ if ( repoManager.isCached( nrepo ) )
+ {
+ SEC << "cleanCache" << endl;
+ repoManager.cleanCache( nrepo );
+ }
+ SEC << "refreshMetadata" << endl;
+ repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
+ SEC << "buildCache" << endl;
+ repoManager.buildCache( nrepo );
+ }
+
+ SEC << nrepo << endl;
+ Repository nrep( repoManager.createFromCache( nrepo ) );
+ const zypp::ResStore & store( nrep.resolvables() );
+ dumpPoolStats( SEC << "Store: " << endl,
+ store.begin(), store.end() ) << endl;
+ getZYpp()->addResolvables( store );
+ }
+
+ ResPool pool( getZYpp()->pool() );
+ vdumpPoolStats( USR << "Initial pool:" << endl,
+ pool.begin(),
+ pool.end() ) << endl;
+
+ if ( 0 )
+ {
+ {
+ //zypp::base::LogControl::TmpLineWriter shutUp;
+ getZYpp()->initTarget( sysRoot );
+ }
+ MIL << "Added target: " << pool << endl;
+ }
+
+ std::for_each( pool.begin(), pool.end(), Xprint() );
+
+ ///////////////////////////////////////////////////////////////////
INT << "===[END]============================================" << endl << endl;
+ zypp::base::LogControl::instance().logNothing();
return 0;
}
-
#include "zypp/Language.h"
#include "zypp/Digest.h"
#include "zypp/PackageKeyword.h"
+#include "zypp/ManagedFile.h"
#include "zypp/NameKindProxy.h"
#include "zypp/pool/GetResolvablesToInsDel.h"
#include "zypp/RepoManager.h"
#include "zypp/RepoInfo.h"
+#include "zypp/repo/PackageProvider.h"
+
#include "zypp/ui/PatchContents.h"
#include "zypp/ResPoolProxy.h"
static const Pathname sysRoot( "/Local/ROOT" );
///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
bool queryInstalledEditionHelper( const std::string & name_r,
const Edition & ed_r,
- const Arch & arch_r ) const
+ const Arch & arch_r )
{
- INT << name_r << "-" << ed_r <<< "." < arch_r << endl;
+ INT << name_r << "-" << ed_r << "." << arch_r << endl;
return false;
}
// Build a repository list for repos
// contributing to the pool
- std::list<Repository> repos( _pool.knownRepositoriesBegin(), _pool.knownRepositoriesEnd() );
- repo::DeltaCandidates deltas(repos);
+ repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
+ _pool.knownRepositoriesEnd() ) );
repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
return pkgProvider.providePackage();
}
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
template<class _Res>
}
template<class _Res>
-Selectable::Ptr getPi( const std::string & name_r, const Edition & ed_r, const Arch & arch_r )
+PoolItem getPi( const std::string & name_r, const Edition & ed_r, const Arch & arch_r )
{
- ResPoolProxy uipool( getZYpp()->poolProxy() );
- for_(it, uipool.byKindBegin<_Res>(), uipool.byKindEnd<_Res>() )
+ PoolItem ret;
+ ResPool pool( getZYpp()->pool() );
+ for_(it, pool.byNameBegin(name_r), pool.byNameEnd(name_r) )
{
- if ( (*it)->name() == name_r )
- return (*it);
+ if ( !ret && isKind<_Res>( (*it).resolvable() )
+ && ( ed_r == Edition() || ed_r == (*it)->edition() )
+ && ( arch_r == Arch() || arch_r == (*it)->arch() ) )
+ {
+ ret = (*it);
+ MIL << " ->" << *it << endl;
+ }
+ else
+ {
+ DBG << " ?" << *it << endl;
+ }
}
- return 0;
+ return ret;
}
template<class _Res>
-Selectable::Ptr getPi( const std::string & name_r, const Edition & ed_r )
+PoolItem getPi( const std::string & name_r )
{
return getPi<_Res>( name_r, Edition(), Arch() );
}
template<class _Res>
-Selectable::Ptr getPi( const std::string & name_r, const Edition & ed_r )
+PoolItem getPi( const std::string & name_r, const Edition & ed_r )
{
return getPi<_Res>( name_r, ed_r, Arch() );
}
template<class _Res>
-Selectable::Ptr getPi( const std::string & name_r, const Arch & arch_r )
+PoolItem getPi( const std::string & name_r, const Arch & arch_r )
{
return getPi<_Res>( name_r, Edition(), arch_r );
}
}
///////////////////////////////////////////////////////////////////
-RepoProvidePackage repoProvidePackage( access, pool_r);
+
struct Xprint
{
bool operator()( const PoolItem & obj_r )
//std::for_each( pool.begin(), pool.end(), Xprint() );
- PoolItem pi(
+ repo::DeltaCandidates deltas( repo::makeDeltaCandidates( pool.knownRepositoriesBegin(),
+ pool.knownRepositoriesEnd() ) );
+
+ DBG << "patch: " << deltas.patchRpms(0).size() << " " << deltas.patchRpms(0) << endl;
+ DBG << "delta: " << deltas.deltaRpms(0).size() << " " << deltas.deltaRpms(0) << endl;
+
- ManagedFile
+ PoolItem pi( getPi<Package>( "kernel-default" ) );
+ USR << pi << endl;
///////////////////////////////////////////////////////////////////
INT << "===[END]============================================" << endl << endl;