Author: mlandres
Date: Fri May 9 18:59:21 2008
New Revision: 10027
URL: http://svn.opensuse.org/viewcvs/zypp?rev=10027&view=rev
Log:
Added );
Added:
trunk/libzypp/zypp/parser/ProductConfReader.cc
trunk/libzypp/zypp/parser/ProductConfReader.h
Modified:
trunk/libzypp/devel/devel.ma/NewPool.cc
trunk/libzypp/zypp/CMakeLists.txt
Modified: trunk/libzypp/devel/devel.ma/NewPool.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/NewPool.cc?rev=10027&r1=10026&r2=10027&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.ma/NewPool.cc (original)
+++ trunk/libzypp/devel/devel.ma/NewPool.cc Fri May 9 18:59:21 2008
@@ -44,8 +44,7 @@
#include "zypp/sat/detail/PoolImpl.h"
#include "zypp/PoolQuery.h"
-#include
-#include
+#include "zypp/parser/ProductConfReader.h"
#include
@@ -458,71 +457,11 @@
namespace zypp
{
- struct ProductConfData
- {
- IdString _name;
- Edition _edition;
- Arch _arch;
-
- IdString _distName;
- Edition _distEdition;
- };
-
- class ProductConfReader
- {
- public:
- typedef function Consumer;
-
- public:
- ProductConfReader()
- {}
-
- ProductConfReader( const Consumer & consumer_r )
- : _consumer( consumer_r )
- {}
-
- ProductConfReader( const Consumer & consumer_r, const InputStream & input_r )
- : _consumer( consumer_r )
- { parse( input_r ); }
-
- public:
- const Consumer & consumer() const
- { return _consumer; }
-
- void setConsumer( const Consumer & consumer_r )
- { _consumer = consumer_r; }
-
- public:
- void parse( const InputStream & input = InputStream() ) const;
-
- private:
- Consumer _consumer;
- };
-
- void ProductConfReader::parse( const InputStream & input_r ) const
- {
- WAR << "+++" << input_r << endl;
- parser::IniDict dict( input_r );
-
- for_( sit, dict.sectionsBegin(), dict.sectionsEnd() )
- {
- string section(*sit);
- MIL << section << endl;
- for_( it, dict.entriesBegin(*sit), dict.entriesEnd(*sit) )
- {
- string entry( it->first );
- string value( it->second );
- DBG << (*it).first << "=" << (*it).second << endl;
- }
-
- }
- WAR << "---" << input_r << endl;
- }
}
-bool PCDC( const ProductConfData & d )
+bool PCDC( const parser::ProductConfData & d )
{
- SEC << endl;
+ SEC << d << endl;
return true;
}
@@ -539,7 +478,8 @@
INT << "===[START]==========================================" << endl;
ZConfig::instance();
- ProductConfReader r( &PCDC, "test.prod" );
+ //parser::ProductConfReader r( &PCDC, "test.prod" );
+ parser::ProductConfReader::scanDir( &PCDC, "." );
///////////////////////////////////////////////////////////////////
INT << "===[END]============================================" << endl << endl;
Modified: trunk/libzypp/zypp/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=10027&r1=10026&r2=10027&view=diff
==============================================================================
--- trunk/libzypp/zypp/CMakeLists.txt (original)
+++ trunk/libzypp/zypp/CMakeLists.txt Fri May 9 18:59:21 2008
@@ -338,6 +338,7 @@
parser/LibXMLHelper.cc
parser/XMLNodeIterator.cc
parser/RepoFileReader.cc
+ parser/ProductConfReader.cc
parser/xml_escape_parser.cpp
)
@@ -351,6 +352,7 @@
parser/XMLNodeIterator.h
parser/xml_parser_assert.h
parser/RepoFileReader.h
+ parser/ProductConfReader.h
parser/xml_escape_parser.hpp
)
Added: trunk/libzypp/zypp/parser/ProductConfReader.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/ProductConfReader.cc?rev=10027&view=auto
==============================================================================
--- trunk/libzypp/zypp/parser/ProductConfReader.cc (added)
+++ trunk/libzypp/zypp/parser/ProductConfReader.cc Fri May 9 18:59:21 2008
@@ -0,0 +1,132 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/ProductConfReader.cc
+ *
+*/
+#include <iostream>
+#include "zypp/base/Logger.h"
+
+#include "zypp/PathInfo.h"
+
+#include "zypp/parser/ProductConfReader.h"
+#include "zypp/parser/IniDict.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace parser
+ { /////////////////////////////////////////////////////////////////
+
+ std::ostream & operator<<( std::ostream & str, const ProductConfData & obj )
+ {
+ str << str::form( "|product|%s|%s|%s|%s|%s|",
+ obj.name().c_str(),
+ obj.edition().c_str(),
+ obj.arch().c_str(),
+ obj.distName().c_str(),
+ obj.distEdition().c_str() );
+ return str;
+ }
+
+ bool ProductConfReader::parse( const InputStream & input_r ) const
+ {
+ parser::IniDict dict( input_r );
+
+ for_( sit, dict.sectionsBegin(), dict.sectionsEnd() )
+ {
+ std::string section( *sit );
+ ProductConfData data;
+
+ // last word is arch (%a substituted by system arch)
+ std::string word( str::stripLastWord( section, /*rtrim_first*/true ) );
+ if ( word.empty() )
+ {
+ ERR << "Malformed section without architecture ignored [" << *sit << "]" << endl;
+ continue;
+ }
+ data._arch = Arch( word == "%arch" ? "" : word );
+
+ // one but last word is edition
+ word = str::stripLastWord( section, /*rtrim_first*/true );
+ if ( word.empty() )
+ {
+ ERR << "Malformed section without edition ignored [" << *sit << "]" << endl;
+ continue;
+ }
+ data._edition = Edition( word );
+
+ // all the rest is name
+ if ( section.empty() )
+ {
+ ERR << "Malformed section without name ignored [" << *sit << "]" << endl;
+ continue;
+ }
+ data._name = IdString( section );
+
+ // now the attributes:
+ for_( it, dict.entriesBegin(*sit), dict.entriesEnd(*sit) )
+ {
+ std::string entry( it->first );
+ std::string value( it->second );
+ if ( entry == "distproduct" )
+ {
+ data._distName = IdString( value );
+ }
+ else if ( entry == "distversion" )
+ {
+ data._distEdition = Edition( value );
+ }
+ else
+ {
+ WAR << "Unknown Key: "<< entry << "=" << value << endl;
+ }
+ }
+
+ if ( _consumer && ! _consumer( data ) )
+ {
+ MIL << "Stop consuming " << input_r << endl;
+ return false;
+ }
+ }
+ return true;
+ }
+
+ bool ProductConfReader::scanDir( const Consumer & consumer_r, const Pathname & dir_r )
+ {
+ DBG << "+++ scanDir " << dir_r << endl;
+
+ std::list<Pathname> retlist;
+ int res = filesystem::readdir( retlist, dir_r, /*dots*/false );
+ if ( res != 0 )
+ {
+ WAR << "scanDir " << dir_r << " failed (" << res << ")" << endl;
+ return true;
+ }
+
+ ProductConfReader reader( consumer_r );
+ for_( it, retlist.begin(), retlist.end() )
+ {
+ if ( it->extension() == ".prod" && ! reader.parse( *it ) )
+ {
+ return false; // consumer_r request to stop parsing.
+ }
+ }
+ DBG << "--- scanDir " << dir_r << endl;
+ return true;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace parser
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
Added: trunk/libzypp/zypp/parser/ProductConfReader.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/ProductConfReader.h?rev=10027&view=auto
==============================================================================
--- trunk/libzypp/zypp/parser/ProductConfReader.h (added)
+++ trunk/libzypp/zypp/parser/ProductConfReader.h Fri May 9 18:59:21 2008
@@ -0,0 +1,156 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/ProductConfReader.h
+ *
+*/
+#ifndef ZYPP_PARSER_PRODUCTCONFREADER_H
+#define ZYPP_PARSER_PRODUCTCONFREADER_H
+
+#include <iosfwd>
+
+#include "zypp/base/Function.h"
+#include "zypp/base/InputStream.h"
+
+#include "zypp/ZConfig.h"
+
+#include "zypp/Pathname.h"
+#include "zypp/IdString.h"
+#include "zypp/Edition.h"
+#include "zypp/Arch.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace parser
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ProductConfData
+ //
+ /** Data returned by \ref ProductConfReader
+ * \see \ref ProductConfReader
+ */
+ class ProductConfData
+ {
+ public:
+ /** Product name */
+ IdString name() const
+ { return _name; }
+
+ /** Product edition */
+ Edition edition() const
+ { return _edition; }
+
+ /** Product arch */
+ Arch arch() const
+ { return _arch.empty() ? ZConfig::instance().systemArchitecture() : _arch; }
+
+ /** Product distName (defaults to \ref name)*/
+ IdString distName() const
+ { return _distName.empty() ? _name : _distName; }
+
+ /** Product distEdition (defaults to \ref edition) */
+ Edition distEdition() const
+ { return _distEdition.empty() ? _edition : _distEdition; }
+
+ public:
+ IdString _name;
+ Edition _edition;
+ Arch _arch;
+
+ IdString _distName;
+ Edition _distEdition;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates ProductConfData Stream output */
+ std::ostream & operator<<( std::ostream & str, const ProductConfData & obj );
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ProductConfReader
+ //
+ /** ProductConfReader (registration helper)
+ * \code
+ * - The file may contain zero or more product sections.
+ * Required format for the section header is:
+ *
+ * [the products name version architecture]
+ *
+ * Last word is architecture,
+ * one but last word is version,
+ * the remaining words are the name.
+ *
+ * Less than 3 words is an error, section is ignored.
+ *
+ * If architecture is "%arch" it is substituted by the sytems architecture.
+ *
+ * - In each section you may define
+ *
+ * distproduct = some dist name
+ * distversion = 1.2.3-4.5
+ * \endcode
+ */
+ class ProductConfReader
+ {
+ public:
+ /** Callback being invoked for each parsed section.
+ * Return \c false to stop parsing.
+ */
+ typedef function Consumer;
+
+ public:
+ ProductConfReader()
+ {}
+
+ ProductConfReader( const Consumer & consumer_r )
+ : _consumer( consumer_r )
+ {}
+
+ ProductConfReader( const Consumer & consumer_r, const InputStream & input_r )
+ : _consumer( consumer_r )
+ { parse( input_r ); }
+
+ public:
+ const Consumer & consumer() const
+ { return _consumer; }
+
+ void setConsumer( const Consumer & consumer_r )
+ { _consumer = consumer_r; }
+
+ public:
+ /** Parse the input stream and call \c _consumer for each
+ * parsed section.
+ *
+ * Returns \c false if the \c _consumer requested to stop parsing.
+ */
+ bool parse( const InputStream & input_r = InputStream() ) const;
+
+ public:
+ /** Parse all <tt>*.prod</tt> files in \c dir_r and call \c consumer_r
+ * for each parsed section.
+ *
+ * Returns \c false if the \c _consumer requested to stop parsing.
+ */
+ static bool scanDir( const Consumer & consumer_r, const Pathname & dir_r );
+
+ private:
+ Consumer _consumer;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace parser
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_PARSER_PRODUCTCONFREADER_H
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org