-#include <ctime>
-#include <iostream>
#include "Tools.h"
#include <zypp/base/PtrTypes.h>
#include <zypp/SourceManager.h>
#include <zypp/SourceFactory.h>
+#include "zypp/ZYppCallbacks.h"
#include "zypp/NVRAD.h"
#include "zypp/ResPool.h"
#include "zypp/ResFilters.h"
#include "zypp/CapFilters.h"
#include "zypp/Package.h"
+#include "zypp/Pattern.h"
#include "zypp/Language.h"
+#include "zypp/PackageKeyword.h"
#include "zypp/NameKindProxy.h"
+#include "zypp/pool/GetResolvablesToInsDel.h"
+#include "zypp/parser/tagfile/TagFileParser.h"
+#include "zypp/parser/TagParser.h"
+#include "zypp/parser/susetags/PackagesFileReader.h"
+#include "zypp/parser/susetags/PackagesLangFileReader.h"
+#include "zypp/parser/susetags/PatternFileReader.h"
+#include "zypp/parser/susetags/ContentFileReader.h"
+#include "zypp/parser/susetags/RepoIndex.h"
+
+#include "zypp/parser/susetags/RepoParser.h"
+#include "zypp/cache/CacheStore.h"
using namespace std;
using namespace zypp;
-using namespace zypp::ui;
using namespace zypp::functor;
+using zypp::parser::tagfile::TagFileParser;
+using zypp::parser::TagParser;
+
///////////////////////////////////////////////////////////////////
static const Pathname sysRoot( "/Local/ROOT" );
///////////////////////////////////////////////////////////////////
-namespace container
+struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
{
- template<class _Tp>
- bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
- { return cont.find( val ) != cont.end(); }
-}
-
-///////////////////////////////////////////////////////////////////
-
-template<class _Condition>
- struct SetTrue
- {
- SetTrue( _Condition cond_r )
- : _cond( cond_r )
- {}
-
- template<class _Tp>
- bool operator()( _Tp t ) const
- {
- _cond( t );
- return true;
- }
-
- _Condition _cond;
- };
-
-template<class _Condition>
- inline SetTrue<_Condition> setTrue_c( _Condition cond_r )
+ virtual void start( const Resolvable::constPtr & script_r,
+ const Pathname & path_r,
+ Task task_r )
{
- return SetTrue<_Condition>( cond_r );
+ SEC << __FUNCTION__ << endl
+ << " " << script_r << endl
+ << " " << path_r << endl
+ << " " << task_r << endl;
}
-template <class _Iterator, class _Filter, class _Function>
- inline _Function for_each_if( _Iterator begin_r, _Iterator end_r,
- _Filter filter_r,
- _Function fnc_r )
+ virtual bool progress( Notify notify_r, const std::string & text_r )
{
- for ( _Iterator it = begin_r; it != end_r; ++it )
- {
- if ( filter_r( *it ) )
- {
- fnc_r( *it );
- }
- }
- return fnc_r;
+ SEC << __FUNCTION__ << endl
+ << " " << notify_r << endl
+ << " " << text_r << endl;
+ return true;
}
-struct PrintPoolItem
-{
- void operator()( const PoolItem & pi ) const
- {
- USR << "S" << pi->source().numericId()
- << "/M" << mediaId(pi)
- << " " << pi << endl;
- }
- unsigned mediaId( const PoolItem & pi ) const
+ virtual void problem( const std::string & description_r )
{
- Package::constPtr pkg( asKind<Package>(pi.resolvable()) );
- if ( pkg )
- return pkg->mediaId();
- return 0;
+ SEC << __FUNCTION__ << endl
+ << " " << description_r << endl;
}
-};
-template <class _Iterator>
- std::ostream & vdumpPoolStats( std::ostream & str,
- _Iterator begin_r, _Iterator end_r )
+ virtual void finish()
{
- pool::PoolStats stats;
- std::for_each( begin_r, end_r,
+ SEC << __FUNCTION__ << endl;
+ }
- functor::chain( setTrue_c(PrintPoolItem()),
- setTrue_c(functor::functorRef<void,ResObject::constPtr>(stats)) )
+};
- );
- return str << stats;
- }
+///////////////////////////////////////////////////////////////////
-struct PoolItemSelect
+struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
{
- void operator()( const PoolItem & pi ) const
+ virtual Action requestMedia( Source_Ref source
+ , unsigned mediumNr
+ , Error error
+ , const std::string & description )
{
- if ( pi->source().numericId() == 2 )
- pi.status().setTransact( true, ResStatus::USER );
+ SEC << __FUNCTION__ << endl
+ << " " << source << endl
+ << " " << mediumNr << endl
+ << " " << error << endl
+ << " " << description << endl;
+ return IGNORE;
}
};
///////////////////////////////////////////////////////////////////
-typedef std::list<PoolItem> PoolItemList;
-typedef std::set<PoolItem> PoolItemSet;
-#include "zypp/solver/detail/InstallOrder.h"
-using zypp::solver::detail::InstallOrder;
-#include "Iorder.h"
+
+namespace container
+{
+ template<class _Tp>
+ bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
+ { return cont.find( val ) != cont.end(); }
+}
///////////////////////////////////////////////////////////////////
-namespace zypp
+struct AddResolvables
{
- struct CollectTransacting
+ bool operator()( const Source_Ref & src ) const
{
- typedef std::list<PoolItem> PoolItemList;
+ getZYpp()->addResolvables( src.resolvables() );
+ return true;
+ }
+};
- void operator()( const PoolItem & pi )
- {
- if ( pi.status().isToBeInstalled() )
- {
- _toInstall.insert( pi );
- }
- else if ( pi.status().isToBeUninstalled() )
- {
- if ( pi.status().isToBeUninstalledDueToObsolete()
- || pi.status().isToBeUninstalledDueToUpgrade() )
- _skipToDelete.insert( pi );
- else
- _toDelete.insert( pi );
- }
- }
+///////////////////////////////////////////////////////////////////
- PoolItemSet _toInstall;
- PoolItemSet _toDelete;
- PoolItemSet _skipToDelete;
- };
- std::ostream & operator<<( std::ostream & str, const CollectTransacting & obj )
- {
- str << "CollectTransacting:" << endl;
- dumpPoolStats( str << " toInstall: ",
- obj._toInstall.begin(), obj._toInstall.end() ) << endl;
- dumpPoolStats( str << " toDelete: ",
- obj._toDelete.begin(), obj._toDelete.end() ) << endl;
- dumpPoolStats( str << " skipToDelete: ",
- obj._skipToDelete.begin(), obj._skipToDelete.end() ) << endl;
- return str;
- }
+std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
+{
+ str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
+ return str;
+
}
///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
-struct AddResolvables
-{
- bool operator()( const Source_Ref & src ) const
- { getZYpp()->addResolvables( src.resolvables() ); }
-};
+using namespace zypp::parser::susetags;
+#include "zypp/cache/CacheStore.h"
-///////////////////////////////////////////////////////////////////
+void consumeIndex( const parser::susetags::RepoIndex_Ptr & index_r )
+{
+ SEC << "[Index]" << index_r << endl;
+}
-struct SetTransactValue
+void consumeProd( const data::Product_Ptr & prod_r )
{
- SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
- : _newVal( newVal_r )
- , _causer( causer_r )
- {}
+ SEC << "[Prod]" << prod_r << endl;
+}
- ResStatus::TransactValue _newVal;
- ResStatus::TransactByValue _causer;
+void consumePkg( const data::Package_Ptr & pkg_r )
+{
+ //MIL << "[Pkg]" << pkg_r << endl;
+}
- bool operator()( const PoolItem & pi ) const
- { return pi.status().setTransactValue( _newVal, _causer ); }
-};
+void consumeSrcPkg( const data::SrcPackage_Ptr & pkg_r )
+{
+ //DBG << "[Src]" << pkg_r << endl;
+}
-struct StatusReset : public SetTransactValue
+void consumePat( const data::Pattern_Ptr & pat_r )
{
- StatusReset()
- : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
- {}
-};
+ MIL << "[Pat]" << pat_r << endl;
+}
+void pPackages( const Pathname & p )
+{
+ Measure x( p.basename() );
+ PackagesFileReader tp;
+ tp.setPkgConsumer( consumePkg );
+ tp.setSrcPkgConsumer( consumeSrcPkg );
+ tp.parse( p );
+}
-inline bool selectForTransact( const NameKindProxy & nkp )
+void pPackagesLang( const Pathname & p, const Locale & locale_r )
{
- if ( nkp.availableEmpty() )
- return false;
+ Measure x( p.basename() );
+ PackagesLangFileReader tp;
+ tp.setLocale( locale_r );
+ tp.setPkgConsumer( consumePkg );
+ tp.setSrcPkgConsumer( consumeSrcPkg );
+ tp.parse( p );
+}
- return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
+void pPattern( const Pathname & p )
+{
+ Measure x( p.basename() );
+ PatternFileReader tp;
+ tp.setConsumer( consumePat );
+ tp.parse( p );
}
-/******************************************************************
+ /******************************************************************
**
** FUNCTION NAME : main
** FUNCTION TYPE : int
*/
int main( int argc, char * argv[] )
{
- //zypp::base::LogControl::instance().logfile( "xxx" );
+ //zypp::base::LogControl::instance().logfile( "log.restrict" );
INT << "===[START]==========================================" << endl;
- ResPool pool( getZYpp()->pool() );
+ Pathname dbdir( "store" );
+ Pathname reporoot( "lmd" );
- if ( 1 )
- {
- getZYpp()->initTarget( sysRoot );
- getZYpp()->addResolvables( getZYpp()->target()->resolvables(), true );
- USR << "Added target: " << pool << endl;
- }
+ cache::CacheStore store( dbdir );
+ data::RecordId repositoryId = store.lookupOrAppendRepository( Url("dir:///"), "/" );
+ {
+ Measure x( "XXXXXXXXXXXXX" );
- if ( 1 ) {
- SourceManager::sourceManager()->restore( sysRoot );
- if ( SourceManager::sourceManager()->allSources().empty() )
- {
- Source_Ref src1( createSource( "dir:/mounts/machcd2/CDs/SLES-10-CD-i386-Beta10/CD1" ) );
- Source_Ref src2( createSource( "dir:/mounts/machcd2/kukuk/sles10-sp-i386/CD1" ) );
- SourceManager::sourceManager()->addSource( src1 );
- SourceManager::sourceManager()->addSource( src2 );
- SourceManager::sourceManager()->store( sysRoot, true );
- }
- for_each( SourceManager::sourceManager()->Source_begin(), SourceManager::sourceManager()->Source_end(),
- AddResolvables() );
- dumpRange( USR << "Sources: ",
- SourceManager::sourceManager()->Source_begin(), SourceManager::sourceManager()->Source_end()
- ) << endl;
- }
+ parser::susetags::RepoParser repo( repositoryId, store );
+ repo.parse( reporoot );
- USR << pool << endl;
- //dumpRange( USR << "Pool: " << pool,
- // pool.begin(), pool.end()
- // ) << endl;
+ store.commit();
+ }
- selectForTransact( nameKindProxy<Pattern>( pool, "default" ) );
- selectForTransact( nameKindProxy<Pattern>( pool, "x11" ) );
- selectForTransact( nameKindProxy<Pattern>( pool, "kde" ) );
- selectForTransact( nameKindProxy<Pattern>( pool, "OOo" ) );
- vdumpPoolStats( USR << "Transacting:"<< endl,
- make_filter_begin<resfilter::ByTransact>(pool),
- make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+#if 0
+ ContentFileReader tp;
+ tp.setProductConsumer( consumeProd );
+ tp.setRepoIndexConsumer( consumeIndex );
+ //tp.setSrcPkgConsumer( consumeSrcPkg );
+ tp.parse( p );
- bool eres, rres;
+ //try
{
- zypp::base::LogControl::TmpLineWriter shutUp;
- eres = getZYpp()->resolver()->establishPool();
- rres = getZYpp()->resolver()->resolvePool();
+ //Pathname dbdir( "/Local/ma/zypp-TRUNK/BUILD/libzypp/devel/devel.ma/store" );
+
+
+ Pathname dbdir( "store" );
+ Pathname metadir( "lmd" );
+
+ cache::CacheStore store( dbdir );
+ data::RecordId repositoryId = store.lookupOrAppendRepository( Url("http://www.google.com"), "/" );
+
+ RepoParser( metadir, repositoryId, store );
+
}
- MIL << "est " << eres << " slv " << rres << endl;
- vdumpPoolStats( USR << "Transacting:"<< endl,
- make_filter_begin<resfilter::ByTransact>(pool),
- make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+ try
+ {
+ ZYpp::Ptr z = getZYpp();
+
+ Pathname dbfile( "data.db" );
+ cache::CacheStore store(getenv("PWD"));
+
+ data::RecordId repository_id = store.lookupOrAppendRepository( Url("http://www.google.com"), "/");
+ PackagesParser parser( repository_id, store);
+ Measure m;
+ parser.start(argv[1], &progress_function);
+ m.elapsed();
+ }
+ catch ( const Exception &e )
+ {
+ cout << "ups! " << e.msg() << std::endl;
+ }
+#endif
INT << "===[END]============================================" << endl << endl;
+ zypp::base::LogControl::instance().logNothing();
+ return 0;
+
+ Pathname proot( "lmd/suse/setup/descr" );
+
+ pPackages( proot/"packages" );
+ //pPackages( proot/"packages.gz" );
+ pPackagesLang( proot/"packages.de", Locale("de") );
+ //pPackagesLang( proot/"packages.de.gz", Locale("de") );
+ pPattern( proot/"base-10.3-30.x86_64.pat" );
+
+ if ( 0 )
+ {
+ Measure x( "lmd.idx" );
+ std::ifstream fIndex( "lmd.idx" );
+ for( iostr::EachLine in( fIndex ); in; in.next() )
+ {
+ Measure x( *in );
+ std::ifstream fIn( (*in).c_str() );
+ for( iostr::EachLine l( fIn ); l; l.next() )
+ {
+ ;
+ }
+ }
+ }
+ INT << "===[END]============================================" << endl << endl;
+ zypp::base::LogControl::instance().logNothing();
return 0;
}