backup
authorMichael Andres <ma@suse.de>
Fri, 14 Sep 2007 15:30:23 +0000 (15:30 +0000)
committerMichael Andres <ma@suse.de>
Fri, 14 Sep 2007 15:30:23 +0000 (15:30 +0000)
devel/devel.ma/CMakeLists.txt
devel/devel.ma/Ex.cc
devel/devel.ma/Parse.cc
devel/devel.ma/Tools.h

index f3ad32c..8e2ada0 100644 (file)
@@ -29,7 +29,7 @@ ADD_CUSTOM_TARGET( ma_test
 
 ## ############################################################
 
-FOREACH( loop_var ScanSource Iorder Xml Main FakePool AOUT Parse Test Basic)
+FOREACH( loop_var ScanSource Iorder Xml Ex Main FakePool AOUT Parse Test Basic)
    ADD_EXECUTABLE( ${loop_var}
       ${loop_var}.cc
    )
index 50b69a4..2a1f8f0 100644 (file)
-#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
@@ -172,17 +93,77 @@ void lparse( const Pathname & repodata_r )
 */
 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;
 }
-
index 803ce0d..08f3852 100644 (file)
@@ -20,6 +20,7 @@
 #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"
 
@@ -34,6 +35,8 @@
 #include "zypp/RepoManager.h"
 #include "zypp/RepoInfo.h"
 
+#include "zypp/repo/PackageProvider.h"
+
 #include "zypp/ui/PatchContents.h"
 #include "zypp/ResPoolProxy.h"
 
@@ -48,11 +51,15 @@ using zypp::parser::TagParser;
 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;
 }
 
@@ -70,12 +77,15 @@ ManagedFile repoProvidePackage( const PoolItem & pi )
 
   // 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>
@@ -91,28 +101,38 @@ Selectable::Ptr getSel( const std::string & name_r )
 }
 
 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 );
 }
@@ -137,7 +157,7 @@ void dbgDu( Selectable::Ptr sel )
 }
 
 ///////////////////////////////////////////////////////////////////
-RepoProvidePackage repoProvidePackage( access, pool_r);
+
 struct Xprint
 {
   bool operator()( const PoolItem & obj_r )
@@ -537,9 +557,15 @@ int main( int argc, char * argv[] )
 
   //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;
index 787ff1f..e5ca4b8 100644 (file)
@@ -109,56 +109,10 @@ inline RepoManager makeRepoManager( const Pathname & mgrdir_r )
   RepoManagerOptions mgropt;
   mgropt.repoCachePath    = mgrdir_r/"cache";
   mgropt.repoRawCachePath = mgrdir_r/"raw_cache";
-  mgropt.knownReposPath   = mgrdir_r/"repos";
+  mgropt.knownReposPath   = mgrdir_r;
 
   return RepoManager( mgropt );
 }
 
 ///////////////////////////////////////////////////////////////////
-
-inline Repository createSource( const Url & url_r, const std::string & alias_r = std::string() )
-{
-  Repository ret;
-#if 0
-  Measure x( "createSource: " + url_r.asString() );
-  try
-    {
-      std::string alias( alias_r.empty() ? Date::now().asSeconds() : alias_r );
-      try
-        {
-          ret = SourceFactory().createFrom( url_r, "/", alias );
-        }
-      catch ( const source::SourceUnknownTypeException & )
-        {
-          ret = SourceFactory().createFrom( "Plaindir", url_r, "/", alias, "", false, true );
-        }
-    }
-  catch ( const Exception & )
-    {
-      return Repository::noSource;
-    }
-  x.start( "parseSource: " + url_r.asString() );
-  {
-    //zypp::base::LogControl::TmpLineWriter shutUp;
-    ret.resolvables();
-  }
-  x.stop();
-  MIL << "Content " << ret << "{" << endl;
-  rstats( ret.resolvables() );
-  MIL << "}" << endl;
-#endif
-  return ret;
-}
-inline Repository createSource( const std::string & url_r, const std::string & alias_r = std::string() )
-{
-  try
-    {
-      return createSource( Url(url_r), alias_r );
-    }
-  catch ( const Exception & )
-    {
-      return Repository::noRepository;
-    }
-}
-
 #endif // Tools_h