Author: mlandres
Date: Wed May 23 10:05:52 2007
New Revision: 5598
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5598&view=rev
Log:
add susetags::RepoParser
Added:
trunk/libzypp/zypp2/parser/susetags/
trunk/libzypp/zypp2/parser/susetags/RepoParser.cc
trunk/libzypp/zypp2/parser/susetags/RepoParser.h
Modified:
trunk/libzypp/zypp2/CMakeLists.txt
Modified: trunk/libzypp/zypp2/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/CMakeLists.txt?rev=5598&r1=5597&r2=5598&view=diff
==============================================================================
--- trunk/libzypp/zypp2/CMakeLists.txt (original)
+++ trunk/libzypp/zypp2/CMakeLists.txt Wed May 23 10:05:52 2007
@@ -112,6 +112,14 @@
repository/memory/DSrcPackageImpl.h
)
+SET( zypp2_parser_susetags_SRCS
+ parser/susetags/RepoParser.cc
+)
+
+SET( zypp2_parser_susetags_HEADERS
+ parser/susetags/RepoParser.h
+)
+
SET( zypp2_parser_yum_SRCS
parser/yum/YUMParser.cc
)
@@ -133,6 +141,7 @@
${zypp2_repository_cached_SRCS}
${zypp2_repository_data_SRCS}
${zypp2_cache_sqlite3x_SRCS}
+${zypp2_parser_susetags_SRCS}
${zypp2_parser_yum_SRCS}
)
@@ -141,6 +150,7 @@
${zypp2_HEADERS}
${zypp2_cache_HEADERS}
${zypp2_cache_sqlite3x_HEADERS}
+${zypp2_parser_susetags_HEADERS}
${zypp2_parser_yum_HEADERS}
)
Added: trunk/libzypp/zypp2/parser/susetags/RepoParser.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/parser/susetags/RepoParser.cc?rev=5598&view=auto
==============================================================================
--- trunk/libzypp/zypp2/parser/susetags/RepoParser.cc (added)
+++ trunk/libzypp/zypp2/parser/susetags/RepoParser.cc Wed May 23 10:05:52 2007
@@ -0,0 +1,218 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp2/parser/susetags/RepoParser.cc
+ *
+*/
+#include <iostream>
+#include "zypp/base/Logger.h"
+#include "zypp/base/Iterator.h"
+#include "zypp/base/String.h"
+
+#include "zypp2/parser/susetags/RepoParser.h"
+#include "zypp/parser/susetags/ContentFileReader.h"
+#include "zypp/parser/susetags/PackagesFileReader.h"
+#include "zypp/parser/susetags/PackagesLangFileReader.h"
+#include "zypp/parser/susetags/PatternFileReader.h"
+#include "zypp/parser/susetags/RepoIndex.h"
+#include "zypp/parser/tagfile/ParseException.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace parser
+ { /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace susetags
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : RepoParser::Impl
+ //
+ /** RepoParser implementation. */
+ class RepoParser::Impl
+ {
+ public:
+ Impl( const data::RecordId & catalogId_r,
+ data::ResolvableDataConsumer & consumer_r,
+ const ProgressData::ReceiverFnc & fnc_r )
+ : _catalogId( catalogId_r )
+ , _consumer( consumer_r )
+ {
+ _ticks.sendTo( fnc_r );
+ }
+
+ void parse( const Pathname & reporoot_r );
+
+ void consumeIndex( const RepoIndex_Ptr & data_r )
+ {
+ SEC << "[Index]" << data_r << endl;
+ _repoIndex = data_r;
+ }
+
+ void consumeProd( const data::Product_Ptr & data_r )
+ {
+ SEC << "[Prod]" << data_r << endl;
+ _prodData = data_r;
+ _consumer.consumeProduct( _catalogId, _prodData );
+ }
+
+ void consumePkg( const data::Package_Ptr & data_r )
+ {
+ SEC << "[Package]" << data_r << endl;
+ }
+
+ void consumeSrcPkg( const data::SrcPackage_Ptr & data_r )
+ {
+ SEC << "[SrcPackage]" << data_r << endl;
+ }
+
+ void consumePat( const data::Pattern_Ptr & data_r )
+ {
+ SEC << "[Pattern]" << data_r << endl;
+ }
+
+ public:
+
+ bool isPatternFile( const std::string & name_r ) const
+ {
+ return( name_r.size() > 4 && name_r.substr( name_r.size() - 4 ) == ".pat" );
+ }
+
+ private:
+ data::RecordId _catalogId;
+ data::ResolvableDataConsumer & _consumer;
+ ProgressData _ticks;
+
+ RepoIndex_Ptr _repoIndex;
+ data::Product_Ptr _prodData;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : RepoParser::Impl::parse
+ // METHOD TYPE : void
+ //
+ void RepoParser::Impl::parse( const Pathname & reporoot_r )
+ {
+ _prodData = 0;
+ _repoIndex = 0;
+
+ // Content file first to get the repoindex
+ {
+ ContentFileReader content;
+ content.setProductConsumer( bind( &Impl::consumeProd, this, _1 ) );
+ content.setRepoIndexConsumer( bind( &Impl::consumeIndex, this, _1 ) );
+ content.parse( reporoot_r / "content" );
+ }
+ if ( ! _repoIndex )
+ {
+ ZYPP_THROW( ParseException( reporoot_r.asString() + ": " + "No reository index in content file." ) );
+ }
+
+ DBG << _repoIndex << endl;
+ Pathname descrdir( reporoot_r / _repoIndex->descrdir );
+
+ _ticks.name( "Parsing susetags repo at " + reporoot_r.asString() );
+ _ticks.range( _repoIndex->metaFileChecksums.size() );
+ if ( ! _ticks.toMin() )
+ ZYPP_THROW( AbortRequestException() );
+
+ // Start with packages
+ {
+ PackagesFileReader reader;
+ reader.setPkgConsumer( bind( &Impl::consumePkg, this, _1 ) );
+ reader.setSrcPkgConsumer( bind( &Impl::consumeSrcPkg, this, _1 ) );
+ reader.parse( descrdir / "packages" );
+ }
+ if ( ! _ticks.incr() )
+ ZYPP_THROW( AbortRequestException() );
+
+#warning FIX selection of language files to parse
+ // Now process packages.lang
+ //for ( RepoIndex::FileChecksumMap::const_iterator it = _repoIndex->metaFileChecksums.begin();
+ // it != _repoIndex->metaFileChecksums.end(); ++it )
+ {
+ PackagesLangFileReader reader;
+ reader.setLocale( Locale("en") );
+ reader.setPkgConsumer( bind( &Impl::consumePkg, this, _1 ) );
+ reader.setSrcPkgConsumer( bind( &Impl::consumeSrcPkg, this, _1 ) );
+ reader.parse( descrdir / "packages.en" );
+ }
+ if ( ! _ticks.incr() )
+ ZYPP_THROW( AbortRequestException() );
+
+
+ // Now process the RepoIndex
+ for ( RepoIndex::FileChecksumMap::const_iterator it = _repoIndex->metaFileChecksums.begin();
+ it != _repoIndex->metaFileChecksums.end(); ++it )
+ {
+ if ( isPatternFile( it->first ) )
+ {
+ PatternFileReader reader;
+ reader.setConsumer( bind( &Impl::consumePat, this, _1 ) );
+ reader.parse( descrdir / it->first );
+ }
+
+ if ( ! _ticks.incr() )
+ ZYPP_THROW( AbortRequestException() );
+ }
+
+ // Done
+ if ( ! _ticks.toMax() )
+ ZYPP_THROW( AbortRequestException() );
+ }
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : RepoParser
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : RepoParser::RepoParser
+ // METHOD TYPE : Ctor
+ //
+ RepoParser::RepoParser( const data::RecordId & catalogId_r,
+ data::ResolvableDataConsumer & consumer_r,
+ const ProgressData::ReceiverFnc & fnc_r )
+ : _pimpl( new Impl( catalogId_r, consumer_r, fnc_r ) )
+ {}
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : RepoParser::~RepoParser
+ // METHOD TYPE : Dtor
+ //
+ RepoParser::~RepoParser()
+ {}
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : RepoParser::parse
+ // METHOD TYPE : void
+ //
+ void RepoParser::parse( const Pathname & reporoot_r )
+ {
+ _pimpl->parse( reporoot_r );
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace susetags
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace parser
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
Added: trunk/libzypp/zypp2/parser/susetags/RepoParser.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/parser/susetags/RepoParser.h?rev=5598&view=auto
==============================================================================
--- trunk/libzypp/zypp2/parser/susetags/RepoParser.h (added)
+++ trunk/libzypp/zypp2/parser/susetags/RepoParser.h Wed May 23 10:05:52 2007
@@ -0,0 +1,80 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp2/parser/susetags/RepoParser.h
+ *
+*/
+#ifndef ZYPP2_PARSER_SUSETAGS_REPOPARSER_H
+#define ZYPP2_PARSER_SUSETAGS_REPOPARSER_H
+
+#include <iosfwd>
+
+#include "zypp/base/PtrTypes.h"
+#include "zypp/base/NonCopyable.h"
+
+#include "zypp/data/RecordId.h"
+#include "zypp/data/ResolvableDataConsumer.h"
+
+#include "zypp/ProgressData.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace parser
+ { /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace susetags
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : RepoParser
+ //
+ /** SuseTags metadata parser.
+ * \todo more doc and Exception specification
+ */
+ class RepoParser : private base::NonCopyable
+ {
+ public:
+ /** Ctor.
+ *
+ * \param catalogId_r repository identifier
+ * \param consumer_r consumer of parsed data
+ * \param fnc_r progress reporting function
+ */
+ RepoParser( const data::RecordId & catalogId_r,
+ data::ResolvableDataConsumer & consumer_r,
+ const ProgressData::ReceiverFnc & fnc_r = ProgressData::ReceiverFnc() );
+ /** Dtor */
+ ~RepoParser();
+
+ /** Parse a local repository located at \a reporoot_r.
+ *
+ * \param reporoot_r The local repositories root directory.
+ * \throw Exception on errors.
+ */
+ void parse( const Pathname & reporoot_r );
+
+ public:
+ class Impl;
+ private:
+ RW_pointer