From: Duncan Mac-Vicar P Date: Tue, 11 Jul 2006 09:52:42 +0000 (+0000) Subject: - finally the cacher and parser connect together X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~552 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b3d621e3792d84ae28123002559e096b0abe347c;p=platform%2Fupstream%2Flibzypp.git - finally the cacher and parser connect together --- diff --git a/configure.ac b/configure.ac index 808e27a..7e2afd9 100644 --- a/configure.ac +++ b/configure.ac @@ -244,6 +244,7 @@ AC_OUTPUT( po/Makefile.in\ zypp/capability/Makefile \ zypp/parser/Makefile \ zypp/parser/yum/Makefile \ + zypp/parser/yum2/Makefile \ zypp/parser/yum/schema/Makefile \ zypp/parser/tagfile/Makefile \ zypp/parser/xmlstore/Makefile \ diff --git a/devel/devel.dmacvicar/testbed.cc b/devel/devel.dmacvicar/testbed.cc index 24d5997..72e6de8 100644 --- a/devel/devel.dmacvicar/testbed.cc +++ b/devel/devel.dmacvicar/testbed.cc @@ -26,6 +26,7 @@ #include "zypp/PublicKey.h" #include "zypp/MediaSetAccess.h" +#include "zypp/source/yum/YUMSourceCacher.h" using namespace zypp::detail; @@ -36,11 +37,20 @@ using namespace zypp::source; int main() { - MediaSetAccess ma( Url("cd:///"), Pathname("/")); - MIL << "done 1" << srd::endl; - Pathname local = ma.provideFile("content", 1); - MIL << local << std::endl; - + //MediaSetAccess ma( Url("cd:///"), Pathname("/")); + //MIL << "done 1" << std::endl; + //ChecksumFileChecker checker(CheckSum("sha1", "fa0abb22f703a3a41f7a39f0844b24daf572fd4c")); + //Pathname local = ma.provideFile("content", 1, checker); + //MIL << local << std::endl; + try + { + zypp::source::yum::YUMSourceCacher cacher(Pathname("/")); + cacher.cache( Url("http://ftp-1.gwdg.de/pub/opensuse/distribution/SL-OSS-factory/inst-source/suse"), Pathname("/")); + } + catch ( const Exception &e ) + { + MIL << "Sorry, bye" << endl; + } } diff --git a/devel/devel.dmacvicar/yum-parser.cc b/devel/devel.dmacvicar/yum-parser.cc index 11b1b58..c946228 100644 --- a/devel/devel.dmacvicar/yum-parser.cc +++ b/devel/devel.dmacvicar/yum-parser.cc @@ -15,243 +15,13 @@ #include /////////////////////////////////////////////////////////////////// -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace zypp::detail; - -using namespace std; -using namespace zypp; -using namespace zypp::parser::yum; -using namespace zypp::source::yum; - -xmlSAXHandler emptySAXHandlerStruct = { - NULL, /* internalSubset */ - NULL, /* isStandalone */ - NULL, /* hasInternalSubset */ - NULL, /* hasExternalSubset */ - NULL, /* resolveEntity */ - NULL, /* getEntity */ - NULL, /* entityDecl */ - NULL, /* notationDecl */ - NULL, /* attributeDecl */ - NULL, /* elementDecl */ - NULL, /* unparsedEntityDecl */ - NULL, /* setDocumentLocator */ - NULL, /* startDocument */ - NULL, /* endDocument */ - NULL, /* startElement */ - NULL, /* endElement */ - NULL, /* reference */ - NULL, /* characters */ - NULL, /* ignorableWhitespace */ - NULL, /* processingInstruction */ - NULL, /* comment */ - NULL, /* xmlParserWarning */ - NULL, /* xmlParserError */ - NULL, /* xmlParserError */ - NULL, /* getParameterEntity */ - NULL, /* cdataBlock; */ - NULL, /* externalSubset; */ - 1 -}; - -xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; -extern xmlSAXHandlerPtr debugSAXHandler; - -/** - * startElementDebug: - * @ctxt: An XML parser context - * @name: The element name - * - * called when an opening tag has been processed. - */ -static void -startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) -{ - int i; - - fprintf(stdout, "SAX.startElement(%s", (char *) name); - if (atts != NULL) { - for (i = 0;(atts[i] != NULL);i++) { - fprintf(stdout, ", %s='", atts[i++]); - if (atts[i] != NULL) - fprintf(stdout, "%s'", atts[i]); - } - } - fprintf(stdout, ")\n"); -} - -static xmlEntityPtr -my_getEntity(void *user_data, const xmlChar *name) -{ - return xmlGetPredefinedEntity(name); -} - - -/** - * endElementDebug: - * @ctxt: An XML parser context - * @name: The element name - * - * called when the end of an element has been detected. - */ -static void -endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) -{ - fprintf(stdout, "SAX.endElement(%s)\n", (char *) name); -} - -static void -primaryStartElement(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) -{ -} +#include -static void -primaryEndElement(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) +struct myParser : public zypp::parser::SAXParser { -} - -struct SAXParserBase -{ - static void - startElement_receiver(void *ctx, const xmlChar *name, const xmlChar **atts) - { - SAXParserBase *rcv = (SAXParserBase *) ctx; - rcv->startElement(std::string( (const char*) name), atts); - } - - static void - endElement_receiver(void *ctx, const xmlChar *name) - { - SAXParserBase *rcv = (SAXParserBase *) ctx; - rcv->endElement(std::string( (const char*) name)); - } - - virtual void startElement(const std::string name, const xmlChar **atts) - { - MIL << name << std::endl; - } - - virtual void endElement(const std::string name) - { - MIL << name << std::endl; - } - - private: - xmlSAXHandler _saxHandler; - - public: - - void parseFile( const Pathname &p) - { - FILE *f = fopen(p.asString().c_str(), "r"); - if (f != NULL) - { - int res = xmlSAXUserParseFile(&_saxHandler, (void *) this, p.asString().c_str()); - if (res != 0) - { - fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); - } - fclose(f); - } - else - { - fprintf(stdout, "UPS\n"); - } - } - -// void parseFileByChunk( const Pathname &p) -// { -// FILE *f = fopen(p.asString().c_str(), "r"); -// if (f != NULL) -// { -// int ret; -// char chars[10]; -// xmlParserCtxtPtr ctxt; -// -// ret = fread(chars, 1, 4, f); -// if (ret > 0) -// { -// ctxt = xmlCreatePushParserCtxt(&_saxHandler, NULL, -// chars, ret, p.asString().c_str()); -// while ((ret = fread(chars, 1, 3, f)) > 0) -// { -// xmlParseChunk(ctxt, chars, ret, 0); -// } -// ret = xmlParseChunk(ctxt, chars, 0, 1); -// xmlFreeParserCtxt(ctxt); -// if (ret != 0) -// { -// fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", ret); -// } -// } -// fclose(f); -// } -// else -// { -// fprintf(stdout, "UPS\n"); -// } -// } - - SAXParserBase() - { - _saxHandler.internalSubset = NULL; - _saxHandler.isStandalone = NULL; - _saxHandler.hasInternalSubset = NULL; - _saxHandler.hasExternalSubset = NULL; - _saxHandler.resolveEntity = NULL; - _saxHandler.getEntity = NULL; - _saxHandler.entityDecl = NULL; - _saxHandler.notationDecl = NULL; - _saxHandler.attributeDecl = NULL; - _saxHandler.elementDecl = NULL; - _saxHandler.unparsedEntityDecl = NULL; - _saxHandler.setDocumentLocator = NULL; - _saxHandler.startDocument = NULL; - _saxHandler.endDocument = NULL; - _saxHandler.startElement = NULL; - _saxHandler.endElement = NULL; - _saxHandler.reference = NULL; - _saxHandler.characters = NULL; - _saxHandler.ignorableWhitespace = NULL; - _saxHandler.processingInstruction = NULL; - _saxHandler.comment = NULL; - - //_saxHandler.xmlParserWarning = NULL; - //_saxHandler.xmlParserError = NULL; - //_saxHandler.xmlParserError = NULL; - - _saxHandler.getParameterEntity = NULL; - _saxHandler.cdataBlock = NULL; - _saxHandler.externalSubset = NULL; - - _saxHandler = emptySAXHandlerStruct; - //_saxHandler.startDocument = startElement_receiver; - _saxHandler.startElement = startElement_receiver; - _saxHandler.endElement = endElement_receiver; - } - - virtual ~SAXParserBase() - { - } + }; - -struct myParser : public SAXParserBase -{ - -}; - - int main() { myParser parser; diff --git a/zypp/cache/SourceCache.h b/zypp/cache/SourceCache.h index 6c557ea..d63f262 100644 --- a/zypp/cache/SourceCache.h +++ b/zypp/cache/SourceCache.h @@ -44,6 +44,7 @@ namespace zypp /** Creates a source cache */ SourceCache( const Pathname &root_r, const std::string alias ); ~SourceCache(); + void cachePattern( const data::Pattern pattern ); void cachePackage( const data::Package package ); protected: diff --git a/zypp/data/Makefile.am b/zypp/data/Makefile.am index 45a1251..4a8bcc7 100644 --- a/zypp/data/Makefile.am +++ b/zypp/data/Makefile.am @@ -11,7 +11,8 @@ INCLUDES = -I$(oldincludedir)/libxml2 \ parserincludedir = $(pkgincludedir)/data parserinclude_HEADERS = \ - ResolvableData.h + ResolvableData.h \ + ResolvableDataConsumer.h noinst_LTLIBRARIES = lib@PACKAGE@_data.la diff --git a/zypp/data/ResolvableDataConsumer.h b/zypp/data/ResolvableDataConsumer.h new file mode 100644 index 0000000..5bbe988 --- /dev/null +++ b/zypp/data/ResolvableDataConsumer.h @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#ifndef ZYPP_ResolvableDataConsumer_H +#define ZYPP_ResolvableDataConsumer_H + + + +#include "zypp/data/ResolvableData.h" + + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// +namespace data +{ ///////////////////////////////////////////////////////////////// + + class ResolvableDataConsumer + { + public: + + ResolvableDataConsumer(); + virtual ~ResolvableDataConsumer(); + + virtual void consumePackage( const data::Package &package) = 0; + + }; + +} // namespace parser +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_SOURCE_ResolvableDataConsumer_H diff --git a/zypp/parser/Makefile.am b/zypp/parser/Makefile.am index f9db48e..5af534f 100644 --- a/zypp/parser/Makefile.am +++ b/zypp/parser/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## ################################################## -SUBDIRS = yum tagfile xmlstore +SUBDIRS = yum2 yum tagfile xmlstore INCLUDES = -I$(oldincludedir)/libxml2 \ -DZYPP_BASE_LOGGER_LOGGROUP=\"parser\" @@ -27,6 +27,7 @@ lib@PACKAGE@_parser_la_SOURCES = \ SAXParser.cc lib@PACKAGE@_parser_la_LIBADD = yum/lib@PACKAGE@_parser_yum.la \ + yum2/lib@PACKAGE@_parser_yum2.la \ -lxml2 \ -lz \ tagfile/lib@PACKAGE@_parser_tagfile.la \ diff --git a/zypp/parser/yum2/Makefile.am b/zypp/parser/yum2/Makefile.am new file mode 100644 index 0000000..117a406 --- /dev/null +++ b/zypp/parser/yum2/Makefile.am @@ -0,0 +1,23 @@ +## Process this file with automake to produce Makefile.in +## ################################################## + +SUBDIRS = + +INCLUDES = -I$(oldincludedir)/libxml2 -I.. \ + -DZYPP_BASE_LOGGER_LOGGROUP=\"parser-yum2\" + +## ################################################## + +parseryum2includedir = $(pkgincludedir)/parser/yum2 + +parseryum2include_HEADERS = \ + YUMPrimaryParser.h + +noinst_LTLIBRARIES = lib@PACKAGE@_parser_yum2.la + +## ################################################## + +lib@PACKAGE@_parser_yum2_la_SOURCES = \ + YUMPrimaryParser.cc + +## ################################################## diff --git a/zypp/parser/yum2/YUMPrimaryParser.cc b/zypp/parser/yum2/YUMPrimaryParser.cc new file mode 100644 index 0000000..a8a90ef --- /dev/null +++ b/zypp/parser/yum2/YUMPrimaryParser.cc @@ -0,0 +1,59 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + + +#include "zypp/parser/yum2/YUMPrimaryParser.h" +#include "zypp/data/ResolvableData.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// +namespace parser +{ ///////////////////////////////////////////////////////////////// +namespace yum2 +{ ///////////////////////////////////////////////////////////////// + + YUMPrimaryParser::YUMPrimaryParser( zypp::data::ResolvableDataConsumer &consumer ) + { + _consumer.reset(&consumer); + } + + void YUMPrimaryParser::startElement(const std::string name, const xmlChar **atts) + { + if ( name == "package" ) + _package.reset(new zypp::data::Package()); + } + + void YUMPrimaryParser::characters(const xmlChar *ch, int len) + { + //MIL << "append buffer :" << len << " [" << ( (len < 20) ? string((const char *)(ch), len) : "" ) << "]" << std::endl; + _buffer.append( (const char *)ch, len); + } + + void YUMPrimaryParser::endElement(const std::string name) + { + if ( name == "name" ) + _package->name = _buffer; + if ( name == "arch" ) + _package->arch = Arch(_buffer); + + if ( name == "package" ) + { + _consumer->consumePackage(*_package); + } + + _buffer.clear(); + } + + +} // namespace yum2 +} // namespace parser +} // namespace zypp +/////////////////////////////////////////////////////////////////// + diff --git a/zypp/parser/yum2/YUMPrimaryParser.h b/zypp/parser/yum2/YUMPrimaryParser.h new file mode 100644 index 0000000..6bf2c15 --- /dev/null +++ b/zypp/parser/yum2/YUMPrimaryParser.h @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#ifndef ZYPP_YUMPrimaryParser_H +#define ZYPP_YUMPrimaryParser_H + +#include "zypp/parser/SAXParser.h" +#include "zypp/data/ResolvableDataConsumer.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// +namespace parser +{ ///////////////////////////////////////////////////////////////// +namespace yum2 +{ ///////////////////////////////////////////////////////////////// + + class YUMPrimaryParser : public parser::SAXParser + { + public: + + YUMPrimaryParser( zypp::data::ResolvableDataConsumer &consumer ); + virtual void startElement(const std::string name, const xmlChar **atts); + virtual void characters(const xmlChar *ch, int len); + virtual void endElement(const std::string name); + + private: + shared_ptr _package; + shared_ptr _consumer; + std::string _buffer; + }; + + +} // namespace yum2 +} // namespace parser +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_SOURCE_YUMPrimaryParser_H diff --git a/zypp/source/yum/YUMSourceCacher.cc b/zypp/source/yum/YUMSourceCacher.cc index a7645f2..9fd58de 100644 --- a/zypp/source/yum/YUMSourceCacher.cc +++ b/zypp/source/yum/YUMSourceCacher.cc @@ -17,10 +17,11 @@ #include "zypp/parser/yum/YUMParser.h" #include "zypp/parser/SAXParser.h" +#include "zypp/parser/yum/YUMParser.h" +#include "zypp/parser/yum2/YUMPrimaryParser.h" #include "zypp/source/yum/YUMSourceCacher.h" using namespace std; -using namespace zypp::parser::yum; ////////////////////////////////////////////////////////////////// namespace zypp @@ -31,51 +32,6 @@ namespace yum { ///////////////////////////////////////////////////////////////// -class YUMPrimaryReader : public parser::SAXParser -{ - public: - YUMPrimaryReader( YUMSourceCacher &cacher ) - { - _cacher.reset(&cacher); - } - - virtual void startElement(const std::string name, const xmlChar **atts) - { - if ( name == "package" ) - _package.reset(new zypp::data::Package()); - } - - virtual void characters(const xmlChar *ch, int len) - { - _buffer.append( (const char *)ch, len); - } - - virtual void endElement(const std::string name) - { - if ( name == "name" ) - _package->name = popBuffer(); - if ( name == "arch" ) - _package->arch = Arch(popBuffer()); - - if ( name == "package" ) - { - _cacher->packageParsed(*_package); - } - } - - std::string popBuffer() - { - std::string rt = _buffer; - _buffer.clear(); - return rt; - } - - private: - shared_ptr _package; - shared_ptr _cacher; - std::string _buffer; -}; - YUMSourceCacher::YUMSourceCacher( const Pathname &root_r ) : zypp::cache::SourceCacher(root_r) { @@ -85,15 +41,15 @@ YUMSourceCacher::~YUMSourceCacher() { } -void YUMSourceCacher::packageParsed( const data::Package &package) +void YUMSourceCacher::consumePackage( const data::Package &package) { - MIL << "caching " << package << std::endl; + MIL << "caching " << package.name << " " << package.arch << std::endl; } void YUMSourceCacher::cache( const Url &url, const Pathname &path ) { filesystem::TmpDir tmpdir = downloadMetadata(url, path); - YUMPrimaryReader reader(*this); + parser::yum2::YUMPrimaryParser reader(*this); reader.parseFile( tmpdir.path() + "/repodata/primary.xml.gz"); } @@ -163,7 +119,7 @@ filesystem::TmpDir YUMSourceCacher::downloadMetadata(const Url &url, const Pathn DBG << "Reading file " << remote_repomd << endl; ifstream repo_st(remote_repomd.asString().c_str()); - YUMRepomdParser repomd(repo_st, ""); + parser::yum::YUMRepomdParser repomd(repo_st, ""); for(; ! repomd.atEnd(); ++repomd) { @@ -182,7 +138,7 @@ filesystem::TmpDir YUMSourceCacher::downloadMetadata(const Url &url, const Pathn Pathname patches_list = local_dir + (*repomd)->location; MIL << "Reading patches file " << patches_list << std::endl; ifgzstream st ( patches_list.asString().c_str() ); - YUMPatchesParser patch(st, ""); + parser::yum::YUMPatchesParser patch(st, ""); for (; !patch.atEnd(); ++patch) { diff --git a/zypp/source/yum/YUMSourceCacher.h b/zypp/source/yum/YUMSourceCacher.h index 1c2ce4a..08dba66 100644 --- a/zypp/source/yum/YUMSourceCacher.h +++ b/zypp/source/yum/YUMSourceCacher.h @@ -15,6 +15,7 @@ #include "zypp/cache/SourceCacher.h" #include "zypp/data/ResolvableData.h" +#include "zypp/data/ResolvableDataConsumer.h" #include "zypp/Pathname.h" #include "zypp/TmpPath.h" @@ -34,7 +35,7 @@ namespace zypp // // CLASS NAME : SourceCacher // - class YUMSourceCacher : public cache::SourceCacher + class YUMSourceCacher : public cache::SourceCacher, public data::ResolvableDataConsumer { friend std::ostream & operator<<( std::ostream & str, const YUMSourceCacher & obj ); @@ -44,7 +45,7 @@ namespace zypp ~YUMSourceCacher(); void cache( const Url &url, const Pathname &path ); - void packageParsed( const data::Package &package); + void consumePackage( const data::Package &package); protected: filesystem::TmpDir downloadMetadata(const Url &url, const Pathname &path);