ADD_SUBDIRECTORY(devel.dmacvicar)
ADD_SUBDIRECTORY(devel.ma)
+ADD_SUBDIRECTORY(devel.jkupec)
--- /dev/null
+INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
+
+ADD_DEFINITIONS(-DSRC_DIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\")
+
+#ADD_EXECUTABLE(sourcedownload sourcedownload.cc)
+#TARGET_LINK_LIBRARIES(sourcedownload zypp zypp2)
+
+ADD_EXECUTABLE( yumparsertest YUMParser_test.cc YUMParser.cc)
+TARGET_LINK_LIBRARIES(yumparsertest zypp zypp2)
--- /dev/null
+//#include "zypp/data/ResolvableDataConsumer.h"
+#include "zypp/ZYpp.h"
+#include "zypp/ZYppFactory.h"
+#include "zypp/base/Logger.h"
+
+#include "YUMParser.h"
+
+using std::endl;
+
+namespace zypp
+{
+ namespace parser
+ {
+ namespace yum
+ {
+
+
+ YUMParser::YUMParser(const zypp::data::RecordId &catalog_id, zypp::cache::CacheStore &consumer)
+ : _consumer(consumer), _catalog_id(catalog_id)
+ {
+ ZYpp::Ptr z = getZYpp();
+// _system_arch = z->architecture();
+
+ MIL << "constructed" << endl;
+ }
+
+
+
+ bool YUMParser::primary_CB(const zypp::data::Package &package)
+ {
+// data::RecordId pkgid = _consumer.appendResolvable( _catalog_id, ResTraits<Package>::kind, nvra, deps );
+
+ MIL << "got package "
+ << package.name << package.edition << " "
+ << package.arch
+ << endl;
+/* MIL << "checksum: " << package.checksum << endl;
+ MIL << "summary: " << package.summary << endl;*/
+ }
+
+ void YUMParser::start(const Pathname &cache_dir, Progress progress_fnc)
+ {
+ progress_fnc(0);
+
+ zypp::parser::yum::PrimaryFileReader(
+ cache_dir + "/repodata/primary.xml.gz",
+ bind(&YUMParser::primary_CB, this, _1));
+
+ progress_fnc(100);
+ }
+
+
+ } // ns yum
+ } // ns parser
+} // ns zypp
--- /dev/null
+#ifndef YUMPARSER_H_
+#define YUMPARSER_H_
+
+#include "zypp/base/Logger.h"
+#include "zypp2/cache/CacheStore.h"
+#include "zypp/data/ResolvableData.h"
+#include "zypp/parser/yum/PrimaryFileReader.h"
+
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "parser"
+
+
+namespace zypp
+{
+ namespace parser
+ {
+ namespace yum
+ {
+
+
+ class YUMParser
+ {
+ public:
+ typedef function<bool( int )> Progress;
+
+ YUMParser(const zypp::data::RecordId &catalog_id, zypp::cache::CacheStore &consumer);
+
+ void start(const zypp::Pathname &path, Progress progress_fnc);
+
+ bool primary_CB(const zypp::data::Package &package);
+ bool test() { return true; }
+
+ private:
+ zypp::cache::CacheStore &_consumer;
+ zypp::data::RecordId _catalog_id;
+ };
+
+
+ }
+ }
+} // ns zypp
+
+#endif /*YUMPARSER_H_*/
--- /dev/null
+#include "zypp/ZYpp.h"
+#include "zypp/ZYppFactory.h"
+#include "zypp/base/Logger.h"
+#include "zypp/base/LogControl.h"
+#include "zypp/parser/yum/PrimaryFileReader.h"
+#include "YUMParser.h"
+
+
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "yumparsertest"
+
+using namespace std;
+using namespace zypp;
+using namespace zypp::parser::yum;
+
+bool progress_function(int p)
+{
+ MIL << p << "%" << endl;
+}
+
+int main(int argc, char **argv)
+{
+ base::LogControl::instance().logfile("yumparsertest.log");
+
+ try
+ {
+ ZYpp::Ptr z = getZYpp();
+//, bind( &YUMDownloader::patches_Callback, this, _1, _2));
+
+// Pathname dbfile = Pathname(getenv("PWD")) + "data.db";
+ cache::CacheStore store(getenv("PWD"));
+ data::RecordId catalog_id = store.lookupOrAppendCatalog( Url("http://www.google.com"), "/");
+
+ MIL << "creating PrimaryFileParser" << endl;
+ parser::yum::YUMParser parser( catalog_id, store);
+ parser.start(argv[1], &progress_function);
+
+/*
+ YUMDownloader downloader(Url(argv[1]), "/");
+ downloader.download(argv[2]);*/
+ }
+ catch ( const Exception &e )
+ {
+ cout << "Oops! " << e.msg() << std::endl;
+ }
+
+ return 0;
+}
parser/yum/YUMRepomdParser.cc
parser/yum/RepomdFileReader.cc
parser/yum/PatchesFileReader.cc
+ parser/yum/PrimaryFileReader.cc
)
SET( zypp_parser_yum_HEADERS
parser/yum/YUMRepomdParser.h
parser/yum/RepomdFileReader.h
parser/yum/PatchesFileReader.h
+ parser/yum/PrimaryFileReader.h
parser/yum/schemanames.h
)
--- /dev/null
+#include "zypp/base/String.h"
+#include "zypp/base/Logger.h"
+#include "zypp/parser/yum/PrimaryFileReader.h"
+#include "zypp/Arch.h"
+#include "zypp/Edition.h"
+#include "zypp/TranslatedText.h"
+
+
+using namespace std;
+using namespace zypp::xml;
+
+namespace zypp
+{
+ namespace parser
+ {
+ namespace yum
+ {
+
+
+ PrimaryFileReader::PrimaryFileReader(const Pathname &primary_file, ProcessPackage callback)
+ : _callback(callback), _package(NULL), _count(0), _tag(tag_NONE)
+ {
+ Reader reader( primary_file );
+ MIL << "Reading " << primary_file << endl;
+ reader.foreachNode( bind( &PrimaryFileReader::consumeNode, this, _1 ) );
+ }
+
+ bool PrimaryFileReader::consumeNode(Reader & reader_r)
+ {
+ if (_tag = tag_format)
+ return consumeFormatChildNodes(reader_r);
+
+ if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
+ {
+ if (reader_r->name() == "package")
+ {
+ _tag = tag_package;
+ // DBG << "got " << reader_r->getAttribute("type") << " package" << endl;
+ if (_package) delete _package;
+ _package = new zypp::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());
+ }
+
+ if (reader_r->name() == "checksum")
+ {
+ _package->checksum = 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();
+ return true;
+ }
+
+ // TODO url
+ // TODO time
+ // TODO size
+
+ if (reader_r->name() == "location")
+ {
+ _package->location = reader_r->getAttribute("href").asString();
+ }
+
+ if (reader_r->name() == "format")
+ {
+ _tag = tag_format;
+ consumeFormatChildNodes(reader_r);
+ }
+ }
+ else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
+ {
+ if (reader_r->name() == "package")
+ {
+ _callback(*_package);
+ if (_package)
+ {
+ delete _package;
+ _package = NULL;
+ }
+ _count++;
+ _tag = tag_NONE;
+ }
+ if (reader_r->name() == "metadata")
+ {
+ MIL << _count << " packages read." << endl;
+ }
+ return true;
+ }
+
+ return true;
+ }
+
+ bool PrimaryFileReader::consumeFormatChildNodes(Reader & reader_r)
+ {
+ if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
+ {
+
+ }
+ else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
+ {
+ if (reader_r->name() == "format");
+ {
+ _tag = tag_package;
+ return true;
+ }
+ }
+ return true;
+ }
+
+
+ } // ns yum
+ } // ns parser
+} //ns zypp
+
+// vim: set ts=2 sts=2 sw=2 et ai:
--- /dev/null
+#ifndef ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H
+#define ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H
+
+#include "zypp/Date.h"
+#include "zypp/base/Function.h"
+#include "zypp/base/Logger.h"
+#include "zypp/parser/xml/Reader.h"
+#include "zypp/data/ResolvableData.h"
+
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "parser"
+
+namespace zypp
+{
+ namespace parser
+ {
+ namespace yum
+ {
+
+ enum Tag
+ {
+ tag_NONE,
+ tag_package,
+ tag_format
+ };
+
+/**
+ * Iterates through a primary.xml file giving on each iteration
+ * a \ref OnMediaLocation object with the resource and its
+ * type ( primary, patches, filelists, etc ).
+ * The iteration is done via a callback provided on
+ * construction.
+ *
+ * \code
+ * RepomdFileReader reader(repomd_file,
+ * bind( &SomeClass::callbackfunc, &object, _1, _2 ) );
+ * \endcode
+ */
+class PrimaryFileReader
+{
+public:
+ /**
+ * Callback definition.
+ */
+ typedef function<bool(const zypp::data::Package&)> ProcessPackage;
+
+ /**
+ * Constructor
+ * \param primary_file the primary.xml.gz file you want to read
+ * \param function to process \ref _package data.
+ *
+ * \see PrimaryFileReader::ProcessPackage
+ */
+ PrimaryFileReader(const Pathname &primary_file, ProcessPackage callback);
+
+ /**
+ * Callback provided to the XML parser.
+ */
+ bool consumeNode(zypp::xml::Reader & reader_r);
+
+private:
+ bool consumeFormatChildNodes(zypp::xml::Reader & reader_r);
+
+private:
+ Tag _tag;
+ unsigned _count;
+ zypp::data::Package *_package;
+ ProcessPackage _callback;
+/* CheckSum _checksum;
+ std::string _checksum_type;
+ Date _timestamp;*/
+};
+
+
+ } // ns zypp
+ } // ns parser
+} // ns yum
+
+#endif /* ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H */
+
+// vim: set ts=2 sts=2 sw=2 et ai: