-#include <ctime>
-
-#include <iostream>
-#include <list>
-#include <map>
-#include <set>
-
-#include "Measure.h"
-#include "Printing.h"
#include "Tools.h"
-#include <zypp/base/Logger.h>
-#include <zypp/base/LogControl.h>
-#include <zypp/base/String.h>
-#include <zypp/base/Exception.h>
#include <zypp/base/PtrTypes.h>
-#include <zypp/base/Iterator.h>
-#include <zypp/base/Algorithm.h>
-#include <zypp/base/Functional.h>
-#include <zypp/base/ProvideNumericId.h>
+#include <zypp/base/Exception.h>
#include <zypp/base/ProvideNumericId.h>
+#include "zypp/ZYppFactory.h"
+#include "zypp/ResPoolProxy.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/SourceManager.h>
-#include <zypp/SourceFactory.h>
-#include <zypp/source/susetags/SuseTagsImpl.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/ZYppFactory.h"
-#include "zypp/ResPoolProxy.h"
-#include "zypp/ResPoolProxy.h"
-#include "zypp/target/rpm/RpmDb.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" );
-static const Url instSrc( "dir:/Local/SLES10" );
-//static const Url instSrc( "dir:/Local/FACTORY" );
///////////////////////////////////////////////////////////////////
-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
+ virtual void start( const Resolvable::constPtr & script_r,
+ const Pathname & path_r,
+ Task task_r )
{
- SetTrue( _Condition cond_r )
- : _cond( cond_r )
- {}
-
- template<class _Tp>
- bool operator()( _Tp t ) const
- {
- _cond( t );
- return true;
- }
-
- _Condition _cond;
- };
+ SEC << __FUNCTION__ << endl
+ << " " << script_r << endl
+ << " " << path_r << endl
+ << " " << task_r << endl;
+ }
-template<class _Condition>
- inline SetTrue<_Condition> setTrue_c( _Condition cond_r )
+ virtual bool progress( Notify notify_r, const std::string & text_r )
{
- return SetTrue<_Condition>( cond_r );
+ SEC << __FUNCTION__ << endl
+ << " " << notify_r << endl
+ << " " << text_r << endl;
+ return true;
}
-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 void problem( const std::string & description_r )
{
- for ( _Iterator it = begin_r; it != end_r; ++it )
- {
- if ( filter_r( *it ) )
- {
- fnc_r( *it );
- }
- }
- return fnc_r;
+ SEC << __FUNCTION__ << endl
+ << " " << description_r << endl;
}
-struct PrintPoolItem
-{
- void operator()( const PoolItem & pi ) const
+ virtual void finish()
{
- USR << "S" << pi->source().numericId()
- << "/M" << mediaId(pi)
- << " " << pi << endl;
+ SEC << __FUNCTION__ << endl;
}
- unsigned mediaId( const PoolItem & pi ) const
+
+};
+
+///////////////////////////////////////////////////////////////////
+
+struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
+{
+ virtual Action requestMedia( Source_Ref source
+ , unsigned mediumNr
+ , Error error
+ , const std::string & description )
{
- Package::constPtr pkg( asKind<Package>(pi.resolvable()) );
- if ( pkg )
- return pkg->mediaId();
- return 0;
+ SEC << __FUNCTION__ << endl
+ << " " << source << endl
+ << " " << mediumNr << endl
+ << " " << error << endl
+ << " " << description << endl;
+ return IGNORE;
}
};
-template <class _Iterator>
- std::ostream & vdumpPoolStats( std::ostream & str,
- _Iterator begin_r, _Iterator end_r )
- {
- pool::PoolStats stats;
- std::for_each( begin_r, end_r,
+///////////////////////////////////////////////////////////////////
- functor::chain( setTrue_c(PrintPoolItem()),
- setTrue_c(functor::functorRef<void,ResObject::constPtr>(stats)) )
+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(); }
+}
- );
- return str << stats;
- }
+///////////////////////////////////////////////////////////////////
-struct PoolItemSelect
+struct AddResolvables
{
- void operator()( const PoolItem & pi ) const
+ bool operator()( const Source_Ref & src ) const
{
- if ( pi->source().numericId() == 2 )
- pi.status().setTransact( true, ResStatus::USER );
+ getZYpp()->addResolvables( src.resolvables() );
+ return true;
}
};
///////////////////////////////////////////////////////////////////
-typedef std::list<PoolItem> PoolItemList;
-typedef std::set<PoolItem> PoolItemSet;
-#include "zypp/solver/detail/InstallOrder.h"
-using zypp::solver::detail::InstallOrder;
-#include "Iorder.h"
+
+
+std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
+{
+ str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
+ return str;
+
+}
///////////////////////////////////////////////////////////////////
namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+
+using namespace zypp::parser::susetags;
+#include "zypp/cache/CacheStore.h"
+
+void consumeIndex( const parser::susetags::RepoIndex_Ptr & index_r )
{
- struct CollectTransacting
- {
- typedef std::list<PoolItem> PoolItemList;
+ SEC << "[Index]" << index_r << endl;
+}
- 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 );
- }
- }
+void consumeProd( const data::Product_Ptr & prod_r )
+{
+ SEC << "[Prod]" << prod_r << endl;
+}
- PoolItemSet _toInstall;
- PoolItemSet _toDelete;
- PoolItemSet _skipToDelete;
- };
+void consumePkg( const data::Package_Ptr & pkg_r )
+{
+ //MIL << "[Pkg]" << pkg_r << endl;
+}
- 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;
- }
+void consumeSrcPkg( const data::SrcPackage_Ptr & pkg_r )
+{
+ //DBG << "[Src]" << pkg_r << endl;
}
-///////////////////////////////////////////////////////////////////
-#if 0
-template<class _InstIterator, class _DelIterator, class _OutputIterator>
-void strip_obsoleted_to_delete( _InstIterator instBegin_r, _InstIterator instEnd_r,
- _DelIterator delBegin_r, _DelIterator delEnd_r,
- _OutputIterator skip_r )
- {
- if ( instBegin_r == instEnd_r
- || delBegin_r == delEnd_r )
- return; // ---> nothing to do
+void consumePat( const data::Pattern_Ptr & pat_r )
+{
+ MIL << "[Pat]" << pat_r << endl;
+}
- // build obsoletes from inst
- CapSet obsoletes;
- for ( /**/; instBegin_r != instEnd_r; ++instBegin_r )
- {
- //xxxxx
- //PoolItem_Ref item( *it );
- //obsoletes.insert( item->dep(Dep::OBSOLETES).begin(), item->dep(Dep::OBSOLETES).end() );
- }
- if ( obsoletes.size() == 0 )
- return; // ---> nothing to do
-
- // match them... ;(
- PoolItemList undelayed;
- // forall applDelete Packages...
- for ( PoolItemList::iterator it = deleteList_r.begin();
- it != deleteList_r.end(); ++it )
- {
- PoolItem_Ref ipkg( *it );
- bool delayPkg = false;
- // ...check whether an obsoletes....
- for ( CapSet::iterator obs = obsoletes.begin();
- ! delayPkg && obs != obsoletes.end(); ++obs )
- {
- // ...matches anything provided by the package?
- for ( CapSet::const_iterator prov = ipkg->dep(Dep::PROVIDES).begin();
- prov != ipkg->dep(Dep::PROVIDES).end(); ++prov )
- {
- if ( obs->matches( *prov ) == CapMatch::yes )
- {
- // if so, delay package deletion
- DBG << "Ignore appl_delete (should be obsoleted): " << ipkg << endl;
- delayPkg = true;
- ipkg.status().setTransact( false, ResStatus::USER );
- break;
- }
- }
- }
- if ( ! delayPkg ) {
- DBG << "undelayed " << ipkg << endl;
- undelayed.push_back( ipkg );
- }
- }
- // Puhh...
- deleteList_r.swap( undelayed );
+void pPackages( const Pathname & p )
+{
+ Measure x( p.basename() );
+ PackagesFileReader tp;
+ tp.setPkgConsumer( consumePkg );
+ tp.setSrcPkgConsumer( consumeSrcPkg );
+ tp.parse( p );
+}
+void pPackagesLang( const Pathname & p, const Locale & locale_r )
+{
+ Measure x( p.basename() );
+ PackagesLangFileReader tp;
+ tp.setLocale( locale_r );
+ tp.setPkgConsumer( consumePkg );
+ tp.setSrcPkgConsumer( consumeSrcPkg );
+ tp.parse( p );
}
-#endif
-///////////////////////////////////////////////////////////////////
-/******************************************************************
+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() );
- if ( 0 )
- {
- Measure x( "initTarget " + sysRoot.asString() );
- getZYpp()->initTarget( sysRoot );
- getZYpp()->addResolvables( getZYpp()->target()->resolvables(), true );
- INT << "Added target: " << pool << endl;
- }
+ Pathname dbdir( "store" );
+ Pathname reporoot( "lmd" );
- if ( 0 ) {
- SourceManager::sourceManager()->restore( sysRoot );
- if ( SourceManager::sourceManager()->allSources().empty() )
- {
- Source_Ref src( createSource( instSrc ) );
- SourceManager::sourceManager()->addSource( src );
- SourceManager::sourceManager()->store( sysRoot, true );
- }
+ cache::CacheStore store( dbdir );
+ data::RecordId repositoryId = store.lookupOrAppendRepository( Url("dir:///"), "/" );
+ {
+ Measure x( "XXXXXXXXXXXXX" );
- Source_Ref src( *SourceManager::sourceManager()->Source_begin() );
- getZYpp()->addResolvables( src.resolvables() );
- INT << "Added source: " << pool << endl;
+ parser::susetags::RepoParser repo( repositoryId, store );
+ repo.parse( reporoot );
+
+ store.commit();
}
- Source_Ref src2( createSource( "dir:/Local/SUSE-Linux-10.1-Build_830-i386/CD1" ) );
- return 0;
- Source_Ref src1( createSource( "dir:/Local/SUSE-Linux-10.1-Build_830-Addon-BiArch/CD1" ) );
- INT << "Pool: " << pool << endl;
- getZYpp()->addResolvables( src1.resolvables() );
- INT << "Added source1: " << pool << endl;
- getZYpp()->addResolvables( src2.resolvables() );
- INT << "Added source2: " << pool << endl;
-
- NameKindProxy s( nameKindProxy<Selection>( pool, "default" ) );
- MIL << s << endl;
- if ( ! s.availableEmpty() )
- {
- PoolItem def( * s.availableBegin() );
- def.status().setTransact( true, ResStatus::USER );
- }
- bool eres, rres;
+#if 0
+ ContentFileReader tp;
+ tp.setProductConsumer( consumeProd );
+ tp.setRepoIndexConsumer( consumeIndex );
+ //tp.setSrcPkgConsumer( consumeSrcPkg );
+ tp.parse( p );
+
+
+ //try
{
- zypp::base::LogControl::TmpLineWriter shutUp;
- eres = getZYpp()->resolver()->establishPool();
- rres = getZYpp()->resolver()->resolvePool();
- }
- MIL << "est " << eres << " slv " << rres << endl;
+ //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"), "/" );
- for_each( pool.byKindBegin<Package>(), pool.byKindEnd<Package>(),
- PoolItemSelect() );
- INT << "FIN: " << pool << endl;
- vdumpPoolStats( INT,
- make_filter_begin<resfilter::ByTransact>(pool),
- make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+ RepoParser( metadir, repositoryId, store );
- if ( 1 )
+ }
+
+ try
{
- PoolItemList errors_r;
- PoolItemList remaining_r;
- PoolItemList srcremaining_r;
- commit( pool, 0, errors_r, remaining_r, srcremaining_r, false );
+ ZYpp::Ptr z = getZYpp();
+
+ Pathname dbfile( "data.db" );
+ cache::CacheStore store(getenv("PWD"));
- dumpPoolStats( WAR << "remaining_r ", remaining_r.begin(), remaining_r.end() ) << endl;
- dumpPoolStats( WAR << "srcremaining_r ", srcremaining_r.begin(), srcremaining_r.end() ) << endl;
+ 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();
}
- else
+ catch ( const Exception &e )
{
- CollectTransacting toTransact;
- std::for_each( make_filter_begin<resfilter::ByTransact>(pool),
- make_filter_end<resfilter::ByTransact>(pool),
- functor::functorRef<void,PoolItem>(toTransact) );
- MIL << toTransact;
+ cout << "ups! " << e.msg() << std::endl;
}
-
-#if 0
- Source_Ref src( *SourceManager::sourceManager()->Source_begin() );
- const std::list<Pathname> srcKeys( src.publicKeys() );
- MIL << src << endl;
- DBG << srcKeys << endl;
-
- target::rpm::RpmDb rpm;
- rpm.initDatabase( sysRoot );
- std::set<Edition> rpmKeys( rpm.pubkeys() );
- MIL << rpm << endl;
- DBG << rpmKeys << endl;
-
- ResPool pool( getZYpp()->pool() );
- getZYpp()->addResolvables( src.resolvables() );
- SEC << pool << endl;
-
- rpm.closeDatabase();
#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;
}