Mailinglist Archive: zypp-commit (149 mails)

< Previous Next >
[zypp-commit] r5412 - in /trunk/libzypp: devel/ devel/devel.jkupec/ zypp/ zypp/parser/yum/
  • From: jkupec@xxxxxxxxxxxxxxxx
  • Date: Thu, 19 Apr 2007 13:36:38 -0000
  • Message-id: <20070419133638.6644835594@xxxxxxxxxxxxxxxx>
Author: jkupec
Date: Thu Apr 19 15:36:37 2007
New Revision: 5412

URL: http://svn.opensuse.org/viewcvs/zypp?rev=5412&view=rev
Log:
yum parser WIP backup

Added:
    trunk/libzypp/devel/devel.jkupec/
    trunk/libzypp/devel/devel.jkupec/CMakeLists.txt
    trunk/libzypp/devel/devel.jkupec/YUMParser.cc
    trunk/libzypp/devel/devel.jkupec/YUMParser.h
    trunk/libzypp/devel/devel.jkupec/YUMParser_test.cc
    trunk/libzypp/zypp/parser/yum/PrimaryFileReader.cc
    trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h
Modified:
    trunk/libzypp/devel/CMakeLists.txt
    trunk/libzypp/zypp/CMakeLists.txt

Modified: trunk/libzypp/devel/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/CMakeLists.txt?rev=5412&r1=5411&r2=5412&view=diff
==============================================================================
--- trunk/libzypp/devel/CMakeLists.txt (original)
+++ trunk/libzypp/devel/CMakeLists.txt Thu Apr 19 15:36:37 2007
@@ -2,3 +2,4 @@
 
 ADD_SUBDIRECTORY(devel.dmacvicar)
 ADD_SUBDIRECTORY(devel.ma)
+ADD_SUBDIRECTORY(devel.jkupec)

Added: trunk/libzypp/devel/devel.jkupec/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/CMakeLists.txt?rev=5412&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.jkupec/CMakeLists.txt (added)
+++ trunk/libzypp/devel/devel.jkupec/CMakeLists.txt Thu Apr 19 15:36:37 2007
@@ -0,0 +1,9 @@
+INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
+
+ADD_DEFINITIONS(-DSRC_DIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\")
+
+#ADD_EXECUTABLE(sourcedownload sourcedownload.cc)
+#TARGET_LINK_LIBRARIES(sourcedownload zypp zypp2)
+
+ADD_EXECUTABLE( yumparsertest YUMParser_test.cc YUMParser.cc)
+TARGET_LINK_LIBRARIES(yumparsertest zypp zypp2)

Added: trunk/libzypp/devel/devel.jkupec/YUMParser.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/YUMParser.cc?rev=5412&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.jkupec/YUMParser.cc (added)
+++ trunk/libzypp/devel/devel.jkupec/YUMParser.cc Thu Apr 19 15:36:37 2007
@@ -0,0 +1,55 @@
+//#include "zypp/data/ResolvableDataConsumer.h"
+#include "zypp/ZYpp.h"
+#include "zypp/ZYppFactory.h"
+#include "zypp/base/Logger.h"
+
+#include "YUMParser.h"
+
+using std::endl;
+
+namespace zypp
+{
+  namespace parser
+  {
+    namespace yum
+    {
+
+
+  YUMParser::YUMParser(const zypp::data::RecordId &catalog_id, zypp::cache::CacheStore &consumer)
+    : _consumer(consumer), _catalog_id(catalog_id)
+  {
+    ZYpp::Ptr z = getZYpp();
+//    _system_arch = z->architecture();
+
+    MIL << "constructed" << endl;
+  }
+  
+  
+  
+  bool YUMParser::primary_CB(const zypp::data::Package &package)
+  {
+//    data::RecordId pkgid = _consumer.appendResolvable( _catalog_id, ResTraits<Package>::kind, nvra, deps );
+
+    MIL << "got package "
+      << package.name << package.edition << " "
+      << package.arch
+      << endl;
+/*    MIL << "checksum: " << package.checksum << endl;
+    MIL << "summary: " << package.summary << endl;*/
+  }
+
+  void YUMParser::start(const Pathname &cache_dir, Progress progress_fnc)
+  {
+    progress_fnc(0);
+
+    zypp::parser::yum::PrimaryFileReader(
+        cache_dir + "/repodata/primary.xml.gz",
+        bind(&YUMParser::primary_CB, this, _1));
+
+    progress_fnc(100);
+  }
+
+
+    } // ns yum
+  } // ns parser
+} // ns zypp

Added: trunk/libzypp/devel/devel.jkupec/YUMParser.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/YUMParser.h?rev=5412&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.jkupec/YUMParser.h (added)
+++ trunk/libzypp/devel/devel.jkupec/YUMParser.h Thu Apr 19 15:36:37 2007
@@ -0,0 +1,43 @@
+#ifndef YUMPARSER_H_
+#define YUMPARSER_H_
+
+#include "zypp/base/Logger.h"
+#include "zypp2/cache/CacheStore.h"
+#include "zypp/data/ResolvableData.h"
+#include "zypp/parser/yum/PrimaryFileReader.h"
+
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "parser"
+
+
+namespace zypp
+{
+  namespace parser
+  {
+    namespace yum
+    {
+
+
+  class YUMParser
+  {
+  public:
+    typedef function<bool( int )> Progress;
+
+    YUMParser(const zypp::data::RecordId &catalog_id, zypp::cache::CacheStore &consumer);
+
+    void start(const zypp::Pathname &path, Progress progress_fnc);
+
+    bool primary_CB(const zypp::data::Package &package);
+    bool test() { return true; }
+
+  private:
+    zypp::cache::CacheStore &_consumer;
+    zypp::data::RecordId _catalog_id;
+  };
+
+
+    }
+  }
+} // ns zypp
+
+#endif /*YUMPARSER_H_*/

Added: trunk/libzypp/devel/devel.jkupec/YUMParser_test.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/YUMParser_test.cc?rev=5412&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.jkupec/YUMParser_test.cc (added)
+++ trunk/libzypp/devel/devel.jkupec/YUMParser_test.cc Thu Apr 19 15:36:37 2007
@@ -0,0 +1,48 @@
+#include "zypp/ZYpp.h"
+#include "zypp/ZYppFactory.h"
+#include "zypp/base/Logger.h"
+#include "zypp/base/LogControl.h"
+#include "zypp/parser/yum/PrimaryFileReader.h"
+#include "YUMParser.h"
+
+
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "yumparsertest"
+
+using namespace std;
+using namespace zypp;
+using namespace zypp::parser::yum;
+
+bool progress_function(int p)
+{
+  MIL << p << "%" << endl;
+}
+
+int main(int argc, char **argv)
+{
+  base::LogControl::instance().logfile("yumparsertest.log");
+
+  try
+  {
+    ZYpp::Ptr z = getZYpp();
+//, bind( &YUMDownloader::patches_Callback, this, _1, _2));
+
+//    Pathname dbfile = Pathname(getenv("PWD")) + "data.db";
+    cache::CacheStore store(getenv("PWD"));
+    data::RecordId catalog_id = store.lookupOrAppendCatalog( Url("http://www.google.com";), "/");
+
+    MIL << "creating PrimaryFileParser" << endl;
+    parser::yum::YUMParser parser( catalog_id, store);
+    parser.start(argv[1], &progress_function);
+
+/*
+      YUMDownloader downloader(Url(argv[1]), "/");
+      downloader.download(argv[2]);*/
+  }
+  catch ( const Exception &e )
+  {
+    cout << "Oops! " << e.msg() << std::endl;
+  }
+
+  return 0;
+}

Modified: trunk/libzypp/zypp/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=5412&r1=5411&r2=5412&view=diff
==============================================================================
--- trunk/libzypp/zypp/CMakeLists.txt (original)
+++ trunk/libzypp/zypp/CMakeLists.txt Thu Apr 19 15:36:37 2007
@@ -540,6 +540,7 @@
   parser/yum/YUMRepomdParser.cc
   parser/yum/RepomdFileReader.cc
   parser/yum/PatchesFileReader.cc
+  parser/yum/PrimaryFileReader.cc
 )
 
 SET( zypp_parser_yum_HEADERS
@@ -556,6 +557,7 @@
   parser/yum/YUMRepomdParser.h
   parser/yum/RepomdFileReader.h
   parser/yum/PatchesFileReader.h
+  parser/yum/PrimaryFileReader.h
   parser/yum/schemanames.h
 )
 

Added: trunk/libzypp/zypp/parser/yum/PrimaryFileReader.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PrimaryFileReader.cc?rev=5412&view=auto
==============================================================================
--- trunk/libzypp/zypp/parser/yum/PrimaryFileReader.cc (added)
+++ trunk/libzypp/zypp/parser/yum/PrimaryFileReader.cc Thu Apr 19 15:36:37 2007
@@ -0,0 +1,155 @@
+#include "zypp/base/String.h"
+#include "zypp/base/Logger.h"
+#include "zypp/parser/yum/PrimaryFileReader.h"
+#include "zypp/Arch.h"
+#include "zypp/Edition.h"
+#include "zypp/TranslatedText.h"
+
+
+using namespace std;
+using namespace zypp::xml;
+
+namespace zypp
+{
+  namespace parser
+  {
+    namespace yum
+    {
+
+
+  PrimaryFileReader::PrimaryFileReader(const Pathname &primary_file, ProcessPackage callback)
+     : _callback(callback), _package(NULL), _count(0), _tag(tag_NONE)
+  {
+    Reader reader( primary_file );
+    MIL << "Reading " << primary_file << endl;
+    reader.foreachNode( bind( &PrimaryFileReader::consumeNode, this, _1 ) );
+  }
+  
+  bool PrimaryFileReader::consumeNode(Reader & reader_r)
+  {
+    if (_tag = tag_format)
+      return consumeFormatChildNodes(reader_r);
+  
+    if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
+    {
+      if (reader_r->name() == "package")
+      {
+        _tag = tag_package;
+  //      DBG << "got " << reader_r->getAttribute("type") << " package" << endl;
+        if (_package) delete _package;
+        _package = new zypp::data::Package();
+  
+        return true; 
+      }
+  
+      if (reader_r->name() == "name")
+      {
+        _package->name = reader_r.nodeText().asString();
+        return true;
+      }
+  
+      if (reader_r->name() == "arch")
+      {
+        //if (arch == "src" || arch == "nosrc") arch = "noarch";
+        _package->arch = Arch(reader_r.nodeText().asString());
+        return true;
+      }
+  
+      if (reader_r->name() == "version")
+      {
+        _package->edition = Edition(reader_r->getAttribute("ver").asString(),
+                                    reader_r->getAttribute("rel").asString(),
+                                    reader_r->getAttribute("epoch").asString());
+      }
+      
+      if (reader_r->name() == "checksum")
+      {
+        _package->checksum = CheckSum(reader_r->getAttribute("type").asString(),
+                                     reader_r.nodeText().asString());
+        // ignoring pkgid attribute 
+        return true;
+      }
+  
+      if (reader_r->name() == "summary")
+      {
+        _package->summary.setText(
+            reader_r.nodeText().asString(),
+            Locale(reader_r->getAttribute("lang").asString()));
+        return true;
+      }
+  
+      if (reader_r->name() == "description")
+      {
+        _package->description.setText(
+            reader_r.nodeText().asString(),
+            Locale(reader_r->getAttribute("lang").asString()));
+        return true;
+      }
+  
+      if (reader_r->name() == "packager")
+      {
+        _package->packager = reader_r.nodeText().asString(); 
+        return true;
+      }
+  
+      // TODO url
+      // TODO time
+      // TODO size
+  
+      if (reader_r->name() == "location")
+      {
+        _package->location = reader_r->getAttribute("href").asString();
+      }
+  
+      if (reader_r->name() == "format")
+      {
+        _tag = tag_format;
+        consumeFormatChildNodes(reader_r);
+      }
+    }
+    else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
+    {
+      if (reader_r->name() == "package")
+      {
+        _callback(*_package);
+        if (_package)
+        {
+          delete _package;
+          _package = NULL;
+        }
+        _count++;
+        _tag = tag_NONE;
+      }
+      if (reader_r->name() == "metadata")
+      {
+        MIL << _count << " packages read." << endl;
+      }
+      return true;
+    }
+  
+    return true;
+  }
+  
+  bool PrimaryFileReader::consumeFormatChildNodes(Reader & reader_r)
+  {
+    if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
+    {
+      
+    }
+    else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
+    {
+      if (reader_r->name() == "format");
+      {
+        _tag = tag_package;
+        return true;
+      }
+    }
+    return true;
+  }
+
+
+    } // ns yum
+  } // ns parser
+} //ns zypp
+
+// vim: set ts=2 sts=2 sw=2 et ai:

Added: trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h?rev=5412&view=auto
==============================================================================
--- trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h (added)
+++ trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h Thu Apr 19 15:36:37 2007
@@ -0,0 +1,81 @@
+#ifndef ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H
+#define ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H
+
+#include "zypp/Date.h"
+#include "zypp/base/Function.h"
+#include "zypp/base/Logger.h"
+#include "zypp/parser/xml/Reader.h"
+#include "zypp/data/ResolvableData.h"
+
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "parser"
+
+namespace zypp
+{
+  namespace parser
+  {
+    namespace yum
+    {
+
+      enum Tag
+      {
+        tag_NONE,
+        tag_package,
+        tag_format
+      };
+
+/**
+ * Iterates through a primary.xml file giving on each iteration
+ * a \ref OnMediaLocation object with the resource and its
+ * type ( primary, patches, filelists, etc ).
+ * The iteration is done via a callback provided on
+ * construction.
+ *
+ * \code
+ * RepomdFileReader reader(repomd_file, 
+ *                  bind( &SomeClass::callbackfunc, &object, _1, _2 ) );
+ * \endcode
+ */
+class PrimaryFileReader
+{
+public:
+  /**
+   * Callback definition.
+   */
+  typedef function<bool(const zypp::data::Package&)> ProcessPackage;
+
+  /**
+   * Constructor
+   * \param primary_file the primary.xml.gz file you want to read
+   * \param function to process \ref _package data.
+   * 
+   * \see PrimaryFileReader::ProcessPackage
+   */
+  PrimaryFileReader(const Pathname &primary_file, ProcessPackage callback);
+
+  /**
+   * Callback provided to the XML parser.
+   */
+  bool consumeNode(zypp::xml::Reader & reader_r);
+
+private:
+  bool consumeFormatChildNodes(zypp::xml::Reader & reader_r);
+
+private:
+  Tag _tag;
+  unsigned _count;
+  zypp::data::Package *_package;
+  ProcessPackage _callback;
+/*  CheckSum _checksum;
+  std::string _checksum_type;
+  Date _timestamp;*/
+};
+
+
+    } // ns zypp
+  } // ns parser
+} // ns yum
+
+#endif /* ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H */
+
+// vim: set ts=2 sts=2 sw=2 et ai:

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages