Separate the tags parser in 2 files, adapt to new cache store api
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 16 Apr 2007 16:56:18 +0000 (16:56 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 16 Apr 2007 16:56:18 +0000 (16:56 +0000)
to set the catalog

devel/devel.dmacvicar/CMakeLists.txt
devel/devel.dmacvicar/CacheStore_tp.cc [moved from devel/devel.dmacvicar/CacheStore.cc with 100% similarity]
devel/devel.dmacvicar/SUSETagsParser.cc
devel/devel.dmacvicar/SUSETagsParser.h [new file with mode: 0644]
devel/devel.dmacvicar/SUSETagsParser_tp.cc [new file with mode: 0644]
devel/devel.dmacvicar/YUMDownloader.cc [deleted file]
devel/devel.dmacvicar/YUMDownloader.h [deleted file]
devel/devel.dmacvicar/YUMDownloader_tp.cc
devel/devel.dmacvicar/testbed.cc

index deeb894..fbf5e8f 100644 (file)
@@ -12,7 +12,7 @@ TARGET_LINK_LIBRARIES(scansource  zypp )
 ADD_EXECUTABLE(susetags-downloader SUSETagsDownloader_tp.cc)
 TARGET_LINK_LIBRARIES(susetags-downloader  zypp )
 
-ADD_EXECUTABLE(cachestore CacheStore.cc)
+ADD_EXECUTABLE(cachestore CacheStore_tp.cc)
 TARGET_LINK_LIBRARIES(cachestore  zypp )
 TARGET_LINK_LIBRARIES(cachestore  zypp2 )
 
@@ -20,7 +20,7 @@ ADD_EXECUTABLE(cachequery CacheQuery_test.cc)
 TARGET_LINK_LIBRARIES(cachequery  zypp )
 TARGET_LINK_LIBRARIES(cachequery  zypp2 )
 
-ADD_EXECUTABLE(tagsparser SUSETagsParser.cc)
+ADD_EXECUTABLE(tagsparser SUSETagsParser.cc SUSETagsParser_tp.cc)
 TARGET_LINK_LIBRARIES(tagsparser  zypp )
 TARGET_LINK_LIBRARIES(tagsparser  zypp2 )
 
@@ -28,7 +28,7 @@ ADD_EXECUTABLE(testbed testbed.cc)
 TARGET_LINK_LIBRARIES(testbed  zypp )
 TARGET_LINK_LIBRARIES(testbed  zypp2 )
 
-ADD_EXECUTABLE(yum-downloader YUMDownloader.cc YUMDownloader_tp.cc)
+ADD_EXECUTABLE(yum-downloader YUMDownloader_tp.cc)
 TARGET_LINK_LIBRARIES(yum-downloader  zypp )
 TARGET_LINK_LIBRARIES(yum-downloader  zypp2 )
 
index 89f4aed..00a2e71 100644 (file)
 #include "zypp/parser/taggedfile/TagCacheRetrieval.h"
 #include "zypp/parser/taggedfile/TagCacheRetrievalPtr.h"
 
+#include "SUSETagsParser.h"
+
 using namespace zypp;
 using namespace std;
 using zypp::debug::Measure;
 
-typedef Exception ParseException;
-
-struct PackageDataProvider;
-
-typedef shared_ptr<PackageDataProvider> PackageDataProviderPtr;
+namespace zypp {
 
+typedef Exception ParseException;
+  
 struct PackageDataProvider
 {
   TagRetrievalPos _attr_SUMMARY;
@@ -42,54 +42,9 @@ struct PackageDataProvider
   PackageDataProviderPtr _fallback_provider;
 };
 
-struct PackagesParser
-{
-  // tag ids for the TaggedParser
-  enum Tags {
-    PACKAGE,  // name version release arch
-    REQUIRES, // list of requires tags
-    PREREQUIRES,// list of pre-requires tags
-    PROVIDES, // list of provides tags
-    CONFLICTS,  // list of conflicts tags
-    OBSOLETES,  // list of obsoletes tags
-    RECOMMENDS, // list of recommends tags
-    SUGGESTS, // list of suggests tags
-    LOCATION, // file location
-    SIZE, // packed and unpacked size
-    BUILDTIME,  // buildtime
-    SOURCERPM,  // source package
-    GROUP,  // rpm group
-    LICENSE,  // license
-    AUTHORS,  // list of authors
-    SHAREWITH,  // package to share data with
-    KEYWORDS, // list of keywords
-
-      // packages.<locale>
-    SUMMARY,  // short summary (label)
-    DESCRIPTION,// long description
-    INSNOTIFY,  // install notification
-    DELNOTIFY,  // delete notification
-    LICENSETOCONFIRM, // license to confirm upon install
-    // packages.DU
-    DU,   // disk usage data
-    NUM_TAGS
-  };
-
-  // our parser
-  TaggedParser _parser;
-  // our set of tags, initialized in constructor
-  TaggedFile::TagSet _tagset;
-  zypp::Arch _system_arch;
-
-  typedef std::map <std::string, PackageDataProviderPtr> pkgmaptype;
-  pkgmaptype _pkgmap;
-
-  zypp::cache::CacheStore *_consumer;
-
-  std::map<std::string, data::RecordId> _idmap;
-
-  PackagesParser( zypp::cache::CacheStore *consumer )
-    : _consumer(consumer)
+
+  PackagesParser::PackagesParser( const data::RecordId &catalog_id, zypp::cache::CacheStore consumer )
+    : _consumer(consumer), _catalog_id(catalog_id)
   {
     ZYpp::Ptr z = getZYpp();
     _system_arch = z->architecture();
@@ -141,7 +96,7 @@ struct PackagesParser
     }
   }
 
-  void start( const Pathname &path )
+  void PackagesParser::start( const Pathname &path )
   {
     std::ifstream content_stream((path + "/content").asString().c_str());
     std::string buffer;
@@ -325,7 +280,7 @@ struct PackagesParser
     } // locales iterator
   }
 
-  void fromCache ( TagCacheRetrieval_Ptr pkgcache)
+  void PackagesParser::fromCache ( TagCacheRetrieval_Ptr pkgcache)
   {
     //---------------------------------------------------------------
     // PACKAGE
@@ -369,10 +324,10 @@ struct PackagesParser
     
     NVRA nvra( splitted[0], Edition( splitted[1], splitted[2] ), Arch(arch) );
     
-     // DEPENDENCIES
+    // DEPENDENCIES
     #define GET_TAG(tagname) \
     _tagset.getTagByIndex (tagname)
-     
+    
     data::Dependencies deps;
     
     std::list<std::string> pkglist;
@@ -391,11 +346,11 @@ struct PackagesParser
     //COLLECT_DEPS(SUPPLEMENTS);
     COLLECT_DEPS(RECOMMENDS);
 
-    data::RecordId pkgid = _consumer->appendResolvable( ResTraits<Package>::kind, nvra, deps );
+    data::RecordId pkgid = _consumer.appendResolvable( _catalog_id, ResTraits<Package>::kind, nvra, deps );
     _idmap[single] = pkgid;
   }
 
-  void collectDeps( zypp::Dep deptype, const std::list<std::string> &depstrlist, data::Dependencies &deps )
+  void PackagesParser::collectDeps( zypp::Dep deptype, const std::list<std::string> &depstrlist, data::Dependencies &deps )
   {
     for ( list<string>::const_iterator it = depstrlist.begin(); it != depstrlist.end(); ++it )
     {
@@ -407,12 +362,12 @@ struct PackagesParser
     }
   }
   
-  void fromPathLocale (const Pathname& path)
+  void PackagesParser::fromPathLocale (const Pathname& path)
   {
     
   }
 
-  void fromLocale ()
+  void PackagesParser::fromLocale ()
   {
     //---------------------------------------------------------------
     // PACKAGE.<locale>
@@ -465,25 +420,5 @@ struct PackagesParser
 #undef SET_CACHE
   }
 
-};
-
-int main(int argc, char **argv)
-{
-    try
-    {
-      ZYpp::Ptr z = getZYpp();
-      Pathname dbfile = Pathname(getenv("PWD")) + "data.db";
-      zypp::cache::CacheStore store(getenv("PWD"));
-
-      PackagesParser parser(&store);
-      Measure m;
-      parser.start(argv[1]);
-      m.elapsed();
-    }
-    catch ( const Exception &e )
-    {
-      cout << "ups! " << e.msg() << std::endl;
-    }
-    return 0;
-}
 
+} // ns zypp
diff --git a/devel/devel.dmacvicar/SUSETagsParser.h b/devel/devel.dmacvicar/SUSETagsParser.h
new file mode 100644 (file)
index 0000000..8a71b79
--- /dev/null
@@ -0,0 +1,82 @@
+
+#ifndef ZYPP_SOURCE_SUSETAGSPARSER_H
+#define ZYPP_SOURCE_SUSETAGSPARSER_H
+// #include <list>
+// #include <string>
+// #include <fstream>
+#include "zypp/base/PtrTypes.h"
+// #include "zypp/base/Measure.h"
+// #include "zypp/Arch.h"
+// #include "zypp/ZYppFactory.h"
+// #include "zypp/ZYpp.h"
+// #include "zypp/capability/CapabilityImpl.h"
+#include "zypp2/cache/CacheStore.h"
+#include "zypp/data/ResolvableData.h"
+#include "zypp/parser/taggedfile/TaggedParser.h"
+#include "zypp/parser/taggedfile/TaggedFile.h"
+#include "zypp/parser/taggedfile/TagCacheRetrieval.h"
+#include "zypp/parser/taggedfile/TagCacheRetrievalPtr.h"
+
+namespace zypp
+{
+  struct PackageDataProvider;
+  typedef zypp::shared_ptr<PackageDataProvider> PackageDataProviderPtr;
+  struct PackageDataProvider;
+  
+  struct PackagesParser
+  {
+    // tag ids for the TaggedParser
+    enum Tags {
+      PACKAGE,  // name version release arch
+      REQUIRES, // list of requires tags
+      PREREQUIRES,// list of pre-requires tags
+      PROVIDES, // list of provides tags
+      CONFLICTS,  // list of conflicts tags
+      OBSOLETES,  // list of obsoletes tags
+      RECOMMENDS, // list of recommends tags
+      SUGGESTS, // list of suggests tags
+      LOCATION, // file location
+      SIZE, // packed and unpacked size
+      BUILDTIME,  // buildtime
+      SOURCERPM,  // source package
+      GROUP,  // rpm group
+      LICENSE,  // license
+      AUTHORS,  // list of authors
+      SHAREWITH,  // package to share data with
+      KEYWORDS, // list of keywords
+  
+        // packages.<locale>
+      SUMMARY,  // short summary (label)
+      DESCRIPTION,// long description
+      INSNOTIFY,  // install notification
+      DELNOTIFY,  // delete notification
+      LICENSETOCONFIRM, // license to confirm upon install
+      // packages.DU
+      DU,   // disk usage data
+      NUM_TAGS
+    };
+  
+    PackagesParser( const data::RecordId &catalog_id, zypp::cache::CacheStore consumer );
+    void start( const zypp::Pathname &path );
+    void fromCache ( TagCacheRetrieval_Ptr pkgcache);
+    void collectDeps( zypp::Dep deptype, const std::list<std::string> &depstrlist, data::Dependencies &deps );
+    void fromPathLocale (const zypp::Pathname& path);
+    void fromLocale ();
+    
+  private:
+    // our parser
+    TaggedParser _parser;
+    // our set of tags, initialized in constructor
+    TaggedFile::TagSet _tagset;
+    zypp::Arch _system_arch;
+    typedef std::map <std::string, PackageDataProviderPtr> pkgmaptype;
+    pkgmaptype _pkgmap;
+    zypp::cache::CacheStore _consumer;
+    std::map<std::string, data::RecordId> _idmap;
+    data::RecordId _catalog_id;
+  };
+}
+
+#endif
+
+
diff --git a/devel/devel.dmacvicar/SUSETagsParser_tp.cc b/devel/devel.dmacvicar/SUSETagsParser_tp.cc
new file mode 100644 (file)
index 0000000..3dc8a94
--- /dev/null
@@ -0,0 +1,33 @@
+
+#include <iostream>
+#include "zypp/base/Measure.h"
+#include "zypp/base/Logger.h"
+#include "zypp/ZYppFactory.h"
+#include "zypp/ZYpp.h"
+
+#include "SUSETagsParser.h"
+
+using namespace std;
+using namespace zypp;
+using namespace zypp::debug;
+
+int main(int argc, char **argv)
+{
+    try
+    {
+      ZYpp::Ptr z = getZYpp();
+      Pathname dbfile = Pathname(getenv("PWD")) + "data.db";
+      zypp::cache::CacheStore store(getenv("PWD"));
+      data::RecordId catalog_id = store.lookupOrAppendCatalog( Url(argv[1]), "/");
+      PackagesParser parser( catalog_id, store);
+      Measure m;
+      parser.start(argv[1]);
+      m.elapsed();
+    }
+    catch ( const Exception &e )
+    {
+      cout << "ups! " << e.msg() << std::endl;
+    }
+    return 0;
+}
+
diff --git a/devel/devel.dmacvicar/YUMDownloader.cc b/devel/devel.dmacvicar/YUMDownloader.cc
deleted file mode 100644 (file)
index 884800f..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-
-#include <fstream>
-#include "zypp/base/String.h"
-#include "zypp/base/Logger.h"
-#include "zypp/base/Function.h"
-
-#include "zypp/Date.h"
-
-#include "zypp/parser/yum/RepomdFileReader.h"
-#include "zypp/parser/yum/PatchesFileReader.h"
-#include "YUMDownloader.h"
-
-using namespace std;
-using namespace zypp::xml;
-
-namespace zypp
-{
-namespace source
-{
-namespace yum
-{
-
-YUMDownloader::YUMDownloader( const Url &url, const Pathname &path )
-  : _url(url), _path(path), _media(url, path)
-{
-}
-
-bool YUMDownloader::patches_Callback( const OnMediaLocation &loc, const string &id )
-{
-  MIL << id << " : " << loc << endl;
-  _fetcher.enqueue(loc);
-  return true;
-}
-
-
-bool YUMDownloader::repomd_Callback( const OnMediaLocation &loc, const string &dtype )
-{
-  MIL << dtype << " : " << loc << endl;
-  _fetcher.enqueue(loc);
-  
-  // We got a patches file we need to read, to add patches listed
-  // there, so we transfer what we have in the queue, and 
-  // queue the patches in the patches callback
-  if ( dtype == "patches" )
-  {
-    _fetcher.start( _dest_dir, _media);
-    // now the patches.xml file must exists
-    PatchesFileReader( _dest_dir + loc.filename(), bind( &YUMDownloader::patches_Callback, this, _1, _2));
-  }
-  return true;
-}
-
-void YUMDownloader::download( const Pathname &dest_dir )
-{
-  _dest_dir = dest_dir;
-  _fetcher.enqueue( OnMediaLocation().filename("/repodata/repomd.xml") );
-  _fetcher.start( dest_dir, _media);
-  _fetcher.reset();
-
-  Reader reader( dest_dir + "/repodata/repomd.xml" );
-  RepomdFileReader( dest_dir + "/repodata/repomd.xml", bind( &YUMDownloader::repomd_Callback, this, _1, _2));
-
-  // ready, go!
-  _fetcher.start( dest_dir, _media);
-}
-
-}// ns yum
-}// ns source 
-} // ns zypp
-
-
diff --git a/devel/devel.dmacvicar/YUMDownloader.h b/devel/devel.dmacvicar/YUMDownloader.h
deleted file mode 100644 (file)
index 37f196b..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-
-#ifndef ZYPP_SOURCE_YUM_DOWNLOADER
-#define ZYPP_SOURCE_YUM_DOWNLOADER
-
-#include "zypp/Url.h"
-#include "zypp/Pathname.h"
-#include "zypp/Fetcher.h"
-#include "zypp/OnMediaLocation.h"
-#include "zypp/MediaSetAccess.h"
-#include "zypp/parser/xml/Reader.h"
-
-namespace zypp
-{
-  namespace source
-  {
-    namespace yum
-    {
-      /**
-      * This class allows to retrieve a YUM repository
-      * to a local directory
-      *
-      * \code
-      * YUMDownloader yum(url, path);
-      * yum.download("localdir");
-      * \endcode
-      */
-      class YUMDownloader
-      {
-       public:
-       /**
-        * Create the download object for a repository
-        * located in \a url with path \a path
-        */
-        YUMDownloader( const Url &url, const Pathname &path );
-       /**
-        * starts the download to local directory \a dest_dir
-        */
-        void download( const Pathname &dest_dir );
-        
-       protected:
-        bool repomd_Callback( const OnMediaLocation &loc, const std::string &dtype );
-        bool patches_Callback( const OnMediaLocation &loc, const std::string &id );
-       private:
-        Url _url;
-        Pathname _path;
-        Fetcher _fetcher;
-        Pathname _dest_dir;
-        std::list<OnMediaLocation> _patches_files;
-        MediaSetAccess _media;
-      };
-
-    } // ns yum
-  } // ns source
-} // ns zypp
-
-#endif
index 719a8ca..76f698b 100644 (file)
@@ -6,17 +6,17 @@
 #include <list>
 #include <set>
 
-#include <zypp/base/Logger.h>
-#include <zypp/base/String.h>
-#include <zypp/ZYpp.h>
-#include <zypp/ZYppFactory.h>
-#include <zypp/media/MediaAccess.h>
-#include <zypp/media/MediaManager.h>
-#include <zypp/MediaSetAccess.h>
-#include <zypp/source/SUSEMediaVerifier.h>
-#include <zypp/OnMediaLocation.h>
-#include <YUMDownloader.h>
-#include <zypp/Fetcher.h>
+#include "zypp/base/Logger.h"
+#include "zypp/base/String.h"
+#include "zypp/ZYpp.h"
+#include "zypp/ZYppFactory.h"
+#include "zypp/media/MediaAccess.h"
+#include "zypp/media/MediaManager.h"
+#include "zypp/MediaSetAccess.h"
+#include "zypp/source/SUSEMediaVerifier.h"
+#include "zypp/OnMediaLocation.h"
+#include "zypp/source/yum/YUMDownloader.h"
+#include "zypp/Fetcher.h"
 
 #include "zypp/Product.h"
 #include "zypp/Package.h"
index 4c8df9a..a546814 100644 (file)
@@ -10,7 +10,7 @@
 #include "zypp/Product.h"
 #include "zypp/detail/PackageImplIf.h"
 #include "zypp/Package.h"
-
+#include "zypp/SourceFactory.h"
 #include "zypp2/source/cached/CachedSourceImpl.h"
 #include "zypp/data/ResolvableData.h"
 
@@ -28,8 +28,12 @@ int main(int argc, char **argv)
     
       Pathname dbpath = Pathname(getenv("PWD"));
       
-      CachedSourceImpl source(dbpath);
-      //ResStore dbres = src.resolvables();
+      SourceImpl_Ptr sourceImpl(new CachedSourceImpl(dbpath));
+      SourceFactory factory;
+      Source_Ref source = factory.createFrom(sourceImpl);
+      ResStore dbres = source.resolvables();
+      
+      MIL << dbres.size() << " resolvables" << endl;
 
     }
     catch ( const Exception &e )