added testcase for parsing whole YUM repository
authorJiri Srain <jsrain@suse.cz>
Thu, 1 Dec 2005 14:19:04 +0000 (14:19 +0000)
committerJiri Srain <jsrain@suse.cz>
Thu, 1 Dec 2005 14:19:04 +0000 (14:19 +0000)
devel/devel.jsrain/Makefile.am
devel/devel.jsrain/SourceRead.cc [new file with mode: 0644]
devel/devel.jsrain/repodata [new symlink]
devel/devel.jsrain/yum/YUMParser.test/filelists.xml [new symlink]
devel/devel.jsrain/yum/YUMParser.test/group.xml [new symlink]
devel/devel.jsrain/yum/YUMParser.test/other.xml [new symlink]
devel/devel.jsrain/yum/YUMParser.test/patch.xml [new symlink]
devel/devel.jsrain/yum/YUMParser.test/patches.xml [new symlink]
devel/devel.jsrain/yum/YUMParser.test/primary.xml [new symlink]
devel/devel.jsrain/yum/YUMParser.test/product.xml [new symlink]

index 6b674d9..d2bf2d4 100644 (file)
@@ -3,7 +3,7 @@
 
 SUBDIRS = yum
 
-noinst_PROGRAMS =      Msg Msg.debug Patch Patch.debug Script Script.debug PatchSelect PatchSelect.debug PatchRead PatchRead.debug
+noinst_PROGRAMS =      Msg Msg.debug Patch Patch.debug Script Script.debug PatchSelect PatchSelect.debug PatchRead PatchRead.debug SourceRead SourceRead.debug
 
 
 ## ##################################################
@@ -43,6 +43,12 @@ PatchRead_SOURCES =  PatchRead.cc
 PatchRead_debug_SOURCES =      $(PatchRead_SOURCES)
 PatchRead_debug_LDFLAGS =      -static
 
+SourceRead_SOURCES =           SourceRead.cc
+
+SourceRead_debug_SOURCES =     $(SourceRead_SOURCES)
+SourceRead_debug_LDFLAGS =     -static
+
+
 ## ##################################################
 
 .PHONY:        always
diff --git a/devel/devel.jsrain/SourceRead.cc b/devel/devel.jsrain/SourceRead.cc
new file mode 100644 (file)
index 0000000..252489f
--- /dev/null
@@ -0,0 +1,288 @@
+#include <iostream>
+#include <fstream>
+#include <zypp/base/Logger.h>
+#include <zypp/detail/MessageImpl.h>
+#include <zypp/Message.h>
+#include <YUMParser.h>
+#include <zypp/base/Logger.h>
+#include <map>
+#include "zypp/source/yum/YUMSource.h"
+
+
+using namespace std;
+using namespace zypp;
+using namespace zypp::source::yum;
+
+  class PackageID {
+  public:
+    PackageID(string name, std::string ver, std::string rel, std::string arch)
+    : _name(name)
+    , _ver(ver)
+    , _rel(rel)
+    , _arch(arch)
+    {};
+    static int compare( const PackageID & lhs, const PackageID & rhs )
+    {
+      if (lhs._name < rhs._name)
+       return 1;
+      if (lhs._name > rhs._name)
+       return -1;
+      if (lhs._ver < rhs._ver)
+       return 1;
+      if (lhs._ver > rhs._ver)
+       return -1;
+      if (lhs._rel < rhs._rel)
+       return 1;
+      if (lhs._rel > rhs._rel)
+       return -1;
+      if (lhs._arch < rhs._arch)
+       return 1;
+      if (lhs._arch > rhs._arch)
+       return -1;
+      return 0;
+    }
+    string name() { return _name; }
+    string ver() { return _ver; }
+    string rel() { return _rel; }
+    string arch() { return _arch; }
+  private:
+    string _name;
+    string _ver;
+    string _rel;
+    string _arch;
+  };
+  inline bool operator<( const PackageID & lhs, const PackageID & rhs )
+  { return PackageID::compare( lhs, rhs ) == -1; }
+
+
+/******************************************************************
+**
+**
+**     FUNCTION NAME : main
+**     FUNCTION TYPE : int
+**
+**     DESCRIPTION :
+*/
+int main( int argc, char * argv[] )
+{
+  INT << "===[START]==========================================" << endl;
+  YUMSource src;
+
+// read repomd first
+
+  std::list<YUMRepomdData_Ptr> repo_primary;
+  std::list<YUMRepomdData_Ptr> repo_files;
+  std::list<YUMRepomdData_Ptr> repo_other;
+  std::list<YUMRepomdData_Ptr> repo_group;
+  std::list<YUMRepomdData_Ptr> repo_product;
+  std::list<YUMRepomdData_Ptr> repo_patches;
+
+  ifstream repo_st("yum/YUMParser.test/001-repomd-correct.test.xml");
+  YUMRepomdParser repomd(repo_st, "");
+  for(;
+      ! repomd.atEnd();
+      ++repomd)
+  {
+    if ((*repomd)->type == "primary")
+      repo_primary.push_back(*repomd);
+    else if ((*repomd)->type == "filelists")
+      repo_files.push_back(*repomd);
+    else if ((*repomd)->type == "other")
+      repo_other.push_back(*repomd);
+    else if ((*repomd)->type == "group")
+      repo_group.push_back(*repomd);
+    else if ((*repomd)->type == "product")
+      repo_product.push_back(*repomd);
+    else if ((*repomd)->type == "patches")
+      repo_patches.push_back(*repomd);
+    else
+      ERR << "Unknown type of repo file: " << (*repomd)->type << endl;
+  }
+
+  // now put other and filelist data to structures for easier find
+  map<PackageID, YUMFileListData_Ptr> files_data;
+  map<PackageID, YUMOtherData_Ptr> other_data;
+  for (std::list<YUMRepomdData_Ptr>::const_iterator it = repo_files.begin();
+       it != repo_files.end();
+       it++)
+  {
+    // TODO check checksum
+    string filename = (*it)->location;
+    DBG << "Reading file " << filename << endl;
+    ifstream st(filename.c_str());
+    YUMFileListParser filelist(st, "");
+    for (;
+        ! filelist.atEnd();
+        ++filelist)
+    {
+      PackageID id((*filelist)->name,
+                  (*filelist)->ver,
+                  (*filelist)->rel,
+                  (*filelist)->arch);
+      files_data[id] = *filelist;
+    }
+    if (filelist.errorStatus())
+      throw *filelist.errorStatus();
+  }
+
+  for (std::list<YUMRepomdData_Ptr>::const_iterator it = repo_other.begin();
+       it != repo_other.end();
+       it++)
+  {
+    // TODO check checksum
+    string filename = (*it)->location;
+    DBG << "Reading file " << filename << endl;
+    ifstream st(filename.c_str());
+    YUMOtherParser other(st, "");
+    for (;
+        ! other.atEnd();
+        ++other)
+    {
+      PackageID id((*other)->name,
+                  (*other)->ver,
+                  (*other)->rel,
+                  (*other)->arch);
+      other_data[id] = *other;
+    }
+    if (other.errorStatus())
+      throw *other.errorStatus();
+  }
+
+  // now read primary data
+  for (std::list<YUMRepomdData_Ptr>::const_iterator it = repo_primary.begin();
+       it != repo_primary.end();
+       it++)
+  {
+    // TODO check checksum
+    string filename = (*it)->location;
+    DBG << "Reading file " << filename << endl;
+    ifstream st(filename.c_str());
+    YUMPrimaryParser prim(st, "");
+    for (;
+        !prim.atEnd();
+        ++prim)
+    {
+      PackageID id((*prim)->name,
+                  (*prim)->ver,
+                  (*prim)->rel,
+                  (*prim)->arch);
+      map<PackageID, YUMOtherData_Ptr>::iterator found_other
+         = other_data.find(id);
+      map<PackageID, YUMFileListData_Ptr>::iterator found_files
+         = files_data.find(id);
+  
+      YUMFileListData filelist_empty;
+      YUMOtherData other_empty;
+      Package::Ptr p = src.createPackage(
+       **prim,
+       found_files != files_data.end()
+         ? *found_files->second
+         : filelist_empty,
+       found_other != other_data.end()
+         ? *found_other->second
+         : other_empty
+      );
+    }
+    if (prim.errorStatus())
+      throw *prim.errorStatus();
+  }
+
+  // and now other metadata
+  // groups
+  for (std::list<YUMRepomdData_Ptr>::const_iterator it = repo_group.begin();
+       it != repo_group.end();
+       it++)
+  {
+    // TODO check checksum
+    string filename = (*it)->location;
+    DBG << "Reading file " << filename << endl;
+    ifstream st(filename.c_str());
+    YUMGroupParser group(st, "");
+    for (;
+        !group.atEnd();
+        ++group)
+    {
+      Selection::Ptr p = src.createGroup(**group);
+    }
+    if (group.errorStatus())
+      throw *group.errorStatus();
+  }
+
+  // products
+  for (std::list<YUMRepomdData_Ptr>::const_iterator it = repo_product.begin();
+       it != repo_product.end();
+       it++)
+  {
+    // TODO check checksum
+    string filename = (*it)->location;
+    DBG << "Reading file " << filename << endl;
+    ifstream st(filename.c_str());
+    YUMProductParser product(st, "");
+    for (;
+        !product.atEnd();
+        ++product)
+    {
+      Product::Ptr p = src.createProduct(**product);
+    }
+    if (product.errorStatus())
+      throw *product.errorStatus();
+  }
+
+  // patches
+  std::list<std::string> patch_files;
+  for (std::list<YUMRepomdData_Ptr>::const_iterator it = repo_patches.begin();
+       it != repo_patches.end();
+       it++)
+  {
+    // TODO check checksum
+    string filename = (*it)->location;
+    DBG << "Reading file " << filename << endl;
+    ifstream st(filename.c_str());
+    YUMPatchesParser patch(st, "");
+    for (;
+        !patch.atEnd();
+        ++patch)
+    {
+      // TODO check checksum
+      string filename = (*patch)->location;
+      patch_files.push_back(filename);
+    }
+    if (patch.errorStatus())
+      throw *patch.errorStatus();
+  }
+
+try {
+
+  for (std::list<std::string>::const_iterator it = patch_files.begin();
+       it != patch_files.end();
+       it++)
+  {
+      std::string filename = *it;
+      DBG << "Reading file " << filename << endl;
+      ifstream st(filename.c_str());
+      YUMPatchParser ptch(st, "");
+      for(;
+          !ptch.atEnd();
+          ++ptch)
+      {
+ERR << "Creating patch" << endl;
+       Patch::Ptr p = src.createPatch(**ptch);
+      }
+      if (ptch.errorStatus())
+       throw *ptch.errorStatus();
+  }
+
+}
+catch (const Exception & excpt_r)
+{
+  ERR << excpt_r << endl;
+}
+catch (...)
+{
+  ERR << "exception" << endl;
+}
+// read data then
+
+  INT << "===[END]============================================" << endl;
+  return 0;
+}
diff --git a/devel/devel.jsrain/repodata b/devel/devel.jsrain/repodata
new file mode 120000 (symlink)
index 0000000..80e8df2
--- /dev/null
@@ -0,0 +1 @@
+yum/YUMParser.test/
\ No newline at end of file
diff --git a/devel/devel.jsrain/yum/YUMParser.test/filelists.xml b/devel/devel.jsrain/yum/YUMParser.test/filelists.xml
new file mode 120000 (symlink)
index 0000000..a44447d
--- /dev/null
@@ -0,0 +1 @@
+003-filelists-correct.test.xml
\ No newline at end of file
diff --git a/devel/devel.jsrain/yum/YUMParser.test/group.xml b/devel/devel.jsrain/yum/YUMParser.test/group.xml
new file mode 120000 (symlink)
index 0000000..d47151f
--- /dev/null
@@ -0,0 +1 @@
+004-group-correct.test.xml
\ No newline at end of file
diff --git a/devel/devel.jsrain/yum/YUMParser.test/other.xml b/devel/devel.jsrain/yum/YUMParser.test/other.xml
new file mode 120000 (symlink)
index 0000000..39baff6
--- /dev/null
@@ -0,0 +1 @@
+005-other-correct.test.xml
\ No newline at end of file
diff --git a/devel/devel.jsrain/yum/YUMParser.test/patch.xml b/devel/devel.jsrain/yum/YUMParser.test/patch.xml
new file mode 120000 (symlink)
index 0000000..dccf6f6
--- /dev/null
@@ -0,0 +1 @@
+006-patch-correct.test.xml
\ No newline at end of file
diff --git a/devel/devel.jsrain/yum/YUMParser.test/patches.xml b/devel/devel.jsrain/yum/YUMParser.test/patches.xml
new file mode 120000 (symlink)
index 0000000..3152597
--- /dev/null
@@ -0,0 +1 @@
+008-patches-correct.test.xml
\ No newline at end of file
diff --git a/devel/devel.jsrain/yum/YUMParser.test/primary.xml b/devel/devel.jsrain/yum/YUMParser.test/primary.xml
new file mode 120000 (symlink)
index 0000000..a11049c
--- /dev/null
@@ -0,0 +1 @@
+002-primary-correct.test.xml
\ No newline at end of file
diff --git a/devel/devel.jsrain/yum/YUMParser.test/product.xml b/devel/devel.jsrain/yum/YUMParser.test/product.xml
new file mode 120000 (symlink)
index 0000000..8d47fca
--- /dev/null
@@ -0,0 +1 @@
+007-product-correct.test.xml
\ No newline at end of file