Author: jkupec Date: Thu May 17 19:04:20 2007 New Revision: 5563 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5563&view=rev Log: backup - PatchFileReader almost done (TODO atom pkg-files, script, code review, clean-up/test/docs) Modified: trunk/libzypp/devel/devel.jkupec/YUMParser.cc trunk/libzypp/devel/devel.jkupec/YUMParser.h trunk/libzypp/zypp/parser/yum/FileReaderBase.h trunk/libzypp/zypp/parser/yum/PatchFileReader.cc trunk/libzypp/zypp/parser/yum/PatchFileReader.h trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h trunk/libzypp/zypp2/cache/CacheStore.cpp Modified: trunk/libzypp/devel/devel.jkupec/YUMParser.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/YUMParser.cc?rev=5563&r1=5562&r2=5563&view=diff ============================================================================== --- trunk/libzypp/devel/devel.jkupec/YUMParser.cc (original) +++ trunk/libzypp/devel/devel.jkupec/YUMParser.cc Thu May 17 19:04:20 2007 @@ -22,8 +22,6 @@ #undef ZYPP_BASE_LOGGER_LOGGROUP #define ZYPP_BASE_LOGGER_LOGGROUP "parser" -using std::endl; - namespace zypp { namespace parser @@ -46,9 +44,6 @@ : _consumer(consumer), _catalog_id(catalog_id) { - ZYpp::Ptr z = getZYpp(); -// _system_arch = z->architecture(); - _ticks.name("YUMParser"); _ticks.sendTo(progress); MIL << "constructed" << endl; Modified: trunk/libzypp/devel/devel.jkupec/YUMParser.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/YUMParser.h?rev=5563&r1=5562&r2=5563&view=diff ============================================================================== --- trunk/libzypp/devel/devel.jkupec/YUMParser.h (original) +++ trunk/libzypp/devel/devel.jkupec/YUMParser.h Thu May 17 19:04:20 2007 @@ -56,6 +56,8 @@ ); void start(const zypp::Pathname & path); + + private: void doJobs(const zypp::Pathname & path); bool repomd_CB(const OnMediaLocation & loc, const YUMResourceType & dtype); Modified: trunk/libzypp/zypp/parser/yum/FileReaderBase.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/FileReaderBase.h?rev=5563&r1=5562&r2=5563&view=diff ============================================================================== --- trunk/libzypp/zypp/parser/yum/FileReaderBase.h (original) +++ trunk/libzypp/zypp/parser/yum/FileReaderBase.h Thu May 17 19:04:20 2007 @@ -38,7 +38,10 @@ tag_NONE, tag_package, tag_format, - tag_atoms + tag_patch, + tag_atoms, + tag_script, + tag_message }; /** @@ -136,8 +139,10 @@ Dep _dtype; }; + /** \relates FileReaderBase::TagPath */ std::ostream & operator << (std::ostream & out, const FileReaderBase::TagPath & obj); + } // ns yum } // ns parser } // ns zypp Modified: trunk/libzypp/zypp/parser/yum/PatchFileReader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PatchFileReader.cc?rev=5563&r1=5562&r2=5563&view=diff ============================================================================== --- trunk/libzypp/zypp/parser/yum/PatchFileReader.cc (original) +++ trunk/libzypp/zypp/parser/yum/PatchFileReader.cc Thu May 17 19:04:20 2007 @@ -7,8 +7,6 @@ | | \---------------------------------------------------------------------*/ -#include <fstream> - #include "zypp/base/Logger.h" #include "zypp/parser/yum/PatchFileReader.h" @@ -38,10 +36,16 @@ bool PatchFileReader::consumeNode(Reader & reader_r) { + if (isBeingProcessed(tag_atoms) && consumeAtomsNode(reader_r)) + return true; + if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) { + // xpath: /patch if (reader_r->name() == "patch") { + tag(tag_patch); + _patch = new data::Patch; _patch->id = reader_r->getAttribute("patchid").asString(); @@ -50,12 +54,14 @@ return true; } + // xpath: /patch/yum:name if (reader_r->name() == "yum:name") { _patch->name = reader_r.nodeText().asString(); return true; } + // xpath: /patch/summary if (reader_r->name() == "summary") { Locale locale(reader_r->getAttribute("lang").asString()); @@ -63,6 +69,7 @@ return true; } + // xpath: /patch/description if (reader_r->name() == "description") { Locale locale(reader_r->getAttribute("lang").asString()); @@ -70,6 +77,7 @@ return true; } + // xpath: /patch/licence-to-confirm if (reader_r->name() == "license-to-confirm") { Locale locale(reader_r->getAttribute("lang").asString()); @@ -77,6 +85,7 @@ return true; } + // xpath: /patch/yum:version if (reader_r->name() == "yum:version") { _patch->edition = Edition(reader_r->getAttribute("ver").asString(), @@ -85,63 +94,267 @@ return true; } + // dependency block nodes if (consumeDependency(reader_r, _patch->deps)) return true; + // xpath: /patch/category if (reader_r->name() == "category") { _patch->category = reader_r.nodeText().asString(); return true; } + // xpath: /patch/reboot-needed if (reader_r->name() == "reboot-needed") { _patch->rebootNeeded = true; return true; } - + + // xpath: /patch/package-manager if (reader_r->name() == "package-manager") { _patch->affectsPkgManager = true; return true; } - // TODO update-script + // TODO xpath: /patch/update-script - // TODO atoms ((package|script|message)+)+ -/* if (reader_r->name() == "atoms") + // xpath: /patch/atoms + if (reader_r->name() == "atoms") { + // remember that we are processing atoms from now on + // xpath: /patch/atoms/* tag(tag_atoms); - return consumeAtomsNode(); + // no need to further process this node so not calling consumeAtomsNode(); + return true; } -*/ } else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT) { + // xpath: /patch if (reader_r->name() == "patch") { + // TODO some validation? e.g. _patch->atoms.size() > 0 + if (_callback) _callback(handoutPatch()); - + + toParentTag(); // just for the case of reuse somewhere/sometimes + return true; } -/* if (reader_r->name() == "atoms") + } + + return true; + } + + // -------------------------------------------------------------------------- + + bool PatchFileReader::consumeAtomsNode(Reader & reader_r) + { + // consumePackageNode + if (isBeingProcessed(tag_package)) + { + data::Package_Ptr package_ptr = zypp::dynamic_pointer_castdata::Package(_tmpResObj); + if (package_ptr && consumePackageNode(reader_r, package_ptr)) + return true; + } + // consumeMessageNode + else if (isBeingProcessed(tag_message) && consumeMessageNode(reader_r)) + return true; + // consumeScriptNode + else if (isBeingProcessed(tag_script) && consumeScriptNode(reader_r)) + return true; + + + if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) + { + // xpath: /patch/atoms/package + if (reader_r->name() == "package") + { + // remember that we are processing package from now on + // xpath: /patch/atoms/package/* + tag(tag_package); + // this object will be used by FileReaderBase::consumePackageNodes() + // which needs Package object, not Atom. But it will be saved as Atom + // after it's been filled. + data::Package_Ptr package = new data::Package; + consumePackageNode(reader_r, package); + _tmpResObj = package; + return true; + } + + // xpath: /patch/atoms/message + if (reader_r->name() == "message") { - toParent(tag_NONE); + tag(tag_message); + _tmpResObj = new data::Message; + return true; + } + + // xpath: /patch/atoms/script + if (reader_r->name() == "script") + { + tag(tag_script); + _tmpResObj = new data::Script; return true; } -*/ } + else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT) + { + // xpath: /patch/atoms/package + if (reader_r->name() == "package") + { + data::Atom_Ptr atom_ptr = new data::Atom; + copyAtomFromTmpObj(atom_ptr); + _patch->atoms.insert(atom_ptr); + + DBG << "Atom " << atom_ptr->name << " " << atom_ptr->edition << " successfully read." << endl; + + // get rid of the old package object + data::ResObject_Ptr tmp; + tmp.swap(_tmpResObj); + + toParentTag(); // back to processing of previous tag (atoms) + return true; + } + + // xpath: /patch/atoms/message + if (reader_r->name() == "message") + { + DBG << "Message " << _tmpResObj->name << " " << _tmpResObj->edition << " successfully read." << endl; + + saveAtomInPatch(); + toParentTag(); // back to processing of previous tag (atoms) + return true; + } + + // xpath: /patch/atoms/script + if (reader_r->name() == "script") + { + DBG << "Script " << _tmpResObj->name << " " << _tmpResObj->edition << " successfully read." << endl; + + saveAtomInPatch(); + toParentTag(); // back to processing of previous tag (atoms) + return true; + } + + // xpath: /patch/atoms + if (reader_r->name() == "atoms") + { + toParentTag(); // back to processing of previous tag (patch) + return true; + } + } + return true; } // -------------------------------------------------------------------------- -/* - bool PatchFileReader::consumeAtomsNode(Reader & reader_r) + +/* bool PatchFileReader::consumePackageNode(Reader & reader_r) { + data::Package_Ptr package_ptr = zypp::dynamic_pointer_castdata::Package(_tmpResObj); + if (package_ptr && consumePackageNode(reader_r, package_ptr)) + return true; + + if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) + { + // TODO package extensions -> pkg-files, license-to-confirm + if (reader_r->name() == "") + { + return true; + } + } + return true; } */ + // -------------------------------------------------------------------------- + + bool PatchFileReader::consumeMessageNode(Reader & reader_r) + { + if (FileReaderBase::consumeDependency(reader_r, _tmpResObj->deps)) + return true; + + if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) + { + // xpath: /patch/atoms/message/yum:name + if (reader_r->name() == "yum:name") + { + _tmpResObj->name = reader_r.nodeText().asString(); + return true; + } + + // xpath: /patch/atoms/message/yum:name + if (reader_r->name() == "yum:version") + { + _tmpResObj->edition = Edition(reader_r->getAttribute("ver").asString(), + reader_r->getAttribute("rel").asString(), + reader_r->getAttribute("epoch").asString()); + return true; + } + + // xpath: /patch/atoms/message//text + if (reader_r->name() == "text") + { + data::Message_Ptr message = dynamic_pointer_castdata::Message(_tmpResObj); + if (message) + message->text.setText( + reader_r.nodeText().asString(), + Locale(reader_r->getAttribute("lang").asString())); + return true; + } + } + + else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT) + { + // xpath: /patch/atoms/message + if (reader_r->name() == "message") + { + return false; + } + } + + return true; + } + + // -------------------------------------------------------------------------- + + bool PatchFileReader::consumeScriptNode(Reader & reader_r) + { + if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) + { + // xpath: /patch/atoms/script/yum:name + if (reader_r->name() == "yum:name") + { + _tmpResObj->name = reader_r.nodeText().asString(); + return true; + } + + // xpath: /patch/atoms/script/yum:version + if (reader_r->name() == "yum:version") + { + _tmpResObj->edition = Edition(reader_r->getAttribute("ver").asString(), + reader_r->getAttribute("rel").asString(), + reader_r->getAttribute("epoch").asString()); + return true; + } + } + + else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT) + { + // xpath: /patch/atoms/script + if (reader_r->name() == "script") + { + return false; + } + } + + return true; + } // -------------------------------------------------------------------------- @@ -152,10 +365,37 @@ return ret; } + // -------------------------------------------------------------------------- + + void PatchFileReader::saveAtomInPatch() + { + data::ResObject_Ptr tmp; + tmp.swap(_tmpResObj); + _patch->atoms.insert(tmp); + } + + // -------------------------------------------------------------------------- + + void PatchFileReader::copyAtomFromTmpObj(data::Atom_Ptr & atom_ptr) const + { + atom_ptr->name = _tmpResObj->name; + atom_ptr->edition = _tmpResObj->edition; + atom_ptr->arch = _tmpResObj->arch; + atom_ptr->deps = _tmpResObj->deps; + atom_ptr->vendor = _tmpResObj->vendor; + atom_ptr->installedSize = _tmpResObj->installedSize; + atom_ptr->buildTime = _tmpResObj->buildTime; + atom_ptr->installOnly = _tmpResObj->installOnly; + atom_ptr->summary = _tmpResObj->summary; + atom_ptr->description = _tmpResObj->description; + atom_ptr->licenseToConfirm = _tmpResObj->licenseToConfirm; + atom_ptr->insnotify = _tmpResObj->insnotify; + atom_ptr->delnotify = _tmpResObj->delnotify; + } + } // ns yum } // ns parser } // ns zypp // vim: set ts=2 sts=2 sw=2 et ai: - Modified: trunk/libzypp/zypp/parser/yum/PatchFileReader.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PatchFileReader.h?rev=5563&r1=5562&r2=5563&view=diff ============================================================================== --- trunk/libzypp/zypp/parser/yum/PatchFileReader.h (original) +++ trunk/libzypp/zypp/parser/yum/PatchFileReader.h Thu May 17 19:04:20 2007 @@ -40,15 +40,40 @@ */ PatchFileReader(const Pathname & patch_file, ProcessPatch callback); + private: + /** - * Callback provided to the XML parser. + * Callback provided to the XML reader. + * + * \param the xml reader object reading the file + * \return true to tell the reader to continue, false to tell it to stop + * + * \see PrimaryFileReader::consumeNode(xml::Reader) */ bool consumeNode(xml::Reader & reader_r); + /** + * Process atoms node and all of its children. + * + * \return true if current node has been completely processed, false + * if additional processing is required outside of the method. + */ + bool consumeAtomsNode(xml::Reader & reader_r); - private: + bool consumeMessageNode(xml::Reader & reader_r); + + bool consumeScriptNode(xml::Reader & reader_r); + + /** + * Creates a new \ref data::Patch_Ptr, swaps its contents with \ref _patch + * and returns it. Used to hand-out the data object to its consumer + * (a \ref ProcessPatch function) after it has been read. + */ data::Patch_Ptr handoutPatch(); + void saveAtomInPatch(); + + void copyAtomFromTmpObj(data::Atom_Ptr & atom_ptr) const; private: /** @@ -61,6 +86,9 @@ * metada (except of depencencies). */ data::Patch_Ptr _patch; + + /** Pointer to an atom currently being read. */ + data::ResObject_Ptr _tmpResObj; }; Modified: trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h?rev=5563&r1=5562&r2=5563&view=diff ============================================================================== --- trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h (original) +++ trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h Thu May 17 19:04:20 2007 @@ -60,14 +60,27 @@ const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc()); /** - * Callback provided to the XML parser. + * Callback provided to the XML reader. + * + * This is the main parsing method which gets envoked by the \ref xml::Reader + * to process each node, one at a time. It is responsible for parsing the + * node and calling all other consume* methods. + * + * \param the xml reader object reading the file + * \return true to tell the reader to continue, false to tell it to stop + * + * \note Semantics of this method's return value also differs from other + * consume* methods. While this method's return value tells the the + * xml reader to continue or stop, return value of the rest tells + * their callers if further */ bool consumeNode(xml::Reader & reader_r); private: /** - * Creates a new Package_Ptr swaps its contents with \ref _package and - * returns it. + * Creates a new \ref data::Package_Ptr, swaps its contents with \ref + * _package and returns it. Used to hand-out the data object to its consumer + * (a \ref ProcessPackage function) after it has been read. */ data::Package_Ptr handoutPackage(); Modified: trunk/libzypp/zypp2/cache/CacheStore.cpp URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/cache/CacheStore.cpp?rev=5563&r1=5562&r2=5563&view=diff ============================================================================== --- trunk/libzypp/zypp2/cache/CacheStore.cpp (original) +++ trunk/libzypp/zypp2/cache/CacheStore.cpp Thu May 17 19:04:20 2007 @@ -211,6 +211,33 @@ RecordId id = appendResolvable( catalog_id, ResTraits<Patch>::kind, NVRA( patch->name, patch->edition, patch->arch ), patch->deps ); consumeResObject( id, patch ); + /* + DBG << "got patch " << patch->name << ", atoms: "; + for (setdata::ResObject_Ptr::const_iterator p = patch->atoms.begin(); + p != patch->atoms.end(); ++p) + { + data::Atom_Ptr atom = dynamic_pointer_castdata::Atom(*p); + if (atom) + { + DBG << atom->name << "(atom) "; + continue; + } + data::Script_Ptr script = dynamic_pointer_castdata::Script(*p); + if (script) + { + DBG << script->name << "(script) "; + continue; + } + data::Message_Ptr message = dynamic_pointer_castdata::Message(*p); + if (message) + { + DBG << message->name << "(message) "; + continue; + } + DBG << "!badatom! "; + } + DBG << endl; + */ } void CacheStore::consumeMessage( const data::RecordId &catalog_id, data::Message_Ptr message ) -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org