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; }
-
/******************************************************************
**
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
+ src.parseSourceMetadata("repodata");
INT << "===[END]============================================" << endl;
return 0;
--- /dev/null
+001-repomd-correct.test.xml
\ No newline at end of file
#include "zypp/base/Logger.h"
#include "zypp/CapFactory.h"
+#include "zypp/parser/yum/YUMParser.h"
+
+#include <fstream>
+
using namespace std;
using namespace zypp::detail;
using namespace zypp::parser::yum;
YUMSource::YUMSource()
{}
+ void YUMSource::parseSourceMetadata(std::string path)
+ {
+ 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;
+
+ try {
+ // first read list of all files in the reposotory
+ std::string filename = path + "/repmod.xml";
+ DBG << "Reading file " << filename << endl;
+ ifstream repo_st(filename.c_str());
+ 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;
+ }
+ }
+ catch (...)
+ {
+ ERR << "Cannot read repomd file, cannot initialize source" << endl;
+// ZYPP_THROW( "Cannot read repomd file, cannot initialize source" );
+ }
+ try {
+ // 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, merge them with filelist and changelog
+ 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 = createPackage(
+ **prim,
+ found_files != files_data.end()
+ ? *found_files->second
+ : filelist_empty,
+ found_other != other_data.end()
+ ? *found_other->second
+ : other_empty
+ );
+ ERR << "Insert package " << *p << " into the pool" << endl;
+ }
+ if (prim.errorStatus())
+ throw *prim.errorStatus();
+ }
+ }
+ catch (...) {
+ ERR << "Cannot read package information" << endl;
+ }
+
+ try {
+ // 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 = createGroup(**group);
+ ERR << "Insert group " << *p << " into the pool" << endl;
+ }
+ if (group.errorStatus())
+ throw *group.errorStatus();
+ }
+ }
+ catch (...) {
+ ERR << "Cannot read package groups information" << endl;
+ }
+
+ try {
+ // 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 = createProduct(**product);
+ ERR << "Insert product " << *p << " into the pool" << endl;
+ }
+ if (product.errorStatus())
+ throw *product.errorStatus();
+ }
+ }
+ catch (...) {
+ ERR << "Cannot read products information" << endl;
+ }
+
+ try {
+ // 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();
+ }
+
+ 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)
+ {
+ Patch::Ptr p = createPatch(**ptch);
+ ERR << "Insert patch " << *p << " into the pool" << endl;
+ Patch::AtomList atoms = p->atoms();
+ for (Patch::AtomList::iterator at = atoms.begin();
+ at != atoms.end();
+ at++)
+ {
+ ERR << "Inserting atom " << **at << " into the pool" << endl;
+ }
+ }
+ if (ptch.errorStatus())
+ throw *ptch.errorStatus();
+ }
+ }
+ catch (...)
+ {
+ ERR << "Cannot read patch metadata" << endl;
+ }
+ }
Package::Ptr YUMSource::createPackage(
const zypp::parser::yum::YUMPrimaryData & parsed,
/** Default ctor */
YUMSource();
+ void parseSourceMetadata(std::string path);
+
Package::Ptr createPackage(
const zypp::parser::yum::YUMPrimaryData & parsed,
const zypp::parser::yum::YUMFileListData & filelist,
Capability createCapability(const YUMDependency & dep,
const Resolvable::Kind & my_kind);
+ class PackageID {
+ public:
+ PackageID(std::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;
+ }
+ std::string name() { return _name; }
+ std::string ver() { return _ver; }
+ std::string rel() { return _rel; }
+ std::string arch() { return _arch; }
+ private:
+ std::string _name;
+ std::string _ver;
+ std::string _rel;
+ std::string _arch;
+ };
+
+ };
+ inline bool operator<( const YUMSource::PackageID & lhs, const YUMSource::PackageID & rhs )
+ { return YUMSource::PackageID::compare( lhs, rhs ) == -1; }
- };
///////////////////////////////////////////////////////////////////
} // namespace yum
/////////////////////////////////////////////////////////////////