#include "Tools.h"
-#include <iostream>
-#include <fstream>
-#include <sstream>
-#include <list>
-#include <map>
-#include <set>
-
-#include <boost/call_traits.hpp>
-
-#include <zypp/base/LogControl.h>
-#include <zypp/base/LogTools.h>
-
-#include "zypp/base/Exception.h"
-#include "zypp/base/InputStream.h"
-#include "zypp/base/DefaultIntegral.h"
-#include <zypp/base/Function.h>
-#include <zypp/base/Iterator.h>
-#include <zypp/Pathname.h>
-#include <zypp/Edition.h>
-#include <zypp/CheckSum.h>
-#include <zypp/Date.h>
-#include <zypp/Rel.h>
-#include <zypp/Bit.h>
-
-#include "zypp/parser/xml/Reader.h"
-#include "zypp/parser/xml/ParseDef.h"
-#include "zypp/parser/xml/ParseDefConsume.h"
-
-#include "zypp/parser/ProductFileReader.h"
-
-using namespace std;
-using namespace zypp;
+#include <zypp/PoolQuery.h>
+#include <zypp/target/rpm/librpmDb.h>
+#include <zypp/parser/ProductFileReader.h>
-///////////////////////////////////////////////////////////////////
+#include "zypp/sat/WhatObsoletes.h"
+#include "zypp/ExternalProgram.h"
+#include <zypp/ZYppCallbacks.h>
-static const Pathname sysRoot( "/Local/ROOT" );
+#include "zypp/sat/Transaction.h"
///////////////////////////////////////////////////////////////////
-template<class _Cl>
- void ti( const _Cl & c )
- {
- SEC << __PRETTY_FUNCTION__ << endl;
- }
+//static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
+//static const Pathname sysRoot( "/tmp/ToolScanRepos" );
+// static const Pathname sysRoot( "/tmp/updateTestcase" );
+static const Pathname sysRoot( "/tmp/ToolScanRepos" );
///////////////////////////////////////////////////////////////////
-
-bool nopNode( xml::Reader & reader_r )
+struct IRR : public zypp::callback::ReceiveReport<zypp::target::rpm::InstallResolvableReport>
{
- return true;
-}
-
-///////////////////////////////////////////////////////////////////
+ IRR()
+ { connect(); }
+#if 0
+ enum Action {
+ ABORT, // abort and return error
+ RETRY, // retry
+ IGNORE // ignore the failure
+ };
-bool accNode( xml::Reader & reader_r )
-{
- int i;
- xml::XmlString s;
-#define X(m) reader_r->m()
- i=X(readState);
- i=X(lineNumber);
- i=X(columnNumber);
- i=X(depth);
- i=X(nodeType);
- s=X(name);
- s=X(prefix);
- s=X(localName);
- i=X(hasAttributes);
- i=X(attributeCount);
- i=X(hasValue);
- s=X(value);
-#undef X
- return true;
-}
+ enum Error {
+ NO_ERROR,
+ NOT_FOUND, // the requested Url was not found
+ IO, // IO error
+ INVALID // th resolvable is invalid
+ };
-///////////////////////////////////////////////////////////////////
+ // the level of RPM pushing
+ /** \deprecated We fortunately no longer do 3 attempts. */
+ enum RpmLevel {
+ RPM,
+ RPM_NODEPS,
+ RPM_NODEPS_FORCE
+ };
+#endif
-bool dumpNode( xml::Reader & reader_r )
-{
- switch ( reader_r->nodeType() )
- {
- case XML_READER_TYPE_ATTRIBUTE:
- case XML_READER_TYPE_TEXT:
- case XML_READER_TYPE_CDATA:
- DBG << *reader_r << endl;
- break;
- case XML_READER_TYPE_ELEMENT:
-
- MIL << *reader_r << endl;
- break;
- default:
- //WAR << *reader_r << endl;
- break;
- }
- return true;
-}
+ virtual void reportbegin()
+ { /*SEC << endl;*/ }
+ virtual void reportend()
+ { /*SEC << endl;*/ }
-///////////////////////////////////////////////////////////////////
+ virtual void start(Resolvable::constPtr /*resolvable*/)
+ { INT << endl; }
-bool dumpEd( xml::Reader & reader_r )
-{
- static int num = 5;
- if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT
- && reader_r->name() == "version" )
+ virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
+ {
+ static int i = 4;
+ if ( --i <= 0 )
{
- MIL << *reader_r << endl;
- DBG << reader_r->getAttribute( "rel" ) << endl;
- ERR << *reader_r << endl;
- DBG << reader_r->getAttribute( "ver" ) << endl;
- ERR << *reader_r << endl;
- DBG << reader_r->getAttribute( "epoch" ) << endl;
- ERR << *reader_r << endl;
- WAR << Edition( reader_r->getAttribute( "ver" ).asString(),
- reader_r->getAttribute( "rel" ).asString(),
- reader_r->getAttribute( "epoch" ).asString() ) << endl;
- --num;
+ INT << "return abort" << endl;
+ return false;
}
- return num;
-}
-
-///////////////////////////////////////////////////////////////////
+ return true;
+ }
-template<class _OutputIterator>
- struct DumpDeps
+ virtual Action problem(Resolvable::constPtr /*resolvable*/, Error /*error*/, const std::string &/*description*/, RpmLevel /*level*/)
{
- DumpDeps( _OutputIterator result_r )
- : _result( result_r )
- {}
+ INT << "return abort" << endl;
+ return ABORT;
+ }
- bool operator()( xml::Reader & reader_r )
- {
- if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT
- && reader_r->prefix() == "rpm"
- && reader_r->localName() == "entry" )
- {
- string n( reader_r->getAttribute( "name" ).asString() );
- Rel op( reader_r->getAttribute( "flags" ).asString() );
- if ( op != Rel::ANY )
- {
- n += " ";
- n += op.asString();
- n += " ";
- n += reader_r->getAttribute( "ver" ).asString();
- n += "-";
- n += reader_r->getAttribute( "rel" ).asString();
- }
- *_result = n;
- ++_result;
- }
- return true;
- }
+ virtual void finish(Resolvable::constPtr /*resolvable*/, Error /*error*/, const std::string &/*reason*/, RpmLevel /*level*/)
+ { INT << endl; }
+};
+
+struct RRR : public zypp::callback::ReceiveReport<zypp::target::rpm::RemoveResolvableReport>
+{
+ RRR()
+ { connect(); }
+#if 0
+ enum Action {
+ ABORT, // abort and return error
+ RETRY, // retry
+ IGNORE // ignore the failure
+ };
- _OutputIterator _result;
+ enum Error {
+ NO_ERROR,
+ NOT_FOUND, // the requested Url was not found
+ IO, // IO error
+ INVALID // th resolvable is invalid
};
+#endif
-template<class _OutputIterator>
- DumpDeps<_OutputIterator> dumpDeps( _OutputIterator result_r )
- { return DumpDeps<_OutputIterator>( result_r ); }
+ virtual void reportbegin()
+ { /*SEC << endl;*/ }
+ virtual void reportend()
+ { /*SEC << endl;*/ }
-///////////////////////////////////////////////////////////////////
+ virtual void start( Resolvable::constPtr /*resolvable*/ )
+ { INT << endl; }
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace xml
- { /////////////////////////////////////////////////////////////////
+ virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
+ { INT << endl; return true; }
+ virtual Action problem( Resolvable::constPtr /*resolvable*/ , Error /*error*/ , const std::string &/*description*/ )
+ { INT << endl; return ABORT; }
+
+ virtual void finish( Resolvable::constPtr /*resolvable*/ , Error /*error*/ , const std::string &/*reason*/ )
+ { INT << endl; }
+};
- /////////////////////////////////////////////////////////////////
- } // namespace xml
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-bool Consumer( const parser::ProductFileData & data_r )
+bool solve()
{
- MIL << data_r << endl;
+ bool rres = false;
+ {
+ //zypp::base::LogControl::TmpLineWriter shutUp;
+ //getZYpp()->resolver()->setOnlyRequires( true );
+ rres = getZYpp()->resolver()->resolvePool();
+ }
+ if ( ! rres )
+ {
+ ERR << "resolve " << rres << endl;
+ getZYpp()->resolver()->problems();
+ return false;
+ }
+ MIL << "resolve " << rres << endl;
return true;
}
-#include "zypp/base/Functional.h"
-#include "zypp/parser/ProductFileReader.h"
+bool upgrade()
+{
+ bool rres = false;
+ {
+ zypp::base::LogControl::TmpLineWriter shutUp;
+ Measure x( "Upgrade" );
+ rres = getZYpp()->resolver()->doUpgrade();
+ }
+ if ( ! rres )
+ {
+ Measure x( "Upgrade Error" );
+ ERR << "upgrade " << rres << endl;
+ getZYpp()->resolver()->problems();
+ return false;
+ }
+ MIL << "upgrade " << rres << endl;
+ return true;
+}
-/******************************************************************
-**
-** FUNCTION NAME : main
-** FUNCTION TYPE : int
-*/
-int main( int argc, char * argv[] )
+bool install()
{
- INT << "===[START]==========================================" << endl;
+ ZYppCommitPolicy pol;
+ //pol.dryRun( true );
+ pol.downloadMode( DownloadAsNeeded );
+ pol.rpmInstFlags( pol.rpmInstFlags().setFlag( target::rpm::RPMINST_JUSTDB ) );
+ ZYppCommitResult res( getZYpp()->commit( pol ) );
+ SEC << res << endl;
+ MIL << res.transactionStepList() << endl;
+ return true;
+}
- {
- Measure x( "PARSE" );
+///////////////////////////////////////////////////////////////////
- std::vector<parser::ProductFileData> result;
- parser::ProductFileReader::scanDir( functor::getAll( std::back_inserter( result ) ),
- sysRoot / "etc/products.d" );
+template <class _Iter>
+unsigned count( _Iter begin, _Iter end )
+{
+ unsigned cnt = 0;
+ for_( it, begin, end )
+ ++cnt;
+ return cnt;
+}
- MIL << "Products: " << result << endl;
- }
+///////////////////////////////////////////////////////////////////
+int main( int argc, char * argv[] )
+try {
+ --argc;
+ ++argv;
+ zypp::base::LogControl::instance().logToStdErr();
+ INT << "===[START]==========================================" << endl;
+ ///////////////////////////////////////////////////////////////////
+ IRR _irr;
+ RRR _rrr;
+ if ( sysRoot == "/" )
+ ::unsetenv( "ZYPP_CONF" );
+
+ sat::Transaction();
+ const sat::Transaction a;
+ sat::Transaction b;
+ sat::Transaction c( a );
+ b = a;
+
+ ResPool pool( ResPool::instance() );
+ sat::Pool satpool( sat::Pool::instance() );
+ ///////////////////////////////////////////////////////////////////
+ dumpRange( WAR << "satpool.multiversion " , satpool.multiversionBegin(), satpool.multiversionEnd() ) << endl;
+ TestSetup::LoadSystemAt( sysRoot, Arch_i586 );
+ getZYpp()->initializeTarget( sysRoot );
-#if 0
- bool write = false;
- bool read = true;
+ ///////////////////////////////////////////////////////////////////
if ( 1 )
- {
- zypp::base::LogControl::TmpLineWriter shutUp;
- getZYpp()->initTarget( sysRoot );
- }
- if ( write )
- {
- ZYpp::LocaleSet lset;
- lset.insert( Locale("gr") );
- getZYpp()->setRequestedLocales( lset );
- }
-
- ResPool pool( getZYpp()->pool() );
- USR << pool << endl;
+ {
+ getPi<Product>( "openSUSE-CD-retail" ).status().setToBeInstalled( ResStatus::USER );
+ getPi<Pattern>( "devel_qt4" ).status().setToBeInstalled( ResStatus::USER );
+// getPi<Pattern>( "devel_qt4" ).status().setToBeInstalled( ResStatus::USER );
+ solve();
+ sat::Transaction trans( pool.resolver().getTransaction() );
+ trans.order();
+
+ USR << count( trans.actionBegin(), trans.actionEnd() ) << endl;
+ USR << count( trans.actionBegin(sat::Transaction::STEP_TODO), trans.actionEnd() ) << endl;
+ USR << count( trans.actionBegin(sat::Transaction::STEP_DONE), trans.actionEnd() ) << endl;
+ USR << count( trans.actionBegin(sat::Transaction::STEP_ERROR), trans.actionEnd() ) << endl;
+ USR << count( trans.actionBegin(sat::Transaction::STEP_TODO|sat::Transaction::STEP_ERROR), trans.actionEnd() ) << endl;
+ USR << count( trans.actionBegin(~sat::Transaction::STEP_ERROR), trans.actionEnd() ) << endl;
+ USR << count( trans.actionBegin(~sat::Transaction::STEP_TODO), trans.actionEnd() ) << endl;
+
+ //install();
+ }
- if ( write )
- {
- syscontent::Writer contentW;
- contentW.name( "mycollection" )
- .edition( Edition( "1.0" ) )
- .description( "All the cool stuff..." );
- for_each( pool.begin(), pool.end(),
- bind( &syscontent::Writer::addIf, ref(contentW), _1 ) );
-
- ofstream s( "mycollection.xml" );
- s << contentW;
- }
+ ///////////////////////////////////////////////////////////////////
+ // ResPoolProxy selpool( pool.proxy() );
+ if ( 0 )
+ {
+ upgrade();
+ install();
+ }
- if ( read )
- {
- Measure x( "Parse" );
- std::ifstream input( "mycollection.xml" );
- syscontent::Reader contentR;
- try
- {
- contentR = syscontent::Reader( input );
- }
- catch( const Exception & excpt_r )
- {
- ERR << excpt_r << endl;
- }
-
- MIL << contentR << endl;
-
- for_each( contentR.begin(), contentR.end(), Print() );
- }
-#endif
+ ///////////////////////////////////////////////////////////////////
INT << "===[END]============================================" << endl << endl;
zypp::base::LogControl::instance().logNothing();
return 0;
}
+catch ( const Exception & exp )
+{
+ INT << exp << endl << exp.historyAsString();
+}
+catch (...)
+{}