}
- bool YUMParser::patch_CB(const zypp::data::Patch & patch)
+ bool YUMParser::patch_CB(const data::Patch_Ptr & patch)
{
_consumer.consumePatch( _catalog_id, patch );
-
+
MIL << "got patch "
- << patch.name << patch.edition << " "
- << patch.arch
+ << patch->name << patch->edition << " "
+ << patch->arch
<< endl;
return true;
bool repomd_CB(const OnMediaLocation & loc, const YUMResourceType & dtype);
bool primary_CB(const data::Package_Ptr & package_r);
bool patches_CB(const OnMediaLocation &loc, const std::string & patch_id);
- bool patch_CB(const zypp::data::Patch & patch);
+ bool patch_CB(const data::Patch_Ptr & patch);
private:
zypp::cache::CacheStore & _consumer;
parser/yum/YUMPrimaryParser.cc
parser/yum/YUMProductParser.cc
parser/yum/YUMRepomdParser.cc
+ parser/yum/FileReaderBase.cc
parser/yum/RepomdFileReader.cc
parser/yum/PatchesFileReader.cc
parser/yum/PrimaryFileReader.cc
parser/yum/YUMPrimaryParser.h
parser/yum/YUMProductParser.h
parser/yum/YUMRepomdParser.h
+ parser/yum/FileReaderBase.h
parser/yum/RepomdFileReader.h
parser/yum/PatchesFileReader.h
parser/yum/PrimaryFileReader.h
{
public:
Patch()
+ : rebootNeeded(false), affectsPkgManager(false)
{};
/** Patch ID */
Date timestamp;
/** Patch category (recommended, security,...) */
std::string category;
-
+
// Flags:
/** Does the system need to reboot to finish the update process? */
DefaultIntegral<bool,false> rebootNeeded;
/** Does the patch affect the package manager itself? */
DefaultIntegral<bool,false> affectsPkgManager;
-
+
/** The list of all atoms building the patch.
* \todo See whether we need this.
- */
+ */
std::set<RecordId> atomList;
};
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+#include <iosfwd>
+
+#include "zypp/base/Logger.h"
+#include "zypp/base/Function.h"
+#include "zypp/Arch.h"
+#include "zypp/Edition.h"
+#include "zypp/TranslatedText.h"
+#include "zypp/ByteCount.h"
+
+#include "zypp/parser/yum/FileReaderBase.h"
+
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "parser"
+
+using namespace std;
+using namespace zypp::xml;
+
+namespace zypp
+{
+ namespace parser
+ {
+ namespace yum
+ {
+
+
+ FileReaderBase::FileReaderBase()
+ : _expect_rpm_entry(false), _dtype(zypp::Dep::REQUIRES)
+ {}
+
+ // --------------------------------------------------------------------------
+
+ bool FileReaderBase::consumePackageNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr)
+ {
+ //DBG << "**node: " << reader_r->name() << " (" << reader_r->nodeType() << ") tagpath = " << _tagpath << endl;
+ if (isBeingProcessed(tag_format) && consumeFormatNode(reader_r, package_ptr))
+ return true;
+
+ if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
+ {
+ if (reader_r->name() == "name")
+ {
+ package_ptr->name = reader_r.nodeText().asString();
+ return true;
+ }
+
+ if (reader_r->name() == "arch")
+ {
+ //if (arch == "src" || arch == "nosrc") arch = "noarch";
+ package_ptr->arch = Arch(reader_r.nodeText().asString());
+ return true;
+ }
+
+ if (reader_r->name() == "version")
+ {
+ package_ptr->edition = Edition(reader_r->getAttribute("ver").asString(),
+ reader_r->getAttribute("rel").asString(),
+ reader_r->getAttribute("epoch").asString());
+ return true;
+ }
+
+ if (reader_r->name() == "checksum")
+ {
+ package_ptr->repositoryLocation.fileChecksum = CheckSum(
+ reader_r->getAttribute("type").asString(),
+ reader_r.nodeText().asString());
+ // ignoring pkgid attribute
+ return true;
+ }
+
+ if (reader_r->name() == "summary")
+ {
+ package_ptr->summary.setText(
+ reader_r.nodeText().asString(),
+ Locale(reader_r->getAttribute("lang").asString()));
+ return true;
+ }
+
+ if (reader_r->name() == "description")
+ {
+ package_ptr->description.setText(
+ reader_r.nodeText().asString(),
+ Locale(reader_r->getAttribute("lang").asString()));
+ return true;
+ }
+
+ if (reader_r->name() == "packager")
+ {
+ package_ptr->packager = reader_r.nodeText().asString();
+// DBG << "packager: " << package_ptr->packager << endl;
+ return true;
+ }
+
+ if (reader_r->name() == "url")
+ {
+// DBG << "url: " << reader_r.nodeText().asString() << endl;
+ package_ptr->url = reader_r.nodeText().asString();
+ return true;
+ }
+
+ if (reader_r->name() == "time")
+ {
+ package_ptr->buildTime = reader_r->getAttribute("build").asString();
+ // ignoring reader_r->getAttribute("file").asString(); (rpm file timestamp)
+ return true;
+ }
+
+ if (reader_r->name() == "size")
+ {
+ // ???
+ // reader_r->getAttribute("archive").asString();
+
+ // installed size
+ package_ptr->installedSize = str::strtonum<ByteCount::SizeType>( reader_r->getAttribute("installed").asString() );
+
+ // rpm package size
+ package_ptr->repositoryLocation.fileSize = str::strtonum<ByteCount::SizeType>( reader_r->getAttribute("package").asString() );
+
+ return true;
+ }
+
+ if (reader_r->name() == "location")
+ {
+ package_ptr->repositoryLocation.filePath = reader_r->getAttribute("href").asString();
+ return true;
+ }
+
+ if (reader_r->name() == "format")
+ {
+ tag(tag_format);
+ return true;
+ }
+ }
+
+ else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
+ {
+ if (reader_r->name() == "package")
+ {
+ // indicate that further processing is required
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ // --------------( consume <format> tag )------------------------------------
+
+ bool FileReaderBase::consumeFormatNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr)
+ {
+ if (consumeDependency(reader_r, package_ptr->deps))
+ // this node has been a dependency, which has been handled by
+ // consumeDependency(), so return right away.
+ return true;
+
+// DBG << "format subtag: " << reader_r->name() << endl;
+ if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
+ {
+ if (reader_r->name() == "rpm:license")
+ {
+ package_ptr->license = reader_r.nodeText().asString();
+ return true;
+ }
+
+ if (reader_r->name() == "rpm:vendor")
+ {
+ package_ptr->vendor = reader_r.nodeText().asString();
+ return true;
+ }
+
+ if (reader_r->name() == "rpm:group")
+ {
+ package_ptr->group = reader_r.nodeText().asString();
+ return true;
+ }
+
+ if (reader_r->name() == "rpm:buildhost")
+ {
+ package_ptr->buildhost = reader_r.nodeText().asString();
+ return true;
+ }
+
+ if (reader_r->name() == "rpm:sourcerpm")
+ {
+ //package->source = reader_r.nodeText().asString();
+ return true;
+ }
+
+ if (reader_r->name() == "rpm:header-range")
+ {
+ //reader_r->getAttribute("start").asString(),
+ //reader_r->getAttribute("end").asString(),
+ return true;
+ }
+
+ if (reader_r->name() == "file")
+ {
+ // TODO figure out how to read files
+ // file = reader_r.nodeText().asString();
+ // type = reader_r->getAttribute("type").asString();
+ return true;
+ }
+ }
+ else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
+ {
+ if (reader_r->name() == "format")
+ {
+ toParentTag();
+ return true;
+ }
+ }
+
+ return true;
+ }
+
+
+ bool FileReaderBase::consumeDependency(xml::Reader & reader_r, data::Dependencies & deps_r)
+ {
+ if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
+ {
+ if (reader_r->name() == "rpm:entry")
+ {
+ if (!_expect_rpm_entry)
+ {
+ // TODO make this a ParseException (once created/taken out of tagfile ns?)
+ ZYPP_THROW(Exception("rpm:entry found when not expected"));
+ }
+
+ Edition edition(
+ reader_r->getAttribute("ver").asString(),
+ reader_r->getAttribute("rel").asString(),
+ reader_r->getAttribute("epoch").asString()
+ );
+/*
+ DBG << "got rpm:entry for " << _dtype << ": "
+ << reader_r->getAttribute("name").asString()
+ << " " << edition << endl;
+*/
+ deps_r[_dtype].insert(
+ zypp::capability::parse(
+ ResTraits<Package>::kind,
+ reader_r->getAttribute("name").asString(),
+ Rel(reader_r->getAttribute("flags").asString()),
+ edition
+ )
+ );
+ }
+
+ if (reader_r->name() == "rpm:provides")
+ {
+ _dtype = zypp::Dep::PROVIDES;
+ _expect_rpm_entry = true;
+ return true;
+ }
+ if (reader_r->name() == "rpm:conflicts")
+ {
+ _dtype = zypp::Dep::CONFLICTS;
+ _expect_rpm_entry = true;
+ return true;
+ }
+ if (reader_r->name() == "rpm:obsoletes")
+ {
+ _dtype = zypp::Dep::OBSOLETES;
+ _expect_rpm_entry = true;
+ return true;
+ }
+ if (reader_r->name() == "rpm:requires")
+ {
+ _dtype = zypp::Dep::REQUIRES;
+ _expect_rpm_entry = true;
+ return true;
+ }
+ if (reader_r->name() == "rpm:recommends")
+ {
+ _dtype = zypp::Dep::RECOMMENDS;
+ _expect_rpm_entry = true;
+ return true;
+ }
+ if (reader_r->name() == "rpm:enhances")
+ {
+ _dtype = zypp::Dep::ENHANCES;
+ _expect_rpm_entry = true;
+ return true;
+ }
+ if (reader_r->name() == "rpm:supplements")
+ {
+ _dtype = zypp::Dep::SUPPLEMENTS;
+ _expect_rpm_entry = true;
+ return true;
+ }
+ if (reader_r->name() == "rpm:suggests")
+ {
+ _dtype = zypp::Dep::SUGGESTS;
+ _expect_rpm_entry = true;
+ return true;
+ }
+ if (reader_r->name() == "rpm:suggests")
+ {
+ _dtype = zypp::Dep::SUGGESTS;
+ _expect_rpm_entry = true;
+ return true;
+ }
+ }
+ else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
+ {
+ if (reader_r->name() == "rpm:requires"
+ || reader_r->name() == "rpm:provides"
+ || reader_r->name() == "rpm:conflicts"
+ || reader_r->name() == "rpm:obsoletes"
+ || reader_r->name() == "rpm:recommends"
+ || reader_r->name() == "rpm:enhances"
+ || reader_r->name() == "rpm:supplements"
+ || reader_r->name() == "rpm:suggests")
+ {
+ _expect_rpm_entry = false;
+ return true;
+ }
+ }
+
+ // tell the caller this has not been a dependency tag (i.e. not processed)
+ return false;
+ }
+
+
+ std::ostream & operator << (std::ostream & out, const FileReaderBase::TagPath & obj)
+ {
+ out << "(";
+
+ if (obj.depth())
+ {
+ FileReaderBase::TagPath::TagList::const_iterator p = obj.path.begin();
+ out << *p;
+ ++p;
+
+ for (; p != obj.path.end(); ++p)
+ out << "," << *p;
+ }
+ else
+ out << "empty";
+
+ out << ")";
+
+ return out;
+ }
+
+
+ }
+ }
+}
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef ZYPP_PARSER_YUM_FILEREADERBASE_H_
+#define ZYPP_PARSER_YUM_FILEREADERBASE_H_
+
+#include "zypp/base/NonCopyable.h"
+#include "zypp/parser/xml/Reader.h"
+#include "zypp/data/ResolvableData.h"
+
+
+namespace zypp
+{
+ namespace parser
+ {
+ namespace yum
+ {
+
+
+ /**
+ * Class implementing parsing methods for common metadata.
+ */
+ class FileReaderBase : private base::NonCopyable
+ {
+ public:
+
+ /**
+ * Enumeration of some YUM metadata xml tags.
+ */
+ enum Tag
+ {
+ tag_NONE,
+ tag_package,
+ tag_format,
+ tag_atoms
+ };
+
+ /**
+ * Lightweight object for remembering currently processed tag.
+ *
+ * Usage:
+ *
+ * - call \ref append() on opening tag
+ * - use \ref contains() to check if the given tag is being processed
+ * - call \ref remove() on closing tag
+ *
+ * \note the above works only if the path elements are unique. To support
+ * also non-unique elements, an equals() method will need to be implemented
+ * and used instead of \ref contains().
+ *
+ * \note tags you want to use with TagPath must be enumerated in \ref Tag
+ * enum.
+ */
+ struct TagPath
+ {
+ typedef std::list<Tag> TagList;
+
+ void append(const Tag tag) { path.push_back(tag); }
+ void remove() { if (!path.empty()) path.pop_back(); }
+ unsigned depth() const { return path.size(); }
+ Tag currentTag() const
+ {
+ if (!path.empty()) return path.back();
+ return tag_NONE;
+ }
+ bool contains(const Tag tag) const
+ {
+ TagList::const_iterator result = find(path.begin(), path.end(), tag);
+ return result != path.end();
+ }
+
+ TagList path;
+ };
+
+ public:
+
+ FileReaderBase();
+ virtual ~FileReaderBase() {}
+
+ /**
+ * Process package node and its subtree.
+ * This method can be extended for specific implementations.
+ *
+ * \return true if the package node or current subnode has been consumed
+ * (no further processing is required), false otherwise.
+ */
+ virtual bool consumePackageNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr);
+
+ /**
+ * Function for processing all <code>format</code> tag subtree nodes.
+ *
+ * \return true if the package node or current subnode has been consumed
+ * (no further processing is required), false otherwise.
+ */
+ bool consumeFormatNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr);
+
+ /**
+ * Processes RPM dependency tags (rpm:entry, rpm:requires, ...).
+ *
+ * \return true if a dependency tag has been encountered, false otherwise.
+ */
+ bool consumeDependency(xml::Reader & reader_r, data::Dependencies & deps_r);
+
+
+ public:
+ /** Appends \a tag to \ref _tagpath. */
+ void tag(const Tag tag) { _tagpath.append(tag); }
+
+ /** Check whether we are currently processing given \a tag. */
+ bool isBeingProcessed(Tag tag) const { return _tagpath.contains(tag); }
+
+ /** Move to parent tag in the \ref _tagpath. */
+ void toParentTag() { _tagpath.remove(); }
+
+
+ private:
+
+ /** Used to remember the tag beeing currently processed. */
+ TagPath _tagpath;
+
+ /**
+ * Used to remember whether we are expecting an rpm:entry tag
+ * e.g. for rpm:requires
+ */
+ bool _expect_rpm_entry;
+
+ /**
+ * Type of dependecy beeing processed.
+ */
+ Dep _dtype;
+ };
+
+ std::ostream & operator << (std::ostream & out, const FileReaderBase::TagPath & obj);
+
+ } // ns yum
+ } // ns parser
+} // ns zypp
+
+
+#endif /*ZYPP_PARSER_YUM_FILEREADERBASE_H_*/
#include <fstream>
+#include "zypp/base/Logger.h"
#include "zypp/parser/yum/PatchFileReader.h"
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "parser"
+
using namespace std;
using namespace zypp::xml;
PatchFileReader::PatchFileReader(const Pathname & patch_file, ProcessPatch callback)
- : _callback(callback), _patch(NULL)
+ : _callback(callback)
{
Reader reader(patch_file);
MIL << "Reading " << patch_file << endl;
reader.foreachNode(bind(&PatchFileReader::consumeNode, this, _1));
}
+ // --------------------------------------------------------------------------
bool PatchFileReader::consumeNode(Reader & reader_r)
{
{
if (reader_r->name() == "patch")
{
- if (_patch) delete _patch;
- _patch = new zypp::data::Patch();
+ _patch = new data::Patch;
_patch->id = reader_r->getAttribute("patchid").asString();
_patch->timestamp = Date(reader_r->getAttribute("timestamp").asString());
+ // reader_r->getAttribute("timestamp").asString() ?
return true;
}
+
if (reader_r->name() == "yum:name")
{
_patch->name = reader_r.nodeText().asString();
return true;
}
+
+ if (reader_r->name() == "summary")
+ {
+ Locale locale(reader_r->getAttribute("lang").asString());
+ _patch->summary.setText(reader_r.nodeText().asString(), locale);
+ return true;
+ }
+
+ if (reader_r->name() == "description")
+ {
+ Locale locale(reader_r->getAttribute("lang").asString());
+ _patch->description.setText(reader_r.nodeText().asString(), locale);
+ return true;
+ }
+
+ if (reader_r->name() == "license-to-confirm")
+ {
+ Locale locale(reader_r->getAttribute("lang").asString());
+ _patch->licenseToConfirm.setText(reader_r.nodeText().asString(), locale);
+ return true;
+ }
+
+ if (reader_r->name() == "yum:version")
+ {
+ _patch->edition = Edition(reader_r->getAttribute("ver").asString(),
+ reader_r->getAttribute("rel").asString(),
+ reader_r->getAttribute("epoch").asString());
+ return true;
+ }
+
+ if (consumeDependency(reader_r, _patch->deps))
+ return true;
+
+ if (reader_r->name() == "category")
+ {
+ _patch->category = reader_r.nodeText().asString();
+ return true;
+ }
+
+ if (reader_r->name() == "reboot-needed")
+ {
+ _patch->rebootNeeded = true;
+ return true;
+ }
+
+ if (reader_r->name() == "package-manager")
+ {
+ _patch->affectsPkgManager = true;
+ return true;
+ }
+
+ // TODO update-script
+
+ // TODO atoms ((package|script|message)+)+
+/* if (reader_r->name() == "atoms")
+ {
+ tag(tag_atoms);
+ return consumeAtomsNode();
+ }
+*/
}
else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
{
if (reader_r->name() == "patch")
{
- _callback(*_patch);
- if (_patch)
- {
- delete _patch;
- _patch = NULL;
- }
+ if (_callback)
+ _callback(handoutPatch());
+
+ return true;
+ }
+/* if (reader_r->name() == "atoms")
+ {
+ toParent(tag_NONE);
return true;
}
+*/
}
return true;
}
+ // --------------------------------------------------------------------------
+/*
+ bool PatchFileReader::consumeAtomsNode(Reader & reader_r)
+ {
+ return true;
+ }
+*/
+
+ // --------------------------------------------------------------------------
+
+ data::Patch_Ptr PatchFileReader::handoutPatch()
+ {
+ data::Patch_Ptr ret;
+ ret.swap(_patch);
+ return ret;
+ }
+
} // ns yum
} // ns parser
} // ns zypp
// vim: set ts=2 sts=2 sw=2 et ai:
+
#define PATCHFILEREADER_H_
#include "zypp/base/Function.h"
-#include "zypp/base/Logger.h"
#include "zypp/parser/xml/Reader.h"
+#include "zypp/parser/yum/FileReaderBase.h"
#include "zypp/data/ResolvableData.h"
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser"
-
namespace zypp
{
namespace parser
/**
*
*/
- class PatchFileReader
+ class PatchFileReader : FileReaderBase
{
public:
/**
* Callback definition.
*/
- typedef function<bool(const zypp::data::Patch &)> ProcessPatch;
+ typedef function<bool(const data::Patch_Ptr &)> ProcessPatch;
/**
*
/**
* Callback provided to the XML parser.
*/
- bool consumeNode(zypp::xml::Reader & reader_r);
+ bool consumeNode(xml::Reader & reader_r);
+
+
+ private:
+ data::Patch_Ptr handoutPatch();
+
private:
/**
* Pointer to the \ref zypp::data::Patch object for storing the patch
* metada (except of depencencies).
*/
- zypp::data::Patch *_patch;
-
- /**
- * A map of lists of strings for storing dependencies.
- *
- * \see zypp::data::Dependencies
- */
- zypp::data::Dependencies _deps;
+ data::Patch_Ptr _patch;
};
- }
- }
-}
+ } // ns yum
+ } // ns parser
+} // ns zypp
#endif /*PATCHFILEREADER_H_*/
\---------------------------------------------------------------------*/
#include "zypp/base/Logger.h"
+
#include "zypp/parser/yum/PrimaryFileReader.h"
-#include "zypp/Arch.h"
-#include "zypp/Edition.h"
-#include "zypp/TranslatedText.h"
-#include "zypp/ByteCount.h"
#undef ZYPP_BASE_LOGGER_LOGGROUP
#define ZYPP_BASE_LOGGER_LOGGROUP "parser"
const ProcessPackage & callback,
const ProgressData::ReceiverFnc & progress)
:
- _callback(callback), _package(NULL),
- _count(0),
- _tag(tag_NONE), _expect_rpm_entry(false),
- _dtype(zypp::Dep::REQUIRES)
+ _callback(callback)
{
_ticks.sendTo(progress);
- Reader reader( primary_file );
+ Reader reader(primary_file);
MIL << "Reading " << primary_file << endl;
- reader.foreachNode( bind( &PrimaryFileReader::consumeNode, this, _1 ) );
+ reader.foreachNode(bind( &PrimaryFileReader::consumeNode, this, _1 ));
}
+ // --------------------------------------------------------------------------
+
bool PrimaryFileReader::consumeNode(Reader & reader_r)
{
// DBG << "**node: " << reader_r->name() << " (" << reader_r->nodeType() << ")" << endl;
- if (_tag == tag_format)
- return consumeFormatChildNodes(reader_r);
+ if (isBeingProcessed(tag_package) && consumePackageNode(reader_r, _package))
+ return true;
+
if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
{
_ticks.toMin();
return true;
}
+
if (reader_r->name() == "package")
{
- _tag = tag_package;
+ tag(tag_package);
// DBG << "got " << reader_r->getAttribute("type") << " package" << endl;
_package = new data::Package;
- return true;
- }
-
- if (reader_r->name() == "name")
- {
- _package->name = reader_r.nodeText().asString();
- return true;
- }
-
- if (reader_r->name() == "arch")
- {
- //if (arch == "src" || arch == "nosrc") arch = "noarch";
- _package->arch = Arch(reader_r.nodeText().asString());
- return true;
- }
-
- if (reader_r->name() == "version")
- {
- _package->edition = Edition(reader_r->getAttribute("ver").asString(),
- reader_r->getAttribute("rel").asString(),
- reader_r->getAttribute("epoch").asString());
- return true;
- }
-
- if (reader_r->name() == "checksum")
- {
- _package->repositoryLocation.fileChecksum = CheckSum(reader_r->getAttribute("type").asString(),
- reader_r.nodeText().asString());
- // ignoring pkgid attribute
- return true;
- }
-
- if (reader_r->name() == "summary")
- {
- _package->summary.setText(
- reader_r.nodeText().asString(),
- Locale(reader_r->getAttribute("lang").asString()));
- return true;
- }
-
- if (reader_r->name() == "description")
- {
- _package->description.setText(
- reader_r.nodeText().asString(),
- Locale(reader_r->getAttribute("lang").asString()));
- return true;
- }
-
- if (reader_r->name() == "packager")
- {
- _package->packager = reader_r.nodeText().asString();
-// DBG << "packager: " << _package->packager << endl;
- return true;
- }
-
- if (reader_r->name() == "url")
- {
-// DBG << "url: " << reader_r.nodeText().asString() << endl;
- _package->url = reader_r.nodeText().asString();
- return true;
- }
-
- if (reader_r->name() == "time")
- {
- _package->buildTime = reader_r->getAttribute("build").asString();
- // ignoring reader_r->getAttribute("file").asString(); (rpm file timestamp)
- return true;
- }
-
- if (reader_r->name() == "size")
- {
- // ???
- // reader_r->getAttribute("archive").asString();
-
- // installed size
- _package->installedSize = str::strtonum<ByteCount::SizeType>( reader_r->getAttribute("installed").asString() );
-
- // rpm package size
- _package->repositoryLocation.fileSize = str::strtonum<ByteCount::SizeType>( reader_r->getAttribute("package").asString() );
-
- return true;
- }
-
- if (reader_r->name() == "location")
- {
- _package->repositoryLocation.filePath = reader_r->getAttribute("href").asString();
- return true;
- }
-
- if (reader_r->name() == "format")
- {
- _tag = tag_format;
- return true;
+ return consumePackageNode(reader_r, _package);
}
}
+
else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
{
if (reader_r->name() == "package")
if (_package && _callback)
_callback(handoutPackage());
- _ticks.set(_count++);
+ _ticks.incr();
- _tag = tag_NONE;
+ toParentTag();
return true;
}
+
if (reader_r->name() == "metadata")
{
_ticks.toMax();
- }
- }
-
- return true;
- }
-
-
- // --------------( consume <format> tag )------------------------------------
-
- bool PrimaryFileReader::consumeFormatChildNodes(Reader & reader_r)
- {
-// DBG << "format subtag: " << reader_r->name() << endl;
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- if (reader_r->name() == "rpm:entry")
- {
- if (!_expect_rpm_entry)
- {
- // TODO make this a ParseException (once created/taken out of tagfile ns?)
- ZYPP_THROW(Exception("rpm:entry found when not expected"));
- }
-
- Edition edition(
- reader_r->getAttribute("ver").asString(),
- reader_r->getAttribute("rel").asString(),
- reader_r->getAttribute("epoch").asString()
- );
-/*
- DBG << "got rpm:entry for " << _dtype << ": "
- << reader_r->getAttribute("name").asString()
- << " " << edition << endl;
-*/
- _package->deps[_dtype].insert(
- zypp::capability::parse(
- ResTraits<Package>::kind,
- reader_r->getAttribute("name").asString(),
- Rel(reader_r->getAttribute("flags").asString()),
- edition
- )
- );
- }
-
- if (reader_r->name() == "rpm:license")
- {
- _package->license = reader_r.nodeText().asString();
- return true;
- }
-
- if (reader_r->name() == "rpm:vendor")
- {
- _package->vendor = reader_r.nodeText().asString();
- return true;
- }
-
- if (reader_r->name() == "rpm:group")
- {
- _package->group = reader_r.nodeText().asString();
- return true;
- }
-
- if (reader_r->name() == "rpm:buildhost")
- {
- _package->buildhost = reader_r.nodeText().asString();
- return true;
- }
-
- if (reader_r->name() == "rpm:sourcerpm")
- {
- //package->source = reader_r.nodeText().asString();
- return true;
- }
-
- if (reader_r->name() == "rpm:header-range")
- {
- //reader_r->getAttribute("start").asString(),
- //reader_r->getAttribute("end").asString(),
- return true;
- }
-
- if (reader_r->name() == "rpm:provides")
- {
- _dtype = zypp::Dep::PROVIDES;
- _expect_rpm_entry = true;
- return true;
- }
- if (reader_r->name() == "rpm:conflicts")
- {
- _dtype = zypp::Dep::CONFLICTS;
- _expect_rpm_entry = true;
- return true;
- }
- if (reader_r->name() == "rpm:obsoletes")
- {
- _dtype = zypp::Dep::OBSOLETES;
- _expect_rpm_entry = true;
- return true;
- }
- if (reader_r->name() == "rpm:requires")
- {
- _dtype = zypp::Dep::REQUIRES;
- _expect_rpm_entry = true;
- return true;
- }
- if (reader_r->name() == "rpm:recommends")
- {
- _dtype = zypp::Dep::RECOMMENDS;
- _expect_rpm_entry = true;
- return true;
- }
- if (reader_r->name() == "rpm:enhances")
- {
- _dtype = zypp::Dep::ENHANCES;
- _expect_rpm_entry = true;
- return true;
- }
- if (reader_r->name() == "rpm:supplements")
- {
- _dtype = zypp::Dep::SUPPLEMENTS;
- _expect_rpm_entry = true;
- return true;
- }
- if (reader_r->name() == "rpm:suggests")
- {
- _dtype = zypp::Dep::SUGGESTS;
- _expect_rpm_entry = true;
- return true;
- }
- if (reader_r->name() == "rpm:suggests")
- {
- _dtype = zypp::Dep::SUGGESTS;
- _expect_rpm_entry = true;
- return true;
- }
-
- if (reader_r->name() == "file")
- {
- // TODO figure out how to read files
- // file = reader_r.nodeText().asString();
- // type = reader_r->getAttribute("type").asString();
return true;
}
}
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- if (reader_r->name() == "rpm:requires"
- || reader_r->name() == "rpm:provides"
- || reader_r->name() == "rpm:conflicts"
- || reader_r->name() == "rpm:obsoletes"
- || reader_r->name() == "rpm:recommends"
- || reader_r->name() == "rpm:enhances"
- || reader_r->name() == "rpm:supplements"
- || reader_r->name() == "rpm:suggests")
- {
- _expect_rpm_entry = false;
- return true;
- }
- if (reader_r->name() == "format")
- {
- _tag = tag_package;
- return true;
- }
- }
return true;
}
+ // --------------------------------------------------------------------------
+
data::Package_Ptr PrimaryFileReader::handoutPackage()
{
data::Package_Ptr ret;
return ret;
}
+
} // ns yum
} // ns parser
} //ns zypp
#define ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H
#include "zypp/base/Function.h"
-#include "zypp/base/Logger.h"
#include "zypp/parser/xml/Reader.h"
+#include "zypp/parser/yum/FileReaderBase.h"
#include "zypp/data/ResolvableData.h"
#include "zypp/ProgressData.h"
+
namespace zypp
{
namespace parser
* bind(&SomeClass::callbackfunc, &object, _1));
* \endcode
*/
- class PrimaryFileReader
+ class PrimaryFileReader : public FileReaderBase
{
public:
/**
typedef function<bool(const data::Package_Ptr &)> ProcessPackage;
/**
- * Enumeration of some primary.xml tags.
- */
- enum Tag
- {
- tag_NONE,
- tag_package,
- tag_format
- };
-
- /**
* Constructor
* \param primary_file the primary.xml.gz file you want to read
* \param callback function to process \ref _package data.
* \see PrimaryFileReader::ProcessPackage
*/
PrimaryFileReader(
- const Pathname &primary_file,
+ const Pathname & primary_file,
const ProcessPackage & callback,
const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc());
/**
* Callback provided to the XML parser.
*/
- bool consumeNode(zypp::xml::Reader & reader_r);
+ bool consumeNode(xml::Reader & reader_r);
private:
/**
- * Function for processing all <code>format</code> tag subtree nodes.
- */
- bool consumeFormatChildNodes(zypp::xml::Reader & reader_r);
-
- /**
* Creates a new Package_Ptr swaps its contents with \ref _package and
* returns it.
*/
data::Package_Ptr _package;
/**
- * Number of packages read so far.
- */
- unsigned _count;
-
- /** Used to remember primary.xml tag beeing currently processed. */
- Tag _tag;
-
- /**
- * Used to remember whether we are expecting an rpm:entry tag
- * e.g. for rpm:requires
- */
- bool _expect_rpm_entry;
-
- /**
- * Type of dependecy beeing processed.
- */
- Dep _dtype;
-
- /**
* Progress reporting object.
*/
ProgressData _ticks;
namespace zypp { namespace parser { namespace yum {
RepomdFileReader::RepomdFileReader( const Pathname &repomd_file, ProcessResource callback )
- : _tag(tag_NONE), _callback(callback), _type(YUMResourceType::NONE_e)
+ : _tag(tag_NONE), _type(YUMResourceType::NONE_e), _callback(callback)
{
Reader reader( repomd_file );
MIL << "Reading " << repomd_file << endl;