From 2f88b9b643527b902d0096156a7def58dd118f0c Mon Sep 17 00:00:00 2001 From: Jiri Srain Date: Tue, 17 Jan 2006 08:25:09 +0000 Subject: [PATCH] adde parser for installation patterns --- zypp/parser/yum/Makefile.am | 2 + zypp/parser/yum/YUMParser.h | 1 + zypp/parser/yum/YUMParserData.cc | 22 ++++ zypp/parser/yum/YUMParserData.h | 18 ++++ zypp/parser/yum/YUMPatternParser.cc | 157 ++++++++++++++++++++++++++++ zypp/parser/yum/YUMPatternParser.h | 71 +++++++++++++ zypp/parser/yum/schema/patterns.rnc | 34 ++++++ zypp/parser/yum/schema/patterns.rng | 71 +++++++++++++ zypp/parser/yum/schemanames.h | 1 + 9 files changed, 377 insertions(+) create mode 100644 zypp/parser/yum/YUMPatternParser.cc create mode 100644 zypp/parser/yum/YUMPatternParser.h create mode 100644 zypp/parser/yum/schema/patterns.rnc create mode 100644 zypp/parser/yum/schema/patterns.rng diff --git a/zypp/parser/yum/Makefile.am b/zypp/parser/yum/Makefile.am index fc4226d1a..dbb494390 100644 --- a/zypp/parser/yum/Makefile.am +++ b/zypp/parser/yum/Makefile.am @@ -15,6 +15,7 @@ parseryuminclude_HEADERS = \ YUMParser.h \ YUMPrimaryParser.h \ YUMGroupParser.h \ + YUMPatternParser.h \ YUMParserData.h \ YUMPatchParser.h \ YUMPatchesParser.h \ @@ -32,6 +33,7 @@ lib@PACKAGE@_parser_yum_la_SOURCES = \ YUMFileListParser.cc \ YUMRepomdParser.cc \ YUMGroupParser.cc \ + YUMPatternParser.cc \ YUMPatchParser.cc \ YUMPatchesParser.cc \ YUMOtherParser.cc \ diff --git a/zypp/parser/yum/YUMParser.h b/zypp/parser/yum/YUMParser.h index 3da209612..8e3c1d31f 100644 --- a/zypp/parser/yum/YUMParser.h +++ b/zypp/parser/yum/YUMParser.h @@ -18,6 +18,7 @@ #include "zypp/parser/yum/YUMRepomdParser.h" #include "zypp/parser/yum/YUMPrimaryParser.h" #include "zypp/parser/yum/YUMGroupParser.h" +#include "zypp/parser/yum/YUMPatternParser.h" #include "zypp/parser/yum/YUMFileListParser.h" #include "zypp/parser/yum/YUMOtherParser.h" #include "zypp/parser/yum/YUMPatchParser.h" diff --git a/zypp/parser/yum/YUMParserData.cc b/zypp/parser/yum/YUMParserData.cc index 87882ca47..cdb9a8f43 100644 --- a/zypp/parser/yum/YUMParserData.cc +++ b/zypp/parser/yum/YUMParserData.cc @@ -79,6 +79,9 @@ namespace zypp { YUMGroupData::YUMGroupData() { } + YUMPatternData::YUMPatternData() + { } + MultiLang::MultiLang() { } @@ -129,6 +132,7 @@ namespace zypp { IMPL_PTR_TYPE(YUMRepomdData); IMPL_PTR_TYPE(YUMPrimaryData); IMPL_PTR_TYPE(YUMGroupData); + IMPL_PTR_TYPE(YUMPatternData); IMPL_PTR_TYPE(YUMFileListData); IMPL_PTR_TYPE(YUMOtherData); IMPL_PTR_TYPE(YUMPatchData); @@ -325,6 +329,24 @@ namespace zypp { return out; } + ostream& operator<<(ostream &out, const YUMPatternData& data) + { + out << "-------------------------------------------------" << endl + << "Pattern Data: " << endl + << "pattern-id: '" << data.patternId << "'" << endl + << "name:" << endl + << data.name << endl + << "default: '" << data.default_ << "'" << endl + << "user-visible: '" << data.userVisible << "'" << endl + << "description:" << endl + << data.description << endl + << "patternlist:" << endl + << data.patternlist << endl + << "packageList:" << endl + << data.packageList << endl; + return out; + } + ostream& operator<<(ostream &out, const YUMFileListData& data) { out << "-------------------------------------------------" << endl diff --git a/zypp/parser/yum/YUMParserData.h b/zypp/parser/yum/YUMParserData.h index 38e5c274e..92deba4d7 100644 --- a/zypp/parser/yum/YUMParserData.h +++ b/zypp/parser/yum/YUMParserData.h @@ -36,6 +36,7 @@ namespace zypp { DEFINE_PTR_TYPE( YUMRepomdData ); DEFINE_PTR_TYPE( YUMPrimaryData ); DEFINE_PTR_TYPE( YUMGroupData ); + DEFINE_PTR_TYPE( YUMPatternData ); DEFINE_PTR_TYPE( YUMFileListData ); DEFINE_PTR_TYPE( YUMOtherData ); DEFINE_PTR_TYPE( YUMPatchData ); @@ -347,6 +348,23 @@ namespace zypp { std::list packageList; }; + /** + * @short Describes the patterns in a YUM repository + **/ + + class YUMPatternData : public base::ReferenceCounted, private base::NonCopyable { + public: + + YUMPatternData(); + std::string patternId; + std::list name; + std::string default_; + std::string userVisible; + std::list description; + std::list patternlist; + std::list packageList; + }; + /** * @short Contains the file list for a YUM package. **/ diff --git a/zypp/parser/yum/YUMPatternParser.cc b/zypp/parser/yum/YUMPatternParser.cc new file mode 100644 index 000000000..b21068d60 --- /dev/null +++ b/zypp/parser/yum/YUMPatternParser.cc @@ -0,0 +1,157 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/parser/yum/YUMPatternParser.cc + * +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +namespace zypp { + namespace parser { + namespace yum { + + YUMPatternParser::YUMPatternParser() + { } + + YUMPatternParser::YUMPatternParser(YUMPatternData_Ptr& entry) + : XMLNodeIterator(entry) + { } + + + YUMPatternParser::~YUMPatternParser() + { } + + + // select for which elements process() will be called + bool + YUMPatternParser::isInterested(const xmlNodePtr nodePtr) + { + return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "pattern"; + } + + // do the actual processing + YUMPatternData_Ptr + YUMPatternParser::process(const xmlTextReaderPtr reader) + { + assert(reader); + YUMPatternData_Ptr dataPtr = new YUMPatternData; + xmlNodePtr dataNode = xmlTextReaderExpand(reader); + assert(dataNode); + + for (xmlNodePtr child = dataNode->children; + child && child != dataNode; + child = child->next) { + if (_helper.isElement(child)) { + string name = _helper.name(child); + if (name == "patternid") { + dataPtr->patternId = _helper.content(child); + } + else if (name == "name") { + dataPtr->name.push_back + (MultiLang(_helper.attribute(child,"lang"), + _helper.content(child))); + } + else if (name == "default") { + dataPtr->default_ = _helper.content(child); + } + else if (name == "uservisible") { + dataPtr->userVisible = _helper.content(child); + } + else if (name == "description") { + dataPtr->description.push_back + (MultiLang(_helper.attribute(child,"lang"), + _helper.content(child))); + } + else if (name == "patternlist") { + parsePatternlist(dataPtr, child); + } + else if (name == "packagelist") { + parsePackageList(dataPtr, child); + } + else { + WAR << "YUM contains the unknown element <" << name << "> " + << _helper.positionInfo(child) << ", skipping" << endl; + } + } + } + return dataPtr; + } /* end process */ + + void YUMPatternParser::parsePatternlist(YUMPatternData_Ptr dataPtr, + xmlNodePtr node) + { + assert(dataPtr); + assert(node); + + for (xmlNodePtr child = node->children; + child != 0; + child = child ->next) { + if (_helper.isElement(child)) { + string name = _helper.name(child); + if (name == "metapkg" || name == "patternreq") { + dataPtr->patternlist.push_back + (MetaPkg(_helper.attribute(child,"type"), + _helper.content(child))); + } + else { + WAR << "YUM contains the unknown element <" << name << "> " + << _helper.positionInfo(child) << ", skipping" << endl; + } + } + } + } + + + void YUMPatternParser::parsePackageList(YUMPatternData_Ptr dataPtr, + xmlNodePtr node) + { + assert(dataPtr); + assert(node); + + for (xmlNodePtr child = node->children; + child != 0; + child = child ->next) { + if (_helper.isElement(child)) { + string name = _helper.name(child); + if (name == "packagereq") { + dataPtr->packageList.push_back + (PackageReq(_helper.attribute(child,"type"), + _helper.attribute(child,"epoch"), + _helper.attribute(child,"ver"), + _helper.attribute(child,"rel"), + _helper.content(child))); + } + else { + WAR << "YUM contains the unknown element <" << name << "> " + << _helper.positionInfo(child) << ", skipping" << endl; + } + } + } + } + + + + YUMPatternParser::YUMPatternParser(istream &is, const string &baseUrl) + : XMLNodeIterator(is, baseUrl,PATTERNSCHEMA) + { + fetchNext(); + } + + } // namespace yum + } // namespace parser +} // namespace zypp diff --git a/zypp/parser/yum/YUMPatternParser.h b/zypp/parser/yum/YUMPatternParser.h new file mode 100644 index 000000000..3b62e1e69 --- /dev/null +++ b/zypp/parser/yum/YUMPatternParser.h @@ -0,0 +1,71 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/parser/yum/YUMPatternParser.h + * +*/ + + + +#ifndef YUMPatternParser_h +#define YUMPatternParser_h + +#include +#include +#include +#include + +namespace zypp { + namespace parser { + namespace yum { + + /** + * + * @short Parser for YUM group files. + * + * Use this class as an iterator that produces, one after one, + * YUMPatternData_Ptr(s) for the XML group elements. + * Here's an example: + * + * for (YUMPatternParser iter(anIstream, baseUrl), + * iter != YUMFileListParser.end(), // or: iter() != 0, or ! iter.atEnd() + * ++iter) { + * doSomething(*iter) + * } + * + * The iterator owns the pointer (i.e., caller must not delete it) + * until the next ++ operator is called. At this time, it will be + * destroyed (and a new ENTRYTYPE is created.) + * + * If the input is fundamentally flawed so that it makes no sense to + * continue parsing, XMLNodeIterator will log it and consider the input as finished. + * You can query the exit status with errorStatus(). + */ + class YUMPatternParser : public XMLNodeIterator + { + public: + YUMPatternParser(std::istream &is, const std::string &baseUrl); + YUMPatternParser(); + YUMPatternParser(YUMPatternData_Ptr& entry); + virtual ~YUMPatternParser(); + + private: + virtual bool isInterested(const xmlNodePtr nodePtr); + virtual YUMPatternData_Ptr process(const xmlTextReaderPtr reader); + void parsePatternlist(YUMPatternData_Ptr dataPtr, + xmlNodePtr node); + void parsePackageList(YUMPatternData_Ptr dataPtr, + xmlNodePtr node); + + LibXMLHelper _helper; + }; + } // namespace yum + } // namespace parser +} // namespace zypp + +#endif diff --git a/zypp/parser/yum/schema/patterns.rnc b/zypp/parser/yum/schema/patterns.rnc new file mode 100644 index 000000000..a41486d48 --- /dev/null +++ b/zypp/parser/yum/schema/patterns.rnc @@ -0,0 +1,34 @@ +default namespace = "http://linux.duke.edu/metadata/patterns" + +element patterns { + element pattern { + element patternid { text }, + element name { + attribute lang { text }?, + text + }+, + element default { "true" | "false" }?, + element uservisible { "true" | "false" }, + element description { + attribute lang { text }?, + text + }+, + element patternlist { + element metapkg { + attribute type { text }?, + text + }+ + }?, + element packagelist { + element packagereq { + attribute type { text }?, + attribute epoch { xsd:nonNegativeInteger }, + attribute ver { text }, + attribute rel { text }, + text + }+ + }?, + empty + }+, + empty +} diff --git a/zypp/parser/yum/schema/patterns.rng b/zypp/parser/yum/schema/patterns.rng new file mode 100644 index 000000000..711a41a56 --- /dev/null +++ b/zypp/parser/yum/schema/patterns.rng @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + true + false + + + + + + true + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/zypp/parser/yum/schemanames.h b/zypp/parser/yum/schemanames.h index 891d57858..b72996887 100644 --- a/zypp/parser/yum/schemanames.h +++ b/zypp/parser/yum/schemanames.h @@ -22,6 +22,7 @@ namespace zypp { #define REPOMDSCHEMA (SCHEMABASE "repomd.rng") #define PRIMARYSCHEMA (SCHEMABASE "suse-primary.rng") #define GROUPSCHEMA (SCHEMABASE "groups.rng") + #define PATTERNSCHEMA (SCHEMABASE "patterns.rng") #define FILELISTSCHEMA (SCHEMABASE "filelists.rng") #define OTHERSCHEMA (SCHEMABASE "other.rng") #define PATCHSCHEMA (SCHEMABASE "patch.rng") -- 2.34.1