#include <iostream>
+#include <fstream>
#include <zypp/base/Logger.h>
#include <zypp/ZYpp.h>
#include "zypp/PublicKey.h"
#include "zypp/detail/PackageImplIf.h"
#include "zypp/source/PackageDelta.h"
+#include "zypp/parser/yum/YUMPrimaryParser.h"
#include "zypp/detail/ImplConnect.h"
#include "zypp/SourceFactory.h"
#include "testsuite/src/utils/TestUtils.h"
+#include "zypp/base/GzStream.h"
using namespace std;
using namespace zypp;
using namespace zypp::packagedelta;
//using namespace DbXml;
-int main()
+struct YUMSourceEventHandler
+{
+ YUMSourceEventHandler()
+ {}
+
+ void operator()( int p )
+ {
+ std::cout << "\rProgress " << p << " " << std::endl;
+ }
+};
+
+int main(int argc, char **argv)
{
try
{
//PublicKey key("repomd.xml.key");
//cout << key << endl;
- z->initializeTarget("/");
-
+ //z->initializeTarget("/");
+
+ Pathname filename = "primary.xml";
+ //ifgzstream st ( argv[1] );
+ std::ifstream st ( argv[1] );
+
+ if ( st.bad() )
+ ZYPP_THROW(Exception("archivo malo"));
+
+ parser::ParserProgress::Ptr progress;
+ YUMSourceEventHandler npp;
+ progress.reset( new parser::ParserProgress( npp, PathInfo(filename).size() ) );
+
+ parser::yum::YUMPrimaryParser prim(st, "", progress);
+ for (; !prim.atEnd(); ++prim)
+ {
+ std::cout << "iteracion" << std::endl;
+ if (*prim == NULL) continue; // incompatible arch detected during parsi
+ }
}
catch ( const Exception &e )
{
/**
* initializes a progress objetc, with a callback functor
* if you are not reporting percentage, then set
- * the metric to the goal, and report using the same
+ * the total_steps to the goal, and report using the same
* unit, then
*/
- ParserProgress( boost::function<void (int)> fnc, int metric = 100 )
- : _fnc(fnc), _previous_progress(0), _metric(metric)
+ ParserProgress( boost::function<void (long int)> fnc, long int total_steps = 100 )
+ : _fnc(fnc), _previous_progress(0), _total_steps(total_steps)
{
};
* this progress object to update progress
* information
*/
- void progress(int p)
+ void progress(long int p)
{
- if ( _metric != 100 )
+ //std::cout << "real " << p << std::endl;
+ if ( _total_steps != 100 )
{
- int current_done = p;
- p = (int)((float) current_done/(float) _metric);
+ long int current_done = p;
+ p = (long int)(((double) current_done/(double) _total_steps)*100);
}
if (_fnc && ( p != _previous_progress ))
}
}
+ void setTotalSteps( long int total_steps )
+ {
+ _total_steps = total_steps;
+ }
+
/**
* report progress finished
*/
}
private:
- boost::function<void (int)> _fnc;
- int _previous_progress;
- int _metric;
+ boost::function<void (long int)> _fnc;
+ long int _previous_progress;
+ long int _total_steps;
};
} // namespace parser
_input(& input),
_reader(xmlReaderForIO(ioread, ioclose, _input, baseUrl.c_str(), "utf-8",
XML_PARSE_PEDANTIC)),
- _baseUrl(baseUrl), _progress(progress)
+ _baseUrl(baseUrl), _progress(progress), _stream_size(0), _bytes_consumed(0)
{
xmlTextReaderSetErrorHandler(_reader, (xmlTextReaderErrorFunc) errorHandler, this);
// xmlTextReaderSetStructuredErrorHandler(_reader, structuredErrorHandler, this);
bool
XMLNodeIteratorBase::atEnd() const
{
- return (_error.get() != 0
- || getCurrent() == 0);
+ if ( _error.get() != 0 || getCurrent() == 0 )
+ {
+ if ( _progress )
+ _progress->finish();
+ return true;
+ }
+ return false;
}
void XMLNodeIteratorBase::fetchNext()
{
xml_assert(_reader);
+
+ if ( _progress )
+ {
+ long int consumed = xmlTextReaderByteConsumed (_reader);
+ //MIL << consumed << " bytes consumed." << endl;
+ // only report every 4k or more
+ if ( ( consumed - _bytes_consumed > 4096 ) )
+ {
+ _progress->progress(consumed);
+ _bytes_consumed = consumed;
+ }
+ }
+
int status;
/* throw away the old entry */
setCurrent(0);
/* this is a trivial iterator over (max) only one element,
and we reach the end now. */
;
- if ( _progress )
- _progress->progress( 100 );
}
else {
/* repeat as long as we successfully read nodes
breaks out when an interesting node has been found */
- while ((status = xmlTextReaderRead(_reader))==1) {
+ while ((status = xmlTextReaderRead(_reader))==1)
+ {
xmlNodePtr node = xmlTextReaderCurrentNode(_reader);
+
if (isInterested(node))
{
// xmlDebugDumpNode(stdout,node,5);
_process(_reader);
- if ( _progress )
- _progress->progress( xmlTextReaderByteConsumed (_reader) );
// _currentDataPtr.reset(new ENTRYTYPE(process(_reader)));
status = xmlTextReaderNext(_reader);
break;
*/
parser::ParserProgress::Ptr _progress;
+ /**
+ * size of the stream to parse
+ */
+ long int _stream_size;
+ /**
+ * bytes consumed in last report
+ */
+ long int _bytes_consumed;
}; /* end class XMLNodeIteratorBase */
callback::SendReport<SourceReport> &_report;
};
+ static long int get_stream_size( const Pathname &p )
+ {
+ ifgzstream input( p.asString().c_str() );
+
+ if ( input.bad() )
+ ZYPP_THROW(Exception("Can't read " + p.asString() + " to calculate compressed stream size"));
+
+ // get the size of the stream
+ DBG << "Getting size of the stream." << std::endl;
+ input.seekg (0, ios::end);
+ long int stream_size = input.tellg();
+ DBG << "XML stream size: " << stream_size << std::endl;
+ return stream_size;
+ }
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : YUMSourceImpl
parser::ParserProgress::Ptr progress;
callback::SendReport<SourceReport> report;
YUMSourceEventHandler npp(report);
- progress.reset( new parser::ParserProgress( npp, PathInfo(repomdFile()).size() ) );
+ progress.reset( new parser::ParserProgress( npp ) );
report->start( selfSourceRef(), "Parsing index file" );
try
parser::ParserProgress::Ptr progress;
YUMSourceEventHandler npp(report);
- progress.reset( new parser::ParserProgress( npp, PathInfo(filename).size() ) );
+ progress.reset( new parser::ParserProgress( npp, get_stream_size(filename) ) );
report->start( selfSourceRef(), "Parsing filelist from " + filename.asString() );
YUMFileListParser filelist ( st, "", progress );
parser::ParserProgress::Ptr progress;
YUMSourceEventHandler npp(report);
- progress.reset( new parser::ParserProgress( npp, PathInfo(filename).size() ) );
+ progress.reset( new parser::ParserProgress( npp ) );
report->start( selfSourceRef(), "Parsing packages from " + filename.asString() );
ifgzstream st ( filename.asString().c_str() );
parser::ParserProgress::Ptr progress;
YUMSourceEventHandler npp(report);
- progress.reset( new parser::ParserProgress( npp, PathInfo(filename).size() ) );
+ progress.reset( new parser::ParserProgress( npp ) );
report->start( selfSourceRef(), "Parsing selection " + filename.asString() );
YUMGroupParser group(st, "", progress);
parser::ParserProgress::Ptr progress;
YUMSourceEventHandler npp(report);
- progress.reset( new parser::ParserProgress( npp, PathInfo(filename).size() ) );
+ progress.reset( new parser::ParserProgress( npp ) );
report->start( selfSourceRef(), "Parsing pattern " + filename.asString() );
YUMPatternParser pattern(st, "", progress);
parser::ParserProgress::Ptr progress;
YUMSourceEventHandler npp(report);
- progress.reset( new parser::ParserProgress( npp, PathInfo(filename).size() ) );
+ progress.reset( new parser::ParserProgress( npp ) );
report->start( selfSourceRef(), "Parsing patches index " + filename.asString() );
YUMPatchesParser patch(st, "", progress);
parser::ParserProgress::Ptr progress;
YUMSourceEventHandler npp(report);
- progress.reset( new parser::ParserProgress( npp, PathInfo(filename).size() ) );
+ progress.reset( new parser::ParserProgress( npp ) );
report->start( selfSourceRef(), "Parsing patch " + filename.asString() );