zypper port starts. zypp2 to zypp
[platform/upstream/libzypp.git] / devel / devel.ma / Parse.cc
index e2c9086..2556a71 100644 (file)
-#include <ctime>
+#include "Tools.h"
 
-#include <iostream>
-#include <list>
-#include <map>
-#include <set>
-
-#include <zypp/base/Logger.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/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/SourceFactory.h>
-#include <zypp/source/susetags/SuseTagsImpl.h>
-
-#include "zypp/ResPoolManager.h"
-#include "zypp/ui/Selectable.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::functor;
-using namespace zypp::resfilter;
+
+using zypp::parser::tagfile::TagFileParser;
+using zypp::parser::TagParser;
+
+///////////////////////////////////////////////////////////////////
+
+static const Pathname sysRoot( "/Local/ROOT" );
 
 ///////////////////////////////////////////////////////////////////
 
-struct Print : public std::unary_function<ResObject::constPtr, bool>
+struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
 {
-  bool operator()( ResObject::constPtr ptr )
+  virtual void start( const Resolvable::constPtr & script_r,
+                      const Pathname & path_r,
+                      Task task_r )
   {
-    USR << *ptr << endl;
-    return true;
+    SEC << __FUNCTION__ << endl
+    << "  " << script_r << endl
+    << "  " << path_r   << endl
+    << "  " << task_r   << endl;
   }
-};
-
-///////////////////////////////////////////////////////////////////
 
-template<class _IntT>
-  struct Counter
+  virtual bool progress( Notify notify_r, const std::string & text_r )
   {
-    Counter()
-    : _value( _IntT(0) )
-    {}
+    SEC << __FUNCTION__ << endl
+    << "  " << notify_r << endl
+    << "  " << text_r   << endl;
+    return true;
+  }
 
-    Counter( _IntT value_r )
-    : _value( _IntT( value_r ) )
-    {}
+  virtual void problem( const std::string & description_r )
+  {
+    SEC << __FUNCTION__ << endl
+    << "  " << description_r << endl;
+  }
 
-    operator _IntT &()
-    { return _value; }
+  virtual void finish()
+  {
+    SEC << __FUNCTION__ << endl;
+  }
 
-    operator const _IntT &() const
-    { return _value; }
+};
 
-    _IntT _value;
-  };
+///////////////////////////////////////////////////////////////////
 
-struct Rstats : public std::unary_function<ResObject::constPtr, void>
+struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
 {
-  void operator()( ResObject::constPtr ptr )
+  virtual Action requestMedia( Source_Ref source
+                               , unsigned mediumNr
+                               , Error error
+                               , const std::string & description )
   {
-    ++_total;
-    ++_perKind[ptr->kind()];
+    SEC << __FUNCTION__ << endl
+    << "  " << source << endl
+    << "  " << mediumNr << endl
+    << "  " << error << endl
+    << "  " << description << endl;
+    return IGNORE;
   }
-
-  typedef std::map<ResolvableTraits::KindType,Counter<unsigned> > KindMap;
-  Counter<unsigned> _total;
-  KindMap           _perKind;
 };
 
-std::ostream & operator<<( std::ostream & str, const Rstats & obj )
+///////////////////////////////////////////////////////////////////
+
+namespace container
 {
-  str << "Total: " << obj._total;
-  for( Rstats::KindMap::const_iterator it = obj._perKind.begin(); it != obj._perKind.end(); ++it )
-    {
-      str << endl << "  " << it->first << ":\t" << it->second;
-    }
-  return str;
+  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 _Iterator>
-  void rstats( _Iterator begin, _Iterator end )
+///////////////////////////////////////////////////////////////////
+
+struct AddResolvables
+{
+  bool operator()( const Source_Ref & src ) const
   {
-    DBG << __PRETTY_FUNCTION__ << endl;
-    Rstats stats;
-    for_each( begin, end, functorRef<void,ResObject::constPtr>(stats) );
-    MIL << stats << endl;
+    getZYpp()->addResolvables( src.resolvables() );
+    return true;
   }
+};
 
 ///////////////////////////////////////////////////////////////////
 
-namespace zypp { namespace ui
+
+std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
 {
+  str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
+  return str;
 
-  struct PP
-  {
-    typedef std::set<ResPool::Item>         ItemC;
-    struct SelC
-    {
-      void add( ResPool::Item it )
-      { available.insert( it ); }
-      ItemC installed;
-      ItemC available;
-    };
-    typedef std::map<std::string,SelC>      NameC;
-    typedef std::map<ResObject::Kind,NameC> KindC;
+}
 
-    KindC _kinds;
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
 
-    void operator()( ResPool::Item it )
-    {
-      _kinds[it->kind()][it->name()].add( it );
-    }
+using namespace zypp::parser::susetags;
+#include "zypp/cache/CacheStore.h"
 
-    void dumpOn() const
-    {
-      for ( KindC::const_iterator it = _kinds.begin(); it != _kinds.end(); ++it )
-        {
-          ERR << it->first << endl;
-          for ( NameC::const_iterator nit = it->second.begin(); nit != it->second.end(); ++nit )
-            {
-              WAR << nit->first << endl;
-              MIL << "i " << nit->second.installed.size()
-                  << " a " << nit->second.available.size() << endl;
-            }
-        }
-    }
-  };
-
-  class ResPoolProxy
-  {
-  public:
+void consumeIndex( const parser::susetags::RepoIndex_Ptr & index_r )
+{
+  SEC << "[Index]" << index_r << endl;
+}
 
-  };
+void consumeProd( const data::Product_Ptr & prod_r )
+{
+  SEC << "[Prod]" << prod_r << endl;
+}
 
+void consumePkg( const data::Package_Ptr & pkg_r )
+{
+  //MIL << "[Pkg]" << pkg_r << endl;
+}
 
+void consumeSrcPkg( const data::SrcPackage_Ptr & pkg_r )
+{
+  //DBG << "[Src]" << pkg_r << endl;
+}
 
-}}
+void consumePat( const data::Pattern_Ptr & pat_r )
+{
+  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 );
+}
 
+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 );
+}
 
-///////////////////////////////////////////////////////////////////
+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[] )
 {
-  string infile( "p" );
-  if (argc >= 2 )
-    infile = argv[1];
+  //zypp::base::LogControl::instance().logfile( "log.restrict" );
+  INT << "===[START]==========================================" << endl;
+
+  Pathname dbdir( "store" );
+  Pathname reporoot( "lmd" );
+
+  cache::CacheStore store( dbdir );
+  data::RecordId repositoryId = store.lookupOrAppendRepository( Url("dir:///"), "/" );
+  {
+    Measure x( "XXXXXXXXXXXXX" );
+
+    parser::susetags::RepoParser repo( repositoryId, store );
+    repo.parse( reporoot );
+
+    store.commit();
+  }
+
+
+#if 0
+  ContentFileReader tp;
+  tp.setProductConsumer( consumeProd );
+  tp.setRepoIndexConsumer( consumeIndex );
+  //tp.setSrcPkgConsumer( consumeSrcPkg );
+  tp.parse( p );
+
+
+  //try
+  {
+    //Pathname dbdir( "/Local/ma/zypp-TRUNK/BUILD/libzypp/devel/devel.ma/store" );
+
+
+    Pathname dbdir( "store" );
+    Pathname metadir( "lmd" );
 
-  Source_Ref src( SourceFactory().createFrom( new source::susetags::SuseTagsImpl(infile) ) );
-  MIL << src.resolvables().size() << endl;
+    cache::CacheStore store( dbdir );
+    data::RecordId repositoryId = store.lookupOrAppendRepository( Url("http://www.google.com"), "/" );
 
-  ResPoolManager pool;
-  pool.insert( src.resolvables().begin(), src.resolvables().end() );
-  MIL << pool << endl;
+    RepoParser( metadir, repositoryId, store );
 
-  ResPool query( pool.accessor() );
-  rstats( query.begin(), query.end() );
+  }
 
-  ui::PP collect;
-  for_each( query.begin(), query.end(),
-            functorRef<void,ResPool::Item>( collect ) );
-  collect.dumpOn();
+    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;
 }