Author: mlandres
Date: Mon Oct 27 18:30:11 2008
New Revision: 11512
URL: http://svn.opensuse.org/viewcvs/zypp?rev=11512&view=rev
Log:
ProductFileReader skeleton
Added:
trunk/libzypp/zypp/parser/ProductFileReader.cc
trunk/libzypp/zypp/parser/ProductFileReader.h
Modified:
trunk/libzypp/devel/devel.ma/CMakeLists.txt
trunk/libzypp/devel/devel.ma/TransList.cc
trunk/libzypp/zypp/CMakeLists.txt
Modified: trunk/libzypp/devel/devel.ma/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/CMakeLists.txt?rev=11512&r1=11511&r2=11512&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.ma/CMakeLists.txt (original)
+++ trunk/libzypp/devel/devel.ma/CMakeLists.txt Mon Oct 27 18:30:11 2008
@@ -24,7 +24,7 @@
## ############################################################
-FOREACH( loop_var MaTest NewPool DumpSolv Iorder Xml Ex Main FakePool AOUT Parse Test Basic Sat)
+FOREACH( loop_var MaTest NewPool DumpSolv Iorder Xml Ex Main FakePool AOUT Parse Test Basic Sat TransList)
ADD_EXECUTABLE( ${loop_var}
${loop_var}.cc
)
Modified: trunk/libzypp/devel/devel.ma/TransList.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/TransList.cc?rev=11512&r1=11511&r2=11512&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.ma/TransList.cc (original)
+++ trunk/libzypp/devel/devel.ma/TransList.cc Mon Oct 27 18:30:11 2008
@@ -28,9 +28,7 @@
#include "zypp/parser/xml/ParseDef.h"
#include "zypp/parser/xml/ParseDefConsume.h"
-#include "zypp/ZYppFactory.h"
-#include "zypp/SysContent.h"
-
+#include "zypp/parser/ProductFileReader.h"
using namespace std;
using namespace zypp;
@@ -178,26 +176,11 @@
} // namespace zypp
///////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace syscontent
- { /////////////////////////////////////////////////////////////////
- std::ostream & operator<<( std::ostream & str, const Reader::Entry & obj )
- {
- str << "[" << obj.kind() << "]"
- << " " << obj.name()
- << "-" << obj.edition()
- << "." << obj.arch();
- return str;
- }
- /////////////////////////////////////////////////////////////////
- } // namespace syscontent
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
+bool Consumer( const parser::ProductFileData & data_r )
+{
+ MIL << data_r << endl;
+ return true;
+}
/******************************************************************
**
@@ -208,6 +191,12 @@
{
INT << "===[START]==========================================" << endl;
+ {
+ Measure x( "PARSE" );
+ USR << parser::ProductFileReader::scanDir( &Consumer, sysRoot / "etc/products.d" ) << endl;
+ }
+
+#if 0
bool write = false;
bool read = true;
@@ -257,7 +246,7 @@
for_each( contentR.begin(), contentR.end(), Print() );
}
-
+#endif
INT << "===[END]============================================" << endl << endl;
zypp::base::LogControl::instance().logNothing();
return 0;
Modified: trunk/libzypp/zypp/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=11512&r1=11511&r2=11512&view=diff
==============================================================================
--- trunk/libzypp/zypp/CMakeLists.txt (original)
+++ trunk/libzypp/zypp/CMakeLists.txt Mon Oct 27 18:30:11 2008
@@ -318,6 +318,7 @@
parser/RepoFileReader.cc
parser/RepoindexFileReader.cc
parser/ServiceFileReader.cc
+ parser/ProductFileReader.cc
)
SET( zypp_parser_HEADERS
@@ -329,6 +330,7 @@
parser/xml_escape_parser.hpp
parser/RepoindexFileReader.h
parser/ServiceFileReader.h
+ parser/ProductFileReader.h
)
INSTALL( FILES
Added: trunk/libzypp/zypp/parser/ProductFileReader.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/ProductFileReader.cc?rev=11512&view=auto
==============================================================================
--- trunk/libzypp/zypp/parser/ProductFileReader.cc (added)
+++ trunk/libzypp/zypp/parser/ProductFileReader.cc Mon Oct 27 18:30:11 2008
@@ -0,0 +1,165 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/ProductFileReader.cc
+ *
+*/
+#include <iostream>
+#include "zypp/base/Logger.h"
+#include "zypp/base/Exception.h"
+
+#include "zypp/PathInfo.h"
+
+#include "zypp/parser/ProductFileReader.h"
+#include "zypp/parser/xml/Reader.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace parser
+ { /////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ //
+ // class ProductFileData::Upgrade
+ //
+ /////////////////////////////////////////////////////////////////
+
+ struct ProductFileData::Upgrade::Impl
+ {
+ std::string _name;
+ std::string _summary;
+ std::string _product;
+ DefaultIntegral _notify;
+ std::string _status;
+ };
+
+ ProductFileData::Upgrade::Upgrade( Impl * allocated_r )
+ : _pimpl( allocated_r ? allocated_r : new Impl )
+ {}
+
+ std::string ProductFileData::Upgrade::name() const { return _pimpl->_name; }
+ std::string ProductFileData::Upgrade::summary() const { return _pimpl->_summary; }
+ std::string ProductFileData::Upgrade::product() const { return _pimpl->_product; }
+ bool ProductFileData::Upgrade::notify() const { return _pimpl->_notify; }
+ std::string ProductFileData::Upgrade::status() const { return _pimpl->_status; }
+
+ /////////////////////////////////////////////////////////////////
+ //
+ // class ProductFileData
+ //
+ /////////////////////////////////////////////////////////////////
+
+ struct ProductFileData::Impl
+ {
+ IdString _vendor;
+ IdString _name;
+ Edition _edition;
+ Arch _arch;
+
+ std::string _productline;
+ std::string _registerTarget;
+ std::string _registerRelease;
+
+ std::string _updaterepokey;
+
+ Upgrades _upgrades;
+ };
+
+ ProductFileData::ProductFileData( Impl * allocated_r )
+ : _pimpl( allocated_r ? allocated_r : new Impl )
+ {}
+
+ IdString ProductFileData::vendor() const { return _pimpl->_vendor; }
+ IdString ProductFileData::name() const { return _pimpl->_name; }
+ Edition ProductFileData::edition() const { return _pimpl->_edition; }
+ Arch ProductFileData::arch() const { return _pimpl->_arch; }
+
+ std::string ProductFileData::productline() const { return _pimpl->_productline; }
+ std::string ProductFileData::registerTarget() const { return _pimpl->_registerTarget; }
+ std::string ProductFileData::registerRelease() const { return _pimpl->_registerRelease; }
+
+ std::string ProductFileData::updaterepokey() const { return _pimpl->_updaterepokey; }
+
+ const ProductFileData::Upgrades & ProductFileData::upgrades() const { return _pimpl->_upgrades; }
+
+ std::ostream & operator<<( std::ostream & str, const ProductFileData & obj )
+ {
+ str << str::form( "|product|%s|%s|%s|%s|",
+ obj.name().c_str(),
+ obj.edition().c_str(),
+ obj.arch().c_str(),
+ obj.vendor().c_str() );
+ return str;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ //
+ // class ProductFileReader
+ //
+ /////////////////////////////////////////////////////////////////
+ bool consumeNode( xml::Reader & reader_r )
+ {
+ //DBG << *reader_r << endl;
+ return true;
+ }
+
+ bool ProductFileReader::parse( const InputStream & input_r ) const
+ {
+ INT << "+++" << input_r << endl;
+ bool ret = true;
+ try
+ {
+ xml::Reader reader( input_r );
+ ret = reader.foreachNode( consumeNode );
+ }
+ catch ( const Exception & err )
+ {
+ // parse error
+ ERR << err << endl;
+ }
+ INT << "---" << ret << " - " << input_r << endl;
+ return ret;
+ }
+
+ bool ProductFileReader::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;
+ }
+
+ ProductFileReader reader( consumer_r );
+ for_( it, retlist.begin(), retlist.end() )
+ {
+ if ( PathInfo( *it, PathInfo::LSTAT ).isFile() && ! reader.parse( *it ) )
+ {
+ return false; // consumer_r request to stop parsing.
+ }
+ }
+ DBG << "--- scanDir " << dir_r << endl;
+ return true;
+ }
+
+ ProductFileData ProductFileReader::scanFile( const Pathname & dir_r )
+ {
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace parser
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
Added: trunk/libzypp/zypp/parser/ProductFileReader.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/ProductFileReader.h?rev=11512&view=auto
==============================================================================
--- trunk/libzypp/zypp/parser/ProductFileReader.h (added)
+++ trunk/libzypp/zypp/parser/ProductFileReader.h Mon Oct 27 18:30:11 2008
@@ -0,0 +1,157 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/ProductFileReader.h
+ *
+*/
+#ifndef ZYPP_PARSER_PRODUCTSDREADER_H
+#define ZYPP_PARSER_PRODUCTSDREADER_H
+
+#include <iosfwd>
+
+#include "zypp/base/PtrTypes.h"
+#include "zypp/base/Function.h"
+#include "zypp/base/InputStream.h"
+
+#include "zypp/Pathname.h"
+#include "zypp/IdString.h"
+#include "zypp/Edition.h"
+#include "zypp/Arch.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace parser
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ProductFileData
+ //
+ /** Data returned by \ref ProductFileReader
+ * \see \ref ProductFileReader
+ */
+ class ProductFileData
+ {
+ public:
+ class Impl;
+ /** Ctor takes ownership of \c allocated_r. */
+ ProductFileData( Impl * allocated_r = 0 );
+
+ public:
+ IdString vendor() const;
+ IdString name() const;
+ Edition edition() const;
+ Arch arch() const;
+
+ public:
+ std::string productline() const;
+ std::string registerTarget() const;
+ std::string registerRelease() const;
+
+ public:
+ std::string updaterepokey() const;
+
+ public:
+ ///////////////////////////////////////////////////////////////////
+ struct Upgrade
+ {
+ public:
+ class Impl;
+ /** Ctor takes ownership of \c allocated_r. */
+ Upgrade( Impl * allocated_r = 0 );
+
+ public:
+ std::string name() const;
+ std::string summary() const;
+ std::string product() const;
+ bool notify() const;
+ std::string status() const;
+
+ private:
+ RWCOW_pointer<Impl> _pimpl;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ typedef std::vector<Upgrade> Upgrades;
+ const Upgrades & upgrades() const;
+
+ private:
+ RWCOW_pointer<Impl> _pimpl;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates ProductFileData Stream output */
+ std::ostream & operator<<( std::ostream & str, const ProductFileData & obj );
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ProductFileReader
+ //
+ /** Parser for /etc/products.d enries (just relevant entires).
+ */
+ class ProductFileReader
+ {
+ public:
+ /** Callback being invoked for each \ref ProductFileData parsed.
+ * Return \c false to stop parsing.
+ */
+ typedef function Consumer;
+
+ public:
+ ProductFileReader()
+ {}
+
+ ProductFileReader( const Consumer & consumer_r )
+ : _consumer( consumer_r )
+ {}
+
+ ProductFileReader( 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 files (no symlinks) in \c dir_r and call \c consumer_r
+ * for each \ref ProductFileData parsed.
+ *
+ * Returns \c false if the \c _consumer requested to stop parsing.
+ */
+ static bool scanDir( const Consumer & consumer_r, const Pathname & dir_r );
+
+ /** Parse one file (or symlink) and return the \ref ProductFileData parsed.
+ */
+ static ProductFileData scanFile( const Pathname & dir_r );
+
+ private:
+ Consumer _consumer;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace parser
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_PARSER_PRODUCTSDREADER_H
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org