+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/FileReaderBase.h
- *
-*/
-#ifndef ZYPP_PARSER_SUSETAGS_FILEREADERBASE_H
-#define ZYPP_PARSER_SUSETAGS_FILEREADERBASE_H
-
-#include <iosfwd>
-
-#include "zypp/base/PtrTypes.h"
-#include "zypp/parser/TagParser.h"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : FileReaderBase
- //
- /** Common base for susetags::FileReaders. */
- class FileReaderBase : public TagParser
- {
- protected:
- class BaseImpl;
- };
- ///////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_PARSER_SUSETAGS_FILEREADERBASE_H
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/FileReaderBaseImpl.h
- *
-*/
-#ifndef ZYPP_PARSER_SUSETAGS_FILEREADERBASEIMPL_H
-#define ZYPP_PARSER_SUSETAGS_FILEREADERBASEIMPL_H
-
-#include <iosfwd>
-
-#include "zypp/base/Logger.h"
-#include "zypp/base/Function.h"
-
-#include "zypp/parser/susetags/FileReaderBase.h"
-#include "zypp/parser/ParseException.h"
-#include "zypp/data/ResolvableData.h"
-#include "zypp/PathInfo.h"
-
-using std::endl;
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- inline std::string makeSharedIdent( ResKind kind_r,
- const std::string & name_r,
- Edition edition_r,
- Arch arch_r )
- {
- std::string ret( kind_r.asString() );
- ret += ":";
- ret += name_r;
- ret += "-";
- ret += edition_r.asString();
- ret += ".";
- ret += arch_r.asString();
- return ret;
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : FileReaderBase::BaseImpl
- //
- /** Common base for susetags::FileReader implementations. */
- class FileReaderBase::BaseImpl : private base::NonCopyable
- {
- public:
- BaseImpl( const FileReaderBase & parent_r )
- : _parent( parent_r )
- {}
- virtual ~BaseImpl()
- {}
-
- public:
-
- template<class _Res>
- void depAddLine( const std::string & line_r,
- data::DependencyList & deps_r )
- {
- depAddLine( line_r, ResTraits<_Res>::kind, deps_r );
- }
-
- void depAddLine( const std::string & line_r,
- ResKind refers_r,
- data::DependencyList & deps_r )
- {
- deps_r.insert( Capability( line_r, refers_r ) );
- }
-
-
- template<class _Res>
- void depParse( const MultiTagPtr & tag_r,
- data::DependencyList & deps_r )
- {
- depParse( tag_r, ResTraits<_Res>::kind, deps_r );
- }
-
- void depParse( const MultiTagPtr & tag_r,
- ResKind refers_r,
- data::DependencyList & deps_r )
- {
- std::for_each( tag_r->value.begin(),
- tag_r->value.end(),
- boost::bind( &BaseImpl::depAddLine, this, _1, refers_r, boost::ref(deps_r) ) );
- }
-
- public:
- ParseException error( const SingleTagPtr & tag_r,
- const std::string & msg_r = std::string() ) const
- { return ParseException( _parent.errPrefix( tag_r, msg_r ) ); }
-
- ParseException error( const MultiTagPtr & tag_r,
- const std::string & msg_r = std::string() ) const
- { return ParseException( _parent.errPrefix( tag_r, msg_r ) ); }
-
- private:
- const FileReaderBase & _parent;
- };
- ///////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_PARSER_SUSETAGS_FILEREADERBASEIMPL_H
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/PackagesDuFileReader.cc
- *
-*/
-#include <iostream>
-#include <cstdlib>
-#include "zypp/base/Easy.h"
-#include "zypp/base/Regex.h"
-#include "zypp/base/Logger.h"
-#include "zypp/base/String.h"
-#include "zypp/ZYppFactory.h"
-
-#include "zypp/parser/susetags/PackagesDuFileReader.h"
-#include "zypp/parser/susetags/FileReaderBaseImpl.h"
-
-using std::endl;
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::susetags"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PackagesDuFileReader::Impl
- //
- /** PackagesDuFileReader implementation. */
- class PackagesDuFileReader::Impl : public BaseImpl
- {
- public:
- Impl( const PackagesDuFileReader & parent_r )
- : BaseImpl( parent_r )
- {
- _mounts = getZYpp()->getPartitions();
-
- for ( DiskUsageCounter::MountPointSet::const_iterator it = _mounts.begin();
- it != _mounts.end();
- ++ it )
- {
- MIL << "Partition " << *it << endl;
- }
-
- }
-
- virtual ~Impl()
- {}
-
- bool hasPackage() const
- { return _pkgData; }
-
- bool hasSourcepackage() const
- { return _srcpkgData; }
-
- data::Package_Ptr handoutPackage()
- {
- data::Package_Ptr ret;
- ret.swap( _pkgData );
- _srcpkgData = 0;
- _data = 0;
- return ret;
- }
-
- data::SrcPackage_Ptr handoutSourcepackage()
- {
- data::SrcPackage_Ptr ret;
- ret.swap( _srcpkgData );
- _pkgData = 0;
- _data = 0;
- return ret;
- }
-
- public: // single tags
- /** Consume =Ver:. */
- void consumeVer( const SingleTagPtr & tag_r )
- { /* NOP */; }
-
- /** Consume =Pkg:. */
- void consumePkg( const SingleTagPtr & tag_r )
- {
- std::vector<std::string> words;
- if ( str::split( tag_r->value, std::back_inserter(words) ) != 4 )
- {
- ZYPP_THROW( error( tag_r, "Expected [name version release arch]") );
- }
-
- if ( words[3] == "src" || words[3] == "nosrc")
- {
- ++_c_srcpkg;
- _data = _srcpkgData = new data::SrcPackage;
- _pkgData = 0;
- // _data->arch is arch_noarch per default
- }
- else
- {
- ++_c_pkg;
- _data = _pkgData = new data::Package;
- _srcpkgData = 0;
- _data->arch = Arch( words[3] );
- }
- _data->name = words[0];
- _data->edition = Edition( words[1], words[2] );
- }
-
-
- public: // multi tags
- /** Consume +Dir:. */
- void consumeDir( const MultiTagPtr & tag_r )
- {
- static str::regex sizeEntryRX( "^(.*/)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]*$" );
- static str::smatch what;
-
- _data->diskusage;
-
- for_( it, tag_r->value.begin(), tag_r->value.end() )
- {
- if ( str::regex_match( *it, what, sizeEntryRX ) )
- {
- bool skip = true;
- DiskUsage::Entry entry( what[1],
- str::strtonum<unsigned>(what[2]) + str::strtonum<unsigned>(what[3]),
- str::strtonum<unsigned>(what[4]) + str::strtonum<unsigned>(what[5]) );
-
- // the partitioning is not known or we are running in instsys (see #308659)
- if ( _mounts.empty() || (getenv("YAST_IS_RUNNING") && (std::string(getenv("YAST_IS_RUNNING")) == "instsys" )))
- {
- // if no mount information, cut off deeper directory
- // levels in DiskUsage::Entry to reduce data size.
- unsigned level = 3; // number of '/' incl. a trailing one
- std::string::size_type pos = 0; // we store absolute pathnames
- while ( --level && pos != std::string::npos )
- {
- pos = entry.path.find( "/", pos+1 );
- }
- if ( pos != std::string::npos )
- {
- // found 'level' number of '/'es.
- skip = ( entry.path[pos+1] != '\0' );
- }
- else
- {
- // less than 'level' number of '/'es.
- skip = false;
- }
- }
- else
- {
- // Store entries, if they are equal to or parent of a mountpoint.
- for ( DiskUsageCounter::MountPointSet::reverse_iterator mit = _mounts.rbegin();
- mit != _mounts.rend();
- ++ mit )
- {
- // Entry.path has leading and trailing '/' (asserted by DiskUsage::Entry).
- // So we append a '/' to the mountpoint and test for prefix_r.
- if ( str::hasPrefix( (mit->dir+"/"), entry.path ) )
- {
- skip = false;
- break;
- }
- }
- }
- // try next entry
- if ( skip )
- continue;
-
- _data->diskusage.add(entry);
- }
- else
- {
- ZYPP_THROW( error( tag_r, "Expected du-entry [path num num num num]") );
- }
- }
- }
-
- public:
- DefaultIntegral<unsigned,0> _c_pkg;
- DefaultIntegral<unsigned,0> _c_srcpkg;
-
- private:
- data::Packagebase_Ptr _data;
- data::Package_Ptr _pkgData;
- data::SrcPackage_Ptr _srcpkgData;
- DiskUsageCounter::MountPointSet _mounts;
- };
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PackagesDuFileReader
- //
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesDuFileReader::PackagesDuFileReader
- // METHOD TYPE : Ctor
- //
- PackagesDuFileReader::PackagesDuFileReader()
- {}
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesDuFileReader::~PackagesDuFileReader
- // METHOD TYPE : Dtor
- //
- PackagesDuFileReader::~PackagesDuFileReader()
- {}
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesDuFileReader::beginParse
- // METHOD TYPE : void
- //
- void PackagesDuFileReader::beginParse()
- {
- _pimpl.reset( new Impl(*this) );
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesDuFileReader::consume
- // METHOD TYPE : void
- //
- void PackagesDuFileReader::consume( const SingleTagPtr & tag_r )
- {
-#define TAGN(V) tag_r->name == #V
-#define TAGFWD(V) ( TAGN(V) ) _pimpl->consume##V( tag_r )
-
- if ( TAGN( Pkg ) )
- {
- // consume old data
- if ( _pimpl->hasPackage() )
- {
- if ( _pkgConsumer )
- _pkgConsumer( _pimpl->handoutPackage() );
- }
- else if ( _pimpl->hasSourcepackage() )
- {
- if ( _srcPkgConsumer )
- _srcPkgConsumer( _pimpl->handoutSourcepackage() );
- }
- // start new data
- _pimpl->consumePkg( tag_r );
- }
- else if TAGFWD( Ver );
- else
- { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesDuFileReader::consume
- // METHOD TYPE : void
- //
- void PackagesDuFileReader::consume( const MultiTagPtr & tag_r )
- {
- if TAGFWD( Dir );
- else
- { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesDuFileReader::lastData
- // METHOD TYPE : void
- //
- void PackagesDuFileReader::endParse()
- {
- // consume oldData
- if ( _pimpl->hasPackage() )
- {
- if ( _pkgConsumer )
- _pkgConsumer( _pimpl->handoutPackage() );
- }
- else if ( _pimpl->hasSourcepackage() )
- {
- if ( _srcPkgConsumer )
- _srcPkgConsumer( _pimpl->handoutSourcepackage() );
- }
- MIL << "[PackagesDu]" << "(" << _pimpl->_c_pkg << "|" << _pimpl->_c_srcpkg << ")" << endl;
- _pimpl.reset();
- }
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/PackagesDuFileReader.h
- *
-*/
-#ifndef ZYPP_PARSER_SUSETAGS_PACKAGESDUFILEREADER_H
-#define ZYPP_PARSER_SUSETAGS_PACKAGESDUFILEREADER_H
-
-#include <iosfwd>
-
-#include "zypp/parser/susetags/FileReaderBase.h"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- namespace data
- { /////////////////////////////////////////////////////////////////
- class Package;
- DEFINE_PTR_TYPE(Package);
- class SrcPackage;
- DEFINE_PTR_TYPE(SrcPackage);
- /////////////////////////////////////////////////////////////////
- } // namespace data
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PackagesDuFileReader
- //
- /** */
- class PackagesDuFileReader : public FileReaderBase
- {
- public:
- typedef function<void(const data::Package_Ptr &)> PkgConsumer;
- typedef function<void(const data::SrcPackage_Ptr &)> SrcPkgConsumer;
-
- public:
- /** Default ctor */
- PackagesDuFileReader();
- /** Dtor */
- virtual ~PackagesDuFileReader();
-
- public:
- /** Consumer to call when a (binary) package entry was parsed. */
- void setPkgConsumer( const PkgConsumer & fnc_r )
- { _pkgConsumer = fnc_r; }
-
- /** Consumer to call when a (source) package entry was parsed. */
- void setSrcPkgConsumer( const SrcPkgConsumer & fnc_r )
- { _srcPkgConsumer = fnc_r; }
-
- private:
- /** Called when start parsing. */
- virtual void beginParse();
- /** Called when a single-tag is found. */
- virtual void consume( const SingleTagPtr & tag_r );
- /** Called when a multi-tag is found. */
- virtual void consume( const MultiTagPtr & tag_r );
- /** Called when the parse is done. */
- virtual void endParse();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- PkgConsumer _pkgConsumer;
- SrcPkgConsumer _srcPkgConsumer;
- };
- ///////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_PARSER_SUSETAGS_PACKAGESDUFILEREADER_H
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/PackagesFileReader.cc
- *
-*/
-#include <iostream>
-#include "zypp/base/Logger.h"
-#include "zypp/ZConfig.h"
-
-#include "zypp/parser/susetags/PackagesFileReader.h"
-#include "zypp/parser/susetags/FileReaderBaseImpl.h"
-
-using std::endl;
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::susetags"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PackagesFileReader::Impl
- //
- /** PackagesFileReader implementation. */
- class PackagesFileReader::Impl : public BaseImpl
- {
- public:
- Impl( const PackagesFileReader & parent_r )
- : BaseImpl( parent_r )
- , _sysarch( ZConfig::instance().systemArchitecture() )
- {}
-
- virtual ~Impl()
- {}
-
- bool hasPackage() const
- { return _pkgData; }
-
- bool hasSourcepackage() const
- { return _srcpkgData; }
-
- data::Package_Ptr handoutPackage()
- {
- data::Package_Ptr ret;
- ret.swap( _pkgData );
- _srcpkgData = 0;
- _data = 0;
- // Filter unwanted stuff
- if ( ret
- && ! Arch(ret->arch).compatibleWith( _sysarch ) )
- {
- return 0;
- }
- return ret;
- }
-
- data::SrcPackage_Ptr handoutSourcepackage()
- {
- data::SrcPackage_Ptr ret;
- ret.swap( _srcpkgData );
- _pkgData = 0;
- _data = 0;
- return ret;
- }
-
- public: // single tags
- /** Consume =Ver:. */
- void consumeVer( const SingleTagPtr & tag_r )
- { /* NOP */; }
-
- /** Consume =Pkg:. */
- void consumePkg( const SingleTagPtr & tag_r )
- {
- std::vector<std::string> words;
- if ( str::split( tag_r->value, std::back_inserter(words) ) != 4 )
- {
- ZYPP_THROW( error( tag_r, "Expected [name version release arch]") );
- }
-
- if ( words[3] == "src" || words[3] == "nosrc")
- {
- ++_c_srcpkg;
- _data = _srcpkgData = new data::SrcPackage;
- _pkgData = 0;
- // _data->arch is arch_noarch per default
- }
- else
- {
- ++_c_pkg;
- _data = _pkgData = new data::Package;
- _srcpkgData = 0;
- _data->arch = Arch( words[3] );
- }
- _data->name = words[0];
- _data->edition = Edition( words[1], words[2] );
- }
-
- /** Consume =Cks:. */
- void consumeCks( const SingleTagPtr & tag_r )
- {
- std::vector<std::string> words;
- if ( str::split( tag_r->value, std::back_inserter(words) ) != 2 )
- {
- ZYPP_THROW( error( tag_r, "Expected [type checksum]") );
- }
- _data->repositoryLocation.setChecksum(CheckSum( words[0], words[1] ));
- }
-
- /** Consume =Grp:. */
- void consumeGrp( const SingleTagPtr & tag_r )
- {
- _data->group = tag_r->value;
- }
-
- /** Consume =Vnd:. */
- void consumeVnd( const SingleTagPtr & tag_r )
- {
- _data->vendor = tag_r->value;
- }
-
- /** Consume =Lic:. */
- void consumeLic( const SingleTagPtr & tag_r )
- {
- _data->license = tag_r->value;
- }
-
- /** Consume =Src:. */
- void consumeSrc( const SingleTagPtr & tag_r )
- {
- if ( ! _pkgData )
- {
- ZYPP_THROW( error( tag_r, "Unexpected sourcepackage definition for sourcepackage") );
- }
-
- std::vector<std::string> words;
- if ( str::split( tag_r->value, std::back_inserter(words) ) != 4 )
- {
- ZYPP_THROW( error( tag_r, "Expected sourcepackages [name version release arch]") );
- }
-
- _pkgData->srcPackageIdent = NVR( words[0], Edition( words[1],words[2] ) );
- }
-
- /** Consume =Tim:. */
- void consumeTim( const SingleTagPtr & tag_r )
- {
- _data->buildTime = str::strtonum<Date::ValueType>( tag_r->value );
- }
-
- /** Consume =Loc:. */
- void consumeLoc( const SingleTagPtr & tag_r )
- {
- std::vector<std::string> words;
- switch ( str::split( tag_r->value, std::back_inserter(words) ) )
- {
- case 2: // [medianr filename]
- _data->repositoryLocation.setLocation( Pathname(_data->arch.asString()) / words[1],
- str::strtonum<unsigned>(words[0]) );
- break;
-
- case 3: // [medianr filename dir]
- _data->repositoryLocation.setLocation( Pathname(words[2]) / words[1],
- str::strtonum<unsigned>(words[0]) );
- break;
-
- default:
- ZYPP_THROW( error( tag_r, "Expected [medianr filename dir]") );
- break;
- }
- }
-
- /** Consume =Siz:. */
- void consumeSiz( const SingleTagPtr & tag_r )
- {
- std::vector<std::string> words;
- if ( str::split( tag_r->value, std::back_inserter(words) ) != 2 )
- {
- ZYPP_THROW( error( tag_r, "Expected [archivesize size]") );
- }
- _data->repositoryLocation.setDownloadSize(str::strtonum<ByteCount::SizeType>( words[0] ));
- _data->installedSize = str::strtonum<ByteCount::SizeType>( words[1] );
- }
-
- /** Consume =Shr:.
- * Raw data to identify the object is the string
- * <tt>kind:name-version-realease.arch</tt>.
- */
- void consumeShr( const SingleTagPtr & tag_r )
- {
- std::vector<std::string> words;
- if ( str::split( tag_r->value, std::back_inserter(words) ) != 4 )
- {
- ZYPP_THROW( error( tag_r, "Expected [name version release arch]") );
- }
-
- if ( words[3] == "src" || words[3] == "nosrc")
- {
- _data->sharedDataTag = makeSharedIdent( ResTraits<SrcPackage>::kind,
- words[0],
- Edition( words[1], words[2] ),
- Arch_noarch );
- }
- else
- {
- _data->sharedDataTag = makeSharedIdent( ResTraits<Package>::kind,
- words[0],
- Edition( words[1], words[2] ),
- Arch( words[3] ) );
- }
- }
-
- public: // multi tags
- /** Consume +Req:. */
- void consumeReq( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::REQUIRES] );
- }
-
- /** Consume +Prq:. */
- void consumePrq( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::PREREQUIRES] );
- }
-
- /** Consume +Prv:. */
- void consumePrv( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::PROVIDES] );
- }
-
- /** Consume +Con:. */
- void consumeCon( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::CONFLICTS] );
- }
-
- /** Consume +Obs:. */
- void consumeObs( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::OBSOLETES] );
- }
-
- /** Consume +Rec:. */
- void consumeRec( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::RECOMMENDS] );
- }
-
- /** Consume +Fre:. */
- void consumeFre( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::FRESHENS] );
- }
-
- /** Consume +Enh:. */
- void consumeEnh( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::ENHANCES] );
- }
-
- /** Consume +Sug:. */
- void consumeSug( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::SUGGESTS] );
- }
-
- /** Consume +Sup:. */
- void consumeSup( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::SUPPLEMENTS] );
- }
-
- /** Consume +Kwd:. */
- void consumeKwd( const MultiTagPtr & tag_r )
- {
- std::copy( tag_r->value.begin(),
- tag_r->value.end(),
- std::inserter(_data->keywords, _data->keywords.begin()) );
- }
-
- /** Consume +Aut:. */
- void consumeAut( const MultiTagPtr & tag_r )
- {
- _data->authors.swap( tag_r->value );
- }
-
- public:
- DefaultIntegral<unsigned,0> _c_pkg;
- DefaultIntegral<unsigned,0> _c_srcpkg;
-
- private:
- data::Packagebase_Ptr _data;
- data::Package_Ptr _pkgData;
- data::SrcPackage_Ptr _srcpkgData;
- Arch _sysarch;
- };
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PackagesFileReader
- //
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesFileReader::PackagesFileReader
- // METHOD TYPE : Ctor
- //
- PackagesFileReader::PackagesFileReader()
- {}
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesFileReader::~PackagesFileReader
- // METHOD TYPE : Dtor
- //
- PackagesFileReader::~PackagesFileReader()
- {}
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesFileReader::beginParse
- // METHOD TYPE : void
- //
- void PackagesFileReader::beginParse()
- {
- _pimpl.reset( new Impl(*this) );
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesFileReader::consume
- // METHOD TYPE : void
- //
- void PackagesFileReader::consume( const SingleTagPtr & tag_r )
- {
-#define TAGN(V) tag_r->name == #V
-#define TAGFWD(V) ( TAGN(V) ) _pimpl->consume##V( tag_r )
-
- if ( TAGN( Pkg ) )
- {
- // consume old data
- if ( _pimpl->hasPackage() )
- {
- if ( _pkgConsumer )
- {
- data::Package_Ptr ptr = _pimpl->handoutPackage();
- if ( ptr )
- _pkgConsumer( ptr );
- }
- }
- else if ( _pimpl->hasSourcepackage() )
- {
- if ( _srcPkgConsumer )
- _srcPkgConsumer( _pimpl->handoutSourcepackage() );
- }
- // start new data
- _pimpl->consumePkg( tag_r );
- }
- else if TAGFWD( Cks );
- else if TAGFWD( Grp );
- else if TAGFWD( Vnd );
- else if TAGFWD( Lic );
- else if TAGFWD( Src );
- else if TAGFWD( Tim );
- else if TAGFWD( Loc );
- else if TAGFWD( Siz );
- else if TAGFWD( Shr );
- else if TAGFWD( Ver );
- else
- { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesFileReader::consume
- // METHOD TYPE : void
- //
- void PackagesFileReader::consume( const MultiTagPtr & tag_r )
- {
- if TAGFWD( Req );
- else if TAGFWD( Prq );
- else if TAGFWD( Prv );
- else if TAGFWD( Con );
- else if TAGFWD( Obs );
- else if TAGFWD( Rec );
- else if TAGFWD( Fre );
- else if TAGFWD( Enh );
- else if TAGFWD( Sug );
- else if TAGFWD( Sup );
- else if TAGFWD( Kwd );
- else if TAGFWD( Aut );
- else
- { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesFileReader::lastData
- // METHOD TYPE : void
- //
- void PackagesFileReader::endParse()
- {
- // consume oldData
- if ( _pimpl->hasPackage() )
- {
- if ( _pkgConsumer )
- {
- data::Package_Ptr ptr = _pimpl->handoutPackage();
- if ( ptr )
- _pkgConsumer( ptr );
- }
- }
- else if ( _pimpl->hasSourcepackage() )
- {
- if ( _srcPkgConsumer )
- _srcPkgConsumer( _pimpl->handoutSourcepackage() );
- }
- MIL << "[Packages]" << "(" << _pimpl->_c_pkg << "|" << _pimpl->_c_srcpkg << ")" << endl;
- _pimpl.reset();
- }
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/PackagesFileReader.h
- *
-*/
-#ifndef ZYPP_PARSER_SUSETAGS_PACKAGESFILEREADER_H
-#define ZYPP_PARSER_SUSETAGS_PACKAGESFILEREADER_H
-
-#include <iosfwd>
-
-#include "zypp/parser/susetags/FileReaderBase.h"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- namespace data
- { /////////////////////////////////////////////////////////////////
- class Package;
- DEFINE_PTR_TYPE(Package);
- class SrcPackage;
- DEFINE_PTR_TYPE(SrcPackage);
- /////////////////////////////////////////////////////////////////
- } // namespace data
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PackagesFileReader
- //
- /** */
- class PackagesFileReader : public FileReaderBase
- {
- public:
- typedef function<void(const data::Package_Ptr &)> PkgConsumer;
- typedef function<void(const data::SrcPackage_Ptr &)> SrcPkgConsumer;
-
- public:
- /** Default ctor */
- PackagesFileReader();
- /** Dtor */
- virtual ~PackagesFileReader();
-
- public:
- /** Consumer to call when a (binary) package entry was parsed. */
- void setPkgConsumer( const PkgConsumer & fnc_r )
- { _pkgConsumer = fnc_r; }
-
- /** Consumer to call when a (source) package entry was parsed. */
- void setSrcPkgConsumer( const SrcPkgConsumer & fnc_r )
- { _srcPkgConsumer = fnc_r; }
-
- private:
- /** Called when start parsing. */
- virtual void beginParse();
- /** Called when a single-tag is found. */
- virtual void consume( const SingleTagPtr & tag_r );
- /** Called when a multi-tag is found. */
- virtual void consume( const MultiTagPtr & tag_r );
- /** Called when the parse is done. */
- virtual void endParse();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- PkgConsumer _pkgConsumer;
- SrcPkgConsumer _srcPkgConsumer;
- };
- ///////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_PARSER_SUSETAGS_PACKAGESFILEREADER_H
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/PackagesLangFileReader.cc
- *
-*/
-#include <iostream>
-#include "zypp/base/Easy.h"
-#include "zypp/base/Logger.h"
-#include "zypp/base/LogTools.h"
-#include "zypp/parser/susetags/PackagesLangFileReader.h"
-#include "zypp/parser/susetags/FileReaderBaseImpl.h"
-
-using std::endl;
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::susetags"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PackagesLangFileReader::Impl
- //
- /** PackagesLangFileReader implementation. */
- class PackagesLangFileReader::Impl : public BaseImpl
- {
- public:
- Impl( const PackagesLangFileReader & parent_r,
- const Locale & locale_r )
- : BaseImpl( parent_r ), _locale( locale_r )
- {}
-
- virtual ~Impl()
- {}
-
- bool hasPackage() const
- { return _pkgData; }
-
- bool hasSourcepackage() const
- { return _srcpkgData; }
-
- data::Package_Ptr handoutPackage()
- {
- data::Package_Ptr ret;
- ret.swap( _pkgData );
- _srcpkgData = 0;
- _data = 0;
- return ret;
- }
-
- data::SrcPackage_Ptr handoutSourcepackage()
- {
- data::SrcPackage_Ptr ret;
- ret.swap( _srcpkgData );
- _pkgData = 0;
- _data = 0;
- return ret;
- }
-
- public: // single tags
- /** Consume =Ver:. */
- void consumeVer( const SingleTagPtr & tag_r )
- { /*NOP*/ }
-
- /** Consume =:Pkg. */
- void consumePkg( const SingleTagPtr & tag_r )
- {
- std::vector<std::string> words;
- if ( str::split( tag_r->value, std::back_inserter(words) ) != 4 )
- {
- ZYPP_THROW( error( tag_r, "Expected [name version release arch]") );
- }
-
- if ( words[3] == "src" || words[3] == "nosrc")
- {
- ++_c_srcpkg;
- _data = _srcpkgData = new data::SrcPackage;
- _pkgData = 0;
- // _data->arch is arch_noarch per default
- }
- else
- {
- ++_c_pkg;
- _data = _pkgData = new data::Package;
- _srcpkgData = 0;
- _data->arch = Arch( words[3] );
- }
- _data->name = words[0];
- _data->edition = Edition( words[1], words[2] );
- }
-
- /** Consume =Sum:. */
- void consumeSum( const SingleTagPtr & tag_r )
- {
- _data->summary.setText( tag_r->value, _locale );
- }
-
- public: // multi tags
- /** Consume +Des:. */
- void consumeDes( const MultiTagPtr & tag_r )
- {
- _data->description.setText( tag_r->value, _locale );
- }
-
- /** Consume +Eul:. */
- void consumeEul( const MultiTagPtr & tag_r )
- {
- _data->licenseToConfirm.setText( tag_r->value, _locale );
- }
-
- /** Consume +Ins:. */
- void consumeIns( const MultiTagPtr & tag_r )
- {
- _data->insnotify.setText( tag_r->value, _locale );
- }
-
- /** Consume +Del:. */
- void consumeDel( const MultiTagPtr & tag_r )
- {
- _data->delnotify.setText( tag_r->value, _locale );
- }
-
- public:
- DefaultIntegral<unsigned,0> _c_pkg;
- DefaultIntegral<unsigned,0> _c_srcpkg;
-
- private:
- Locale _locale;
- data::Packagebase_Ptr _data;
- data::Package_Ptr _pkgData;
- data::SrcPackage_Ptr _srcpkgData;
- };
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PackagesLangFileReader
- //
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesLangFileReader::PackagesLangFileReader
- // METHOD TYPE : Ctor
- //
- PackagesLangFileReader::PackagesLangFileReader()
- {}
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesLangFileReader::~PackagesLangFileReader
- // METHOD TYPE : Dtor
- //
- PackagesLangFileReader::~PackagesLangFileReader()
- {}
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesLangFileReader::beginParse
- // METHOD TYPE : void
- //
- void PackagesLangFileReader::beginParse()
- {
- _pimpl.reset( new Impl( *this, _locale ) );
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesLangFileReader::consume
- // METHOD TYPE : void
- //
- void PackagesLangFileReader::consume( const SingleTagPtr & tag_r )
- {
-#define TAGN(V) tag_r->name == #V
-#define TAGFWD(V) ( TAGN(V) ) _pimpl->consume##V( tag_r )
-
- if ( TAGN( Pkg ) )
- {
- // consume old data
- if ( _pimpl->hasPackage() )
- {
- if ( _pkgConsumer )
- _pkgConsumer( _pimpl->handoutPackage() );
- }
- else if ( _pimpl->hasSourcepackage() )
- {
- if ( _srcPkgConsumer )
- _srcPkgConsumer( _pimpl->handoutSourcepackage() );
- }
- // start new data
- _pimpl->consumePkg( tag_r );
- }
- else if TAGFWD( Sum );
- else if TAGFWD( Ver );
- else
- { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesLangFileReader::consume
- // METHOD TYPE : void
- //
- void PackagesLangFileReader::consume( const MultiTagPtr & tag_r )
- {
- if TAGFWD( Des );
- else if TAGFWD( Eul );
- else if TAGFWD( Ins );
- else if TAGFWD( Del );
- else
- { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PackagesLangFileReader::lastData
- // METHOD TYPE : void
- //
- void PackagesLangFileReader::endParse()
- {
- // consume oldData
- if ( _pimpl->hasPackage() )
- {
- if ( _pkgConsumer )
- _pkgConsumer( _pimpl->handoutPackage() );
- }
- else if ( _pimpl->hasSourcepackage() )
- {
- if ( _srcPkgConsumer )
- _srcPkgConsumer( _pimpl->handoutSourcepackage() );
- }
- MIL << "[PackagesLang]" << "(" << _pimpl->_c_pkg << "|" << _pimpl->_c_srcpkg << ")" << endl;
- _pimpl.reset();
- }
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/PackagesLangFileReader.h
- *
-*/
-#ifndef ZYPP_PARSER_SUSETAGS_PACKAGESLANGFILEREADER_H
-#define ZYPP_PARSER_SUSETAGS_PACKAGESLANGFILEREADER_H
-
-#include <iosfwd>
-
-#include "zypp/parser/susetags/FileReaderBase.h"
-#include "zypp/Locale.h"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- namespace data
- { /////////////////////////////////////////////////////////////////
- class Package;
- DEFINE_PTR_TYPE(Package);
- class SrcPackage;
- DEFINE_PTR_TYPE(SrcPackage);
- /////////////////////////////////////////////////////////////////
- } // namespace data
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PackagesLangFileReader
- //
- /** */
- class PackagesLangFileReader : public FileReaderBase
- {
- public:
- typedef function<void(const data::Package_Ptr &)> PkgConsumer;
- typedef function<void(const data::SrcPackage_Ptr &)> SrcPkgConsumer;
-
- public:
- /** Default ctor */
- PackagesLangFileReader();
- /** Dtor */
- virtual ~PackagesLangFileReader();
-
- public:
- /** Locale to parse. */
- void setLocale( const Locale & locale_r )
- { _locale = locale_r; }
-
- /** Consumer to call when a (binary) package entry was parsed. */
- void setPkgConsumer( const PkgConsumer & fnc_r )
- { _pkgConsumer = fnc_r; }
-
- /** Consumer to call when a (source) package entry was parsed. */
- void setSrcPkgConsumer( const SrcPkgConsumer & fnc_r )
- { _srcPkgConsumer = fnc_r; }
-
- private:
- /** Called when start parsing. */
- virtual void beginParse();
- /** Called when a single-tag is found. */
- virtual void consume( const SingleTagPtr & tag_r );
- /** Called when a multi-tag is found. */
- virtual void consume( const MultiTagPtr & tag_r );
- /** Called when the parse is done. */
- virtual void endParse();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- Locale _locale;
- PkgConsumer _pkgConsumer;
- SrcPkgConsumer _srcPkgConsumer;
- };
- ///////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_PARSER_SUSETAGS_PACKAGESLANGFILEREADER_H
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/PatternFileReader.cc
- *
-*/
-#include <iostream>
-#include "zypp/base/Logger.h"
-
-#include "zypp/parser/susetags/PatternFileReader.h"
-#include "zypp/parser/susetags/FileReaderBaseImpl.h"
-
-using std::endl;
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::susetags"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PatternFileReader::Impl
- //
- /** PatternFileReader implementation. */
- class PatternFileReader::Impl : public BaseImpl
- {
- public:
- Impl( const PatternFileReader & parent_r )
- : BaseImpl( parent_r )
- {}
-
- virtual ~Impl()
- {}
-
- bool hasData() const
- { return _data; }
-
- data::Pattern_Ptr handoutData()
- {
- data::Pattern_Ptr ret;
- ret.swap( _data );
- return ret;
- }
-
- public: // single tags
- /** Consume =Ver:. */
- void consumeVer( const SingleTagPtr & tag_r )
- { /* NOP */; }
-
- /** Consume =Pat:. */
- void consumePat( const SingleTagPtr & tag_r )
- {
- std::vector<std::string> words;
- if ( str::split( tag_r->value, std::back_inserter(words) ) != 4 )
- {
- ZYPP_THROW( error( tag_r, "Expected [name version release arch]") );
- }
-
- _data = new data::Pattern;
- _data->name = words[0];
- _data->edition = Edition( words[1], words[2] );
- _data->arch = Arch( words[3] );
- }
-
- /** Consume =Sum:. */
- void consumeSum( const SingleTagPtr & tag_r )
- {
- _data->summary.setText( tag_r->value, Locale(tag_r->modifier) );
- }
-
- /** Consume =Vis:. */
- void consumeVis( const SingleTagPtr & tag_r )
- {
- _data->userVisible = ( tag_r->value == "true" );
- }
-
- /** Consume =Cat:. */
- void consumeCat( const SingleTagPtr & tag_r )
- {
- _data->category.setText( tag_r->value, Locale(tag_r->modifier) );
- }
-
- /** Consume =Ico:. */
- void consumeIco( const SingleTagPtr & tag_r )
- {
- _data->icon = tag_r->value;
- }
-
- /** Consume =Ord:. */
- void consumeOrd( const SingleTagPtr & tag_r )
- {
- _data->order = tag_r->value;
- }
-
- public: // multi tags
- /** Consume +Req:. */
- void consumeReq( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->deps[Dep::REQUIRES] );
- }
-
- /** Consume +Prv:. */
- void consumePrv( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->deps[Dep::PROVIDES] );
- }
-
- /** Consume +Con:. */
- void consumeCon( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->deps[Dep::CONFLICTS] );
- }
-
- /** Consume +Obs:. */
- void consumeObs( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->deps[Dep::OBSOLETES] );
- }
-
- /** Consume +Rec:. */
- void consumeRec( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->deps[Dep::RECOMMENDS] );
- }
-
- /** Consume +Fre:. */
- void consumeFre( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->deps[Dep::FRESHENS] );
- }
-
- /** Consume +Enh:. */
- void consumeEnh( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->deps[Dep::ENHANCES] );
- }
-
- /** Consume +Sug:. */
- void consumeSug( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->deps[Dep::SUGGESTS] );
- }
-
- /** Consume +Sup:. */
- void consumeSup( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->deps[Dep::SUPPLEMENTS] );
- }
-
- // package related dependencies:
-
- /** Consume +Prq:. */
- void consumePrq( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::REQUIRES] );
- }
-
- /** Consume +Pcn:. */
- void consumePcn( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::CONFLICTS] );
- }
-
- /** Consume +Pob:. */
- void consumePob( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::OBSOLETES] );
- }
-
- /** Consume +Prc:. */
- void consumePrc( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::RECOMMENDS] );
- }
-
- /** Consume +Pfr:. */
- void consumePfr( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::FRESHENS] );
- }
-
- /** Consume +Pen:. */
- void consumePen( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::ENHANCES] );
- }
-
- /** Consume +Psg:. */
- void consumePsg( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::SUGGESTS] );
- }
-
- /** Consume +Psp:. */
- void consumePsp( const MultiTagPtr & tag_r )
- {
- depParse<Package>( tag_r, _data->deps[Dep::SUPPLEMENTS] );
- }
-
- // non dependency tags
-
- /** Consume +Des:. */
- void consumeDes( const MultiTagPtr & tag_r )
- {
- _data->description.setText( tag_r->value, Locale(tag_r->modifier) );
- }
-
- /** Consume +Inc:. */
- void consumeInc( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->includes );
- }
-
- /** Consume +Ext:. */
- void consumeExt( const MultiTagPtr & tag_r )
- {
- depParse<Pattern>( tag_r, _data->extends );
- }
-
- private:
- data::Pattern_Ptr _data;
- };
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PatternFileReader
- //
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PatternFileReader::PatternFileReader
- // METHOD TYPE : Ctor
- //
- PatternFileReader::PatternFileReader()
- {}
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PatternFileReader::~PatternFileReader
- // METHOD TYPE : Dtor
- //
- PatternFileReader::~PatternFileReader()
- {}
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PatternFileReader::beginParse
- // METHOD TYPE : void
- //
- void PatternFileReader::beginParse()
- {
- _pimpl.reset( new Impl(*this) );
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PatternFileReader::consume
- // METHOD TYPE : void
- //
- void PatternFileReader::consume( const SingleTagPtr & tag_r )
- {
-#define TAGN(V) tag_r->name == #V
-#define TAGFWD(V) ( TAGN(V) ) _pimpl->consume##V( tag_r )
-
- if ( TAGN( Pat ) )
- {
- // consume old data
- if ( _pimpl->hasData() )
- {
- if ( _consumer )
- _consumer( _pimpl->handoutData() );
- }
- // start new data
- _pimpl->consumePat( tag_r );
- }
- else
- {
- if ( _pimpl->hasData() )
- {
- if TAGFWD( Sum );
- else if TAGFWD( Vis );
- else if TAGFWD( Cat );
- else if TAGFWD( Ico );
- else if TAGFWD( Ord );
- else
- { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
- }
- else
- {
- if TAGFWD( Ver );
- else
- { WAR << errPrefix( tag_r, "Unknown header tag" ) << endl; }
- }
- }
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PatternFileReader::consume
- // METHOD TYPE : void
- //
- void PatternFileReader::consume( const MultiTagPtr & tag_r )
- {
- if ( _pimpl->hasData() )
- {
- if TAGFWD( Req );
- else if TAGFWD( Prv );
- else if TAGFWD( Con );
- else if TAGFWD( Obs );
- else if TAGFWD( Rec );
- else if TAGFWD( Fre );
- else if TAGFWD( Enh );
- else if TAGFWD( Sug );
- else if TAGFWD( Sup );
- // package related dependencies
- else if TAGFWD( Prq ); // requires
- else if TAGFWD( Pcn ); // conflicts
- else if TAGFWD( Pob ); // obsoletes
- else if TAGFWD( Prc ); // recommends
- else if TAGFWD( Pfr ); // freshens
- else if TAGFWD( Pen ); // enhances
- else if TAGFWD( Psg ); // suggests
- else if TAGFWD( Psp ); // supplements
- //
- else if TAGFWD( Des );
- else if TAGFWD( Inc ); // UI hint: includes
- else if TAGFWD( Ext ); // UI hint: extends
- else
- { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
- }
- else
- { WAR << errPrefix( tag_r, "Unknown header tag" ) << endl; }
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : PatternFileReader::lastData
- // METHOD TYPE : void
- //
- void PatternFileReader::endParse()
- {
- // consume data
- if ( _pimpl->hasData() )
- {
- if ( _consumer )
- _consumer( _pimpl->handoutData() );
- }
- _pimpl.reset();
- }
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/PatternFileReader.h
- *
-*/
-#ifndef ZYPP_PARSER_SUSETAGS_PATTERNFILEREADER_H
-#define ZYPP_PARSER_SUSETAGS_PATTERNFILEREADER_H
-
-#include <iosfwd>
-
-#include "zypp/parser/susetags/FileReaderBase.h"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- namespace data
- { /////////////////////////////////////////////////////////////////
- class Pattern;
- DEFINE_PTR_TYPE(Pattern);
- /////////////////////////////////////////////////////////////////
- } // namespace data
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PatternFileReader
- //
- /** */
- class PatternFileReader : public FileReaderBase
- {
- public:
- typedef function<void(const data::Pattern_Ptr &)> Consumer;
-
- public:
- /** Default ctor */
- PatternFileReader();
- /** Dtor */
- virtual ~PatternFileReader();
-
- public:
- /** Consumer to call when a pattern was parsed. */
- void setConsumer( const Consumer & fnc_r )
- { _consumer = fnc_r; }
-
- private:
- /** Called when start parsing. */
- virtual void beginParse();
- /** Called when a single-tag is found. */
- virtual void consume( const SingleTagPtr & tag_r );
- /** Called when a multi-tag is found. */
- virtual void consume( const MultiTagPtr & tag_r );
- /** Called when the parse is done. */
- virtual void endParse();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
-
- Consumer _consumer;
- };
- ///////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_PARSER_SUSETAGS_PATTERNFILEREADER_H
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/susetags/RepoParser.cc
- *
-*/
-#include <iostream>
-#include "zypp/base/Easy.h"
-#include "zypp/base/Logger.h"
-#include "zypp/base/LogTools.h"
-#include "zypp/base/Iterator.h"
-#include "zypp/base/String.h"
-#include "zypp/base/Gettext.h"
-
-#include "zypp/parser/susetags/FileReaderBaseImpl.h"
-#include "zypp/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/PackagesDuFileReader.h"
-#include "zypp/parser/susetags/PatternFileReader.h"
-#include "zypp/parser/susetags/RepoIndex.h"
-#include "zypp/parser/ParseException.h"
-
-#include "zypp/ZConfig.h"
-
-using std::endl;
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::susetags"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace susetags
- { /////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : RepoParser::Impl
- //
- /** RepoParser implementation.
- * \todo Clean data on exeption.
- */
- class RepoParser::Impl
- {
- public:
- Impl( const std::string & repositoryId_r,
- data::ResolvableDataConsumer & consumer_r,
- const ProgressData::ReceiverFnc & fnc_r )
- : _repositoryId( repositoryId_r )
- , _consumer( consumer_r )
- {
- _ticks.sendTo( fnc_r );
- }
-
- /** Main entry to parser. */
- void parse( const Pathname & reporoot_r );
-
- /** \name FileReader callbacks delivering data. */
- //@{
- ///////////////////////////////////////////////////////////////////
- void consumeIndex( const RepoIndex_Ptr & data_r )
- {
- //SEC << "[Index]" << data_r << endl;
- _repoIndex = data_r;
- }
-
- ///////////////////////////////////////////////////////////////////
- void consumeProd( const data::Product_Ptr & data_r )
- {
- MIL << "[Product] " << data_r << endl;
- ++_stats.prod;
- _prodData = data_r;
- _defaultVendor = data_r->vendor;
- _consumer.consumeProduct( data_r );
- }
-
- ///////////////////////////////////////////////////////////////////
- void consumePkg( const data::Package_Ptr & data_r )
- {
- fixVendor( data_r );
- fixLocationPath( data_r );
- resolveSharedDataTag( data_r );
-
- ++_stats.pack;
- data::RecordId newid = _consumer.consumePackage( data_r );
-
- // remember for later reference
- idMapAdd( makeSharedIdent( ResTraits<Package>::kind,
- data_r->name,
- data_r->edition,
- data_r->arch ),
- newid );
- }
-
- ///////////////////////////////////////////////////////////////////
- void consumeSrcPkg( const data::SrcPackage_Ptr & data_r )
- {
- fixVendor( data_r );
- fixLocationPath( data_r );
- resolveSharedDataTag( data_r );
-
- ++_stats.srcp;
- data::RecordId newid = _consumer.consumeSourcePackage( data_r );
-
- // remember for later reference
- idMapAdd( makeSharedIdent( ResTraits<SrcPackage>::kind,
- data_r->name,
- data_r->edition,
- data_r->arch),
- newid );
- }
-
- ///////////////////////////////////////////////////////////////////
- void consumePkgLang( const data::Package_Ptr & data_r )
- {
- data::RecordId id = idMapGet( makeSharedIdent( ResTraits<Package>::kind,
- data_r->name,
- data_r->edition,
- data_r->arch ) );
- if ( id != data::noRecordId )
- {
- _consumer.updatePackageLang( id, data_r );
- }
- }
-
- ///////////////////////////////////////////////////////////////////
- void consumeSrcPkgLang( const data::SrcPackage_Ptr & data_r )
- {
- data::RecordId id = idMapGet( makeSharedIdent( ResTraits<SrcPackage>::kind,
- data_r->name,
- data_r->edition,
- data_r->arch ) );
- if ( id != data::noRecordId )
- {
- _consumer.updatePackageLang( id, data_r );
- }
- }
-
- ///////////////////////////////////////////////////////////////////
- void consumePkgDu( const data::Package_Ptr & data_r )
- {
- data::RecordId id = idMapGet( makeSharedIdent( ResTraits<Package>::kind,
- data_r->name,
- data_r->edition,
- data_r->arch ) );
- if ( id != data::noRecordId )
- {
- _consumer.consumeDiskUsage( id, data_r->diskusage );
- }
- }
-
- ///////////////////////////////////////////////////////////////////
- void consumeSrcPkgDu( const data::SrcPackage_Ptr & data_r )
- {
- data::RecordId id = idMapGet( makeSharedIdent( ResTraits<SrcPackage>::kind,
- data_r->name,
- data_r->edition,
- data_r->arch ) );
- if ( id != data::noRecordId )
- {
- _consumer.consumeDiskUsage( id, data_r->diskusage );
- }
- }
-
- ///////////////////////////////////////////////////////////////////
- void consumePat( const data::Pattern_Ptr & data_r )
- {
- //SEC << "[Pattern]" << data_r << endl;
- fixVendor( data_r );
- ++_stats.patt;
- _consumer.consumePattern( data_r );
- }
- //@}
-
- public:
- /** Use products vendor if vendor was not specified. */
- void fixVendor( const data::ResObject_Ptr & data_r )
- {
- if ( data_r->vendor.empty() && ! _defaultVendor.empty() )
- {
- data_r->vendor = _defaultVendor;
- }
- }
-
- /** Prepend location with 'datadir'. */
- void fixLocationPath( const data::Packagebase_Ptr & data_r )
- {
- Pathname tofix( data_r->repositoryLocation.filename() );
- data_r->repositoryLocation.changeFilename( _datadir / tofix );
- }
-
- /** Resolve shared data tag. */
- void resolveSharedDataTag( const data::Packagebase_Ptr & data_r )
- {
- if ( ! data_r->sharedDataTag.empty() )
- {
- data_r->shareDataWith = idMapGet( data_r->sharedDataTag );
- }
- }
-
- public:
- /** Throw \ref ParseException if a required file is not
- * available below \ref _reporoot on disk.
- */
- Pathname assertMandatoryFile( const Pathname & file_r, bool lookgz = true ) const
- {
- if ( lookgz )
- {
- PathInfo gzinputfile( _reporoot / (file_r.extend(".gz")) );
- if ( !gzinputfile.isFile() )
- {
- WAR << _reporoot << ": Skip gz required file (will look for non-gz): " << file_r.extend(".gz").asString() << endl;
- }
- else
- {
- return gzinputfile.path();
- }
- }
- PathInfo inputfile( _reporoot / file_r );
- if ( ! inputfile.isFile() )
- {
- ZYPP_THROW( ParseException( _reporoot.asString() + ": " + _("Required file is missing: ") + file_r.asString() ) );
- }
- return inputfile.path();
- }
-
- /** Print a warning if an optional file is not
- * available below \ref _reporoot on disk.
- */
- Pathname getOptionalFile( const Pathname & file_r, bool lookgz = true ) const
- {
- if ( lookgz )
- {
- PathInfo gzinputfile( _reporoot / (file_r.extend(".gz")) );
- if ( !gzinputfile.isFile() )
- {
- //WAR << _reporoot << ": Skip optional file: " << file_r.extend(".gz").asString() << endl;
- }
- else
- {
- return gzinputfile.path();
- }
- }
- PathInfo inputfile( _reporoot / file_r );
- if ( ! inputfile.isFile() )
- {
- //WAR << _reporoot << ": Skip optional file: " << file_r.asString() << endl;
- return Pathname();
- }
- return inputfile.path();
- }
-
- bool isPatternFile( const std::string & name_r ) const
- {
- return(
- (name_r.size() > 4 && name_r.substr( name_r.size() - 4 ) == ".pat" )
- || (name_r.size() > 7 && name_r.substr( name_r.size() - 7 ) == ".pat.gz" )
- );
- }
-
- /** Test for \c packages.lang in \ref _repoIndex.*/
- bool haveLocale( const Locale & locale_r ) const
- {
- std::string searchFor( "packages." + locale_r.code() );
- for ( RepoIndex::FileChecksumMap::const_iterator it = _repoIndex->metaFileChecksums.begin();
- it != _repoIndex->metaFileChecksums.end(); ++it )
- {
- if ( it->first == searchFor )
- {
- // got it
- PathInfo inputfile( _reporoot / _descrdir / searchFor );
- if ( ! inputfile.isFile() )
- {
- WAR << "Known and desired file is not on disk: " << inputfile << endl;
- }
- else
- return true; // got it
- }
-
- if ( it->first == (searchFor+".gz") )
- {
- // got it
- PathInfo inputfile( _reporoot / _descrdir / (searchFor+".gz") );
- if ( ! inputfile.isFile() )
- {
- WAR << "Known and desired file is not on disk: " << inputfile << endl;
- }
- else
- return true; // got it
- }
- }
- return false; // not found
- }
-
- /** Take care translations for \a locale_r or an appropriate
- * fallback were parsed.
- */
- void parseLocaleIf( const Locale & locale_r )
- {
- Locale toParse( locale_r );
- bool alreadyParsed = false;
-
- while ( toParse != Locale::noCode )
- {
- alreadyParsed = ( _parsedLocales.find( toParse ) != _parsedLocales.end() );
- if ( alreadyParsed || haveLocale( toParse ) )
- break; // no return because we want to log in case of a fallback
- toParse = toParse.fallback();
- }
-
- if ( toParse != locale_r )
- {
- WAR << "Using fallback locale " << toParse << " for " << locale_r << endl;
- }
-
- if ( alreadyParsed )
- {
- return; // now return...
- }
- // ...or parse
- _parsedLocales.insert( toParse ); // don't try again.
-
- Pathname inputfile( getOptionalFile( _descrdir / ("packages." + toParse.code()) ) );
- if ( ! inputfile.empty() )
- {
- PackagesLangFileReader reader;
- reader.setLocale( toParse );
- reader.setPkgConsumer( bind( &Impl::consumePkgLang, this, _1 ) );
- reader.setSrcPkgConsumer( bind( &Impl::consumeSrcPkgLang, this, _1 ) );
- CombinedProgressData progress( _ticks, PathInfo(inputfile).size() );
- reader.parse( inputfile, progress );
- }
-
- if ( ! _ticks.incr( PathInfo(inputfile).size() ) )
- ZYPP_THROW( AbortRequestException() );
- }
-
- private:
- void idMapAdd( const std::string & key_r, data::RecordId value_r )
- {
- if ( _idMap[key_r] != data::noRecordId )
- {
- WAR << "Multiple record ids for " << key_r
- << " (first " << _idMap[key_r] << ", now " << value_r << ")" << endl;
- }
- _idMap[key_r] = value_r;
- }
-
- data::RecordId idMapGet( const std::string & key_r )
- {
- data::RecordId ret = _idMap[key_r];
- if ( ret == data::noRecordId )
- {
- //WAR << "No record id for " << key_r << endl;
- }
- return ret;
- }
-
- private:
- std::string _repositoryId;
- data::ResolvableDataConsumer & _consumer;
- ProgressData _ticks;
-
- private: // these (and _ticks) are actually scoped per parse() run.
- RepoIndex_Ptr _repoIndex;
- data::Product_Ptr _prodData;
- std::string _defaultVendor;
- Pathname _reporoot; // full path
- Pathname _descrdir; // path below reporoot
- Pathname _datadir; // path below reporoot
-
- /** Translations processed by \ref parseLocaleIf so far.*/
- std::set<Locale> _parsedLocales;
-
- /** Remember the record ids of created packages and soucepackages. */
- std::map<std::string,data::RecordId> _idMap;
-
- struct Stats {
- DefaultIntegral<unsigned,0> prod;
- DefaultIntegral<unsigned,0> patt;
- DefaultIntegral<unsigned,0> pack;
- DefaultIntegral<unsigned,0> srcp;
- };
- Stats _stats;
- };
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : RepoParser::Impl::parse
- // METHOD TYPE : void
- //
- void RepoParser::Impl::parse( const Pathname & reporoot_r )
- {
- _prodData = 0;
- _repoIndex = 0;
- _defaultVendor.clear();
- _reporoot = reporoot_r;
- _descrdir = _datadir = Pathname();
- _parsedLocales.clear();
-
- // Content file first to get the repoindex
- {
- Pathname inputfile( assertMandatoryFile( "content" ) );
- ContentFileReader content;
- content.setProductConsumer( bind( &Impl::consumeProd, this, _1 ) );
- content.setRepoIndexConsumer( bind( &Impl::consumeIndex, this, _1 ) );
- content.parse( inputfile );
- }
- if ( ! _repoIndex )
- {
- ZYPP_THROW( ParseException( reporoot_r.asString() + ": " + "No repository index in content file." ) );
- }
- DBG << _repoIndex << endl;
-
- // Prepare parsing
- _descrdir = _repoIndex->descrdir; // path below reporoot
- _datadir = _repoIndex->datadir; // path below reporoot
-
- _ticks.name( "Parsing susetags repo at " + reporoot_r.asString() );
-
- // calculate progress range based on file sizes to parse
- int jobssize = 0;
- for ( RepoIndex::FileChecksumMap::const_iterator it = _repoIndex->metaFileChecksums.begin();
- it != _repoIndex->metaFileChecksums.end(); ++it )
- {
- // here the paths already contain the gz extension
- jobssize += PathInfo(getOptionalFile(_descrdir / it->first, false)).size();
-
- }
- MIL << "Total job size: " << jobssize << endl;
-
- _ticks.range(jobssize);
-
- if ( ! _ticks.toMin() )
- ZYPP_THROW( AbortRequestException() );
-
- // Start with packages
- {
- // Even the packages file is optional, see e.g. bug #309235
- Pathname inputfile( getOptionalFile( _descrdir / "packages" ) );
- if (!inputfile.empty())
- {
- PackagesFileReader reader;
- reader.setPkgConsumer( bind( &Impl::consumePkg, this, _1 ) );
- reader.setSrcPkgConsumer( bind( &Impl::consumeSrcPkg, this, _1 ) );
-
- CombinedProgressData progress( _ticks, PathInfo(inputfile).size() );
- reader.parse( inputfile, progress );
-
- // Now process packages.lang. Always parse 'en'.
- // At least packages.en is mandatory if packages exists, because the
- // file might contain license texts.
- assertMandatoryFile( _descrdir / "packages.en" );
- parseLocaleIf( Locale("en") );
- // For each wanted locale at least
- // some fallback, if locale is not present.
- parseLocaleIf( ZConfig::instance().textLocale() );
-
- // Now process packages.DU.
- //if ( 0 ) // remove the if to enable, but leave the {} around.
- {
- Pathname inputfile( getOptionalFile( _descrdir / "packages.DU" ) );
- if ( ! inputfile.empty() )
- {
- PackagesDuFileReader reader;
- reader.setPkgConsumer( bind( &Impl::consumePkgDu, this, _1 ) );
- reader.setSrcPkgConsumer( bind( &Impl::consumeSrcPkgDu, this, _1 ) );
-
- CombinedProgressData progress( _ticks, PathInfo(inputfile).size() );
- reader.parse( inputfile, progress );
- }
- }
- }
- }
-
- // Now process the rest of RepoIndex
- for ( RepoIndex::FileChecksumMap::const_iterator it = _repoIndex->metaFileChecksums.begin();
- it != _repoIndex->metaFileChecksums.end(); ++it )
- {
- Pathname inputfile;
- inputfile = "";
-
- if ( it->first == "patterns.pat"
- || it->first == "patterns.pat.gz" )
- {
- // read all patterns in one go
- inputfile = getOptionalFile( _descrdir / it->first, false /*filename already contains .gz */ );
- }
- else if ( isPatternFile( it->first ) )
- {
- // *** see also zypp/repo/susetags/Downloader.cc ***
-
- // omit unwanted patterns, see https://bugzilla.novell.com/show_bug.cgi?id=298716
- // expect "<name>.<arch>.pat[.gz]", <name> might contain additional dots
- // split at dots, take .pat or .pat.gz into account
-
- // vector of splitted pattern filename elements
- std::vector<std::string> patparts;
-
- // this is the offset from the last element of patparts
- unsigned archoff = 2;
-
- unsigned count = str::split( it->first, std::back_inserter( patparts ), "." );
-
- if ( patparts[count-1] == "gz" )
- archoff++;
-
- if ( count > archoff )
- {
- try // might by an invalid architecture
- {
- Arch patarch( patparts[count-archoff] );
- if ( !patarch.compatibleWith( ZConfig::instance().systemArchitecture() ) )
- {
- // discard, if not compatible
- MIL << "Discarding pattern " << it->first << endl;
- continue;
- }
- }
- catch ( const Exception & excpt )
- {
- WAR << "Pattern file name does not contain recognizable architecture: " << it->first << endl;
- // keep .pat file if it doesn't contain an recognizable arch
- }
- }
- inputfile = getOptionalFile( _descrdir / it->first, false /*filename already contains .gz */ );
-
- }
- if ( ! inputfile.empty() )
- {
- PatternFileReader reader;
- reader.setConsumer( bind( &Impl::consumePat, this, _1 ) );
- CombinedProgressData progress( _ticks, PathInfo(inputfile).size() );
- reader.parse( inputfile, progress );
- }
- }
-
- // Done
- if ( ! _ticks.toMax() )
- ZYPP_THROW( AbortRequestException() );
-
- MIL << "DONE " << reporoot_r << "("
- << _stats.prod << " products, "
- << _stats.patt << " patterns, "
- << _stats.pack << " packages, "
- << _stats.srcp << " srcpackages)" << endl;
- }
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : RepoParser
- //
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : RepoParser::RepoParser
- // METHOD TYPE : Ctor
- //
- RepoParser::RepoParser( const std::string & repositoryId_r,
- data::ResolvableDataConsumer & consumer_r,
- const ProgressData::ReceiverFnc & fnc_r )
- : _pimpl( new Impl( repositoryId_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
-///////////////////////////////////////////////////////////////////
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/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.
- *
- * Reads a \c content file to get the \ref data::Product and a \Ref RepoIndex.
- * Then parses the remaining files and feeds them to a \ref data::ResolvableDataConsumer
- * (typically to store them in a database).
- *
- * \see \ref ContentFileReader and \ref FileReaderBase
- *
- * \code
- * Pathname dbdir( "store" );
- * Pathname reporoot( "lmd" );
- *
- * cache::CacheStore store( dbdir );
- * data::RecordId catalogId = store.lookupOrAppendRepository( Url("dir:///somewhere"), "/" );
- *
- * parser::susetags::RepoParser repo( catalogId, store );
- * repo.parse( reporoot );
- *
- * store.commit();
- * \endcode
- *
- * \todo Improve selection of Languages to parse
- * \todo Improve feeding of translations into Cachestore. Add specialized consumer, for Du too.
- * \todo DiskUsage filereader and parsing
- * \todo more doc and Exception specification
- */
- class RepoParser : private base::NonCopyable
- {
- public:
- /** Ctor.
- *
- * \param repositoryId_r repository identifier
- * \param consumer_r consumer of parsed data
- * \param fnc_r progress reporting function
- */
- RepoParser( const std::string &repositoryId_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<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- };
- ///////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////
- } // namespace susetags
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP2_PARSER_SUSETAGS_REPOPARSER_H
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/FileReaderBase.h
- *
- */
-#ifndef ZYPP_PARSER_YUM_FILEREADERBASE_H_
-#define ZYPP_PARSER_YUM_FILEREADERBASE_H_
-
-#include "zypp/base/PtrTypes.h"
-#include "zypp/base/NonCopyable.h"
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- /**
- * Base for yum::*FileReaders. Implements parsing methods for common metadata.
- */
- class FileReaderBase : private base::NonCopyable
- {
- protected:
- class BaseImpl;
- };
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-
-#endif /*ZYPP_PARSER_YUM_FILEREADERBASE_H_*/
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/FileReaderBaseImpl.cc
- * Implementation of shared code for yum::*FileReaders.
- */
-#include <sstream>
-
-#include "zypp/base/Logger.h"
-#include "zypp/base/Function.h"
-#include "zypp/Arch.h"
-#include "zypp/Edition.h"
-#include "zypp/TranslatedText.h"
-#include "zypp/ByteCount.h"
-
-#include "zypp/parser/ParseException.h"
-#include "zypp/parser/yum/FileReaderBaseImpl.h"
-
-using namespace std;
-using namespace zypp::xml;
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- FileReaderBase::BaseImpl::BaseImpl()
- : _expect_rpm_entry(false), _dtype(zypp::Dep::REQUIRES)
- {}
-
- // --------------------------------------------------------------------------
-
- /*
- * xpath and multiplicity of processed nodes are included in the code
- * for convenience:
- *
- * // xpath: <xpath> (?|*|+)
- *
- * if multiplicity is ommited, then the node has multiplicity 'one'.
- */
-
- // --------------------------------------------------------------------------
-
- bool FileReaderBase::BaseImpl::consumePackageNode(xml::Reader & reader_r, data::Packagebase_Ptr & package_ptr)
- {
- // DBG << "**node: " << reader_r->name() << " (" << reader_r->nodeType() << ") tagpath = " << _tagpath << endl;
- if (!isBeingProcessed(tag_package))
- ZYPP_THROW(ParseException("consumePackageNode() called outside of package element"));
-
- if (isBeingProcessed(tag_format) && consumeFormatNode(reader_r, package_ptr))
- return true;
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: //package/name
- if (reader_r->name() == "name")
- {
- package_ptr->name = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: //package/arch
- if (reader_r->name() == "arch")
- {
- string arch = reader_r.nodeText().asString();
- // create SrcPackage instead of Package for source packages
- if (arch == "src" || arch == "nosrc")
- {
- arch = "noarch";
- data::Packagebase_Ptr srcpkg = new data::SrcPackage;
- // we have read name only so far, copying only the name
- srcpkg->name = package_ptr->name;
- // package_ptr will point to a SrcPackage from now on
- package_ptr.swap(srcpkg);
- }
- package_ptr->arch = Arch( arch );
- return true;
- }
-
- // xpath: //package/version
- if (reader_r->name() == "version")
- {
- package_ptr->edition = Edition( reader_r->getAttribute("ver").asString(),
- reader_r->getAttribute("rel").asString(),
- reader_r->getAttribute("epoch").asString() );
- return true;
- }
-
- // xpath: //package/checksum
- if (reader_r->name() == "checksum")
- {
- package_ptr->repositoryLocation.setChecksum(CheckSum(
- reader_r->getAttribute("type").asString(),
- reader_r.nodeText().asString()));
- // ignoring pkgid attribute
- return true;
- }
-
- // xpath: //package/summary (*)
- if (reader_r->name() == "summary")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- package_ptr->summary.setText(
- reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: //package/description (*)
- if (reader_r->name() == "description")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- package_ptr->description.setText(
- reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: //package/packager
- if (reader_r->name() == "packager")
- {
- package_ptr->packager = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: //package/url
- if (reader_r->name() == "url")
- {
- package_ptr->url = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: //package/time
- if (reader_r->name() == "time")
- {
- package_ptr->buildTime = reader_r->getAttribute("build").asString();
- // ignoring reader_r->getAttribute("file").asString(); (rpm file timestamp)
- return true;
- }
-
- // xpath: //package/size
- if (reader_r->name() == "size")
- {
- //! \todo what's 'archive' size of the package (it is neither the rpm file size nor its installed size)
- // reader_r->getAttribute("archive").asString();
-
- // installed size
- package_ptr->installedSize = str::strtonum<ByteCount::SizeType>( reader_r->getAttribute("installed").asString() );
-
- // rpm package size
- package_ptr->repositoryLocation.setDownloadSize(str::strtonum<ByteCount::SizeType>( reader_r->getAttribute("package").asString() ));
-
- return true;
- }
-
- // xpath: //package/location
- if (reader_r->name() == "location")
- {
- package_ptr->repositoryLocation.setLocation(reader_r->getAttribute("href").asString(), 1);
- return true;
- }
-
- // xpath: //package/format
- if (reader_r->name() == "format")
- {
- tag(tag_format);
- return true;
- }
- }
-
- else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
- {
- // xpath: //package
- if (reader_r->name() == "package")
- {
- // indicate that further processing is required
- // e.g. caller needs to to check for </package> to trigger some action
- return false;
- }
- }
-
- return true;
- }
-
- // --------------( consume <format> tag )------------------------------------
-
- bool FileReaderBase::BaseImpl::consumeFormatNode(
- xml::Reader & reader_r, data::Packagebase_Ptr & package_ptr)
- {
- if (consumeDependency(reader_r, package_ptr->deps))
- // this node has been a dependency, which has been handled by
- // consumeDependency(), so return right away.
- return true;
-
- // DBG << "format subtag: " << reader_r->name() << endl;
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: //format/rpm:license
- if (reader_r->name() == "rpm:license")
- {
- package_ptr->license = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: //format/rpm:vendor
- if (reader_r->name() == "rpm:vendor")
- {
- package_ptr->vendor = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: //format/rpm:group
- if (reader_r->name() == "rpm:group")
- {
- package_ptr->group = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: //format/rpm:buildhost
- if (reader_r->name() == "rpm:buildhost")
- {
- package_ptr->buildhost = reader_r.nodeText().asString();
- return true;
- }
-
- //! \todo xpath: //format/rpm:sourcerpm where to store this?
- if (reader_r->name() == "rpm:sourcerpm")
- {
- //package->source = reader_r.nodeText().asString();
- return true;
- }
-
- //! \todo xpath: //format/rpm:header-range what is this?
- if (reader_r->name() == "rpm:header-range")
- {
- //reader_r->getAttribute("start").asString(),
- //reader_r->getAttribute("end").asString(),
- return true;
- }
-
- // file entries listed outside of filelists.xml to be treated
- // like rpm:provides
- // xpath: //format/file (*)
- if (reader_r->name() == "file")
- {
- // insert file dependency into the list
- package_ptr->deps[Dep::PROVIDES].insert( Capability( reader_r.nodeText().asString(), Capability::PARSED ) );
- return true;
- }
-
- // xpath: //format/suse:authors/suse:author (+)
- // but tolerating multiplicity (*)
- if (reader_r->name() == "suse:author")
- {
- package_ptr->authors.push_back(reader_r.nodeText().asString());
- return true;
- }
-
- // xpath: //format/suse:keywords (?)
- // xpath: //format/suse:keywords/suse:keyword (+)
- if (reader_r->name() == "suse:keyword")
- {
- package_ptr->keywords.insert(reader_r.nodeText().asString());
- return true;
- }
-
- //! \todo xpath: //format/suse:dirsizes (?)
-
- // xpath: //format/suse:install-only (?)
- if (reader_r->name() == "suse:install-only")
- {
- package_ptr->installOnly = true;
- return true;
- }
-
- // xpath: //format/suse:license-to-confirm (*)
- //! \todo this is ambiguous - fix the rnc schema
- if (reader_r->name() == "suse:license-to-confirm")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- package_ptr->licenseToConfirm.setText(
- reader_r.nodeText().asString(), locale);
- return true;
- }
- }
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: //format
- if (reader_r->name() == "format")
- {
- toParentTag();
- return true;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- bool FileReaderBase::BaseImpl::consumeDependency(
- xml::Reader & reader_r, data::Dependencies & deps_r)
- {
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: //format/*/rpm:entry | //format/suse-freshens/suse:entry (+)
- if (reader_r->name() == "rpm:entry" || reader_r->name() == "suse:entry")
- {
- if (!_expect_rpm_entry)
- ZYPP_THROW(ParseException("rpm:entry found when not expected"));
-
- // read kind of resolvable this entry refers, default to Package
- ResKind kind( reader_r->getAttribute("kind").asString() );
- if ( ! kind )
- kind = ResKind::package;
-
- // Check whether this is actually a prerequires dependency.
- // If so, it will be stored in deps_r as Dep::PREREQUIRES
- // instead of Dep::REQUIRES (a prerequires can appear as part
- // of requires dependencies only).
- bool pre = false;
- if (reader_r->getAttribute("pre").asString() == "1")
- {
- if (_dtype.inSwitch() != Dep::REQUIRES_e)
- ZYPP_THROW(ParseException("pre=\"1\" found for non-requires dependency"));
- pre = true;
- }
-
- string version = reader_r->getAttribute("ver").asString();
-
- if (version.empty())
- {
- // insert unversion dependency into the list
- deps_r[pre ? Dep::PREREQUIRES : _dtype].insert(
- Capability( reader_r->getAttribute("name").asString(), kind, Capability::PARSED )
- );
- }
- else
- {
- Edition edition(
- version,
- reader_r->getAttribute("rel").asString(),
- reader_r->getAttribute("epoch").asString()
- );
-
- // insert versioned dependency into the list
- deps_r[pre ? Dep::PREREQUIRES : _dtype].insert(
- Capability( reader_r->getAttribute("name").asString(),
- Rel( reader_r->getAttribute("flags").asString() ),
- edition,
- kind )
- );
- }
-
- //! \todo check <rpm:entry name="/bin/sh" pre="1">
- }
-
- // xpath: //format/rpm:provides (?)
- if (reader_r->name() == "rpm:provides")
- {
- _dtype = zypp::Dep::PROVIDES;
- _expect_rpm_entry = true;
- return true;
- }
- // xpath: //format/rpm:conflicts (?)
- if (reader_r->name() == "rpm:conflicts")
- {
- _dtype = zypp::Dep::CONFLICTS;
- _expect_rpm_entry = true;
- return true;
- }
- // xpath: //format/rpm:obsoletes (?)
- if (reader_r->name() == "rpm:obsoletes")
- {
- _dtype = zypp::Dep::OBSOLETES;
- _expect_rpm_entry = true;
- return true;
- }
- // xpath: //format/rpm:requires (?)
- if (reader_r->name() == "rpm:requires")
- {
- _dtype = zypp::Dep::REQUIRES;
- _expect_rpm_entry = true;
- return true;
- }
- // xpath: //format/rpm:recommends (?)
- if (reader_r->name() == "rpm:recommends")
- {
- _dtype = zypp::Dep::RECOMMENDS;
- _expect_rpm_entry = true;
- return true;
- }
- // xpath: //format/rpm:enhances (?)
- if (reader_r->name() == "rpm:enhances")
- {
- _dtype = zypp::Dep::ENHANCES;
- _expect_rpm_entry = true;
- return true;
- }
- // xpath: //format/rpm:supplements (?)
- if (reader_r->name() == "rpm:supplements")
- {
- _dtype = zypp::Dep::SUPPLEMENTS;
- _expect_rpm_entry = true;
- return true;
- }
- // xpath: //format/rpm:suggests (?)
- if (reader_r->name() == "rpm:suggests")
- {
- _dtype = zypp::Dep::SUGGESTS;
- _expect_rpm_entry = true;
- return true;
- }
- // xpath: //format/suse:freshens (?)
- if (reader_r->name() == "suse:freshens")
- {
- _dtype = zypp::Dep::FRESHENS;
- _expect_rpm_entry = true;
- }
- }
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: //format/* (?)
- if (reader_r->name() == "rpm:requires"
- || reader_r->name() == "rpm:provides"
- || reader_r->name() == "rpm:conflicts"
- || reader_r->name() == "rpm:obsoletes"
- || reader_r->name() == "rpm:recommends"
- || reader_r->name() == "rpm:enhances"
- || reader_r->name() == "rpm:supplements"
- || reader_r->name() == "rpm:suggests"
- || reader_r->name() == "suse:freshens")
- {
- _expect_rpm_entry = false;
- return true;
- }
- }
-
- // tell the caller this has not been a dependency tag (i.e. not processed)
- return false;
- }
-
- // --------------------------------------------------------------------------
-
- string FileReaderBase::BaseImpl::TagPath::asString()
- {
- ostringstream s;
-
- s << "(";
-
- if (depth())
- {
- TagList::const_iterator p = path.begin();
- s << *p;
- ++p;
-
- for (; p != path.end(); ++p)
- s << "," << *p;
- }
- else
- s << "empty";
-
- s << ")";
-
- return s.str();
- }
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/FileReaderBaseImpl.h
- * Implementation interface of shared code for yum::*FileReaders.
- */
-#ifndef ZYPP_PARSER_YUM_FILEREADERBASEIMPL_H_
-#define ZYPP_PARSER_YUM_FILEREADERBASEIMPL_H_
-
-#include "zypp/data/ResolvableData.h"
-#include "zypp/parser/xml/Reader.h"
-
-#include "zypp/parser/yum/FileReaderBase.h"
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- class FileReaderBase::BaseImpl : private base::NonCopyable
- {
- public:
-
- /**
- * Enumeration of some YUM metadata xml tags.
- */
- enum Tag
- {
- tag_NONE,
- tag_package,
- tag_format,
- tag_patch,
- tag_atoms,
- tag_script,
- tag_message,
- tag_pkgfiles,
- tag_deltarpm,
- tag_patchrpm,
- tag_pattern,
- tag_product
- };
-
- /**
- * Lightweight object for remembering currently processed tag.
- *
- * Usage:
- *
- * - call \ref append() on opening tag
- * - use \ref contains() to check if the given tag is being processed
- * - call \ref remove() on closing tag
- *
- * \note the above works only if the path elements are unique. To support
- * also non-unique elements, an equals() method will need to be implemented
- * and used instead of \ref contains().
- *
- * \note tags you want to use with TagPath must be enumerated in \ref Tag
- * enum.
- */
- struct TagPath
- {
- typedef std::list<Tag> TagList;
-
- void append(const Tag tag) { path.push_back(tag); }
- void remove() { if (!path.empty()) path.pop_back(); }
- unsigned depth() const { return path.size(); }
- Tag currentTag() const
- {
- if (!path.empty()) return path.back();
- return tag_NONE;
- }
- bool contains(const Tag tag) const
- {
- TagList::const_iterator result = find(path.begin(), path.end(), tag);
- return result != path.end();
- }
- std::string asString();
-
- TagList path;
- };
-
-
- public:
- /** CTOR */
- BaseImpl();
-
- /**
- * Process package node and its subtree.
- * This method can be extended for specific implementations.
- *
- * \param reader_r
- * \param package_ptr This can be either data::Package or data::SrcPackage.
- * \return true if the package node or current subnode has been consumed
- * (no further processing is required), false otherwise.
- * \throws ParseException if a serious error is encountered while parsing
- */
- bool consumePackageNode(xml::Reader & reader_r, data::Packagebase_Ptr & package_ptr);
-
- /**
- * Function for processing all <code>format</code> tag subtree nodes.
- *
- * \return true if the package node or current subnode has been consumed
- * (no further processing is required), false otherwise.
- */
- bool consumeFormatNode(xml::Reader & reader_r, data::Packagebase_Ptr & package_ptr);
-
- /**
- * Processes RPM dependency tags (rpm:entry, rpm:requires, ...).
- *
- * \return true if a dependency tag has been encountered, false otherwise.
- * \throws ParseException if a serious error is encountered while parsing
- */
- bool consumeDependency(xml::Reader & reader_r, data::Dependencies & deps_r);
-
- void editionStringFromAttrs( xml::Reader & reader_r, Edition & edition ) const
- { edition = Edition( reader_r->getAttribute("ver").asString(),
- reader_r->getAttribute("rel").asString(),
- reader_r->getAttribute("epoch").asString() ); }
-
- public:
- /** Appends \a tag to \ref _tagpath. */
- void tag(const Tag tag) { _tagpath.append(tag); }
-
- /** Check whether we are currently processing given \a tag. */
- bool isBeingProcessed(Tag tag) const { return _tagpath.contains(tag); }
-
- /** Move to parent tag in the \ref _tagpath. */
- void toParentTag() { _tagpath.remove(); }
-
- /** Getter of the tagpath object. */
- const TagPath & tagPath() const { return _tagpath; }
-
-
- private:
- /** Used to remember the tag beeing currently processed. */
- TagPath _tagpath;
-
- /**
- * Used to remember whether we are expecting an rpm:entry tag
- * e.g. for rpm:requires
- */
- bool _expect_rpm_entry;
-
- /**
- * Type of dependecy beeing processed.
- */
- Dep _dtype;
- };
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-#endif /*ZYPP_PARSER_YUM_FILEREADERBASEIMPL_H_*/
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/FilelistsFileReader.cc
- * Implementation of filelists.xml.gz file reader.
- */
-#include "zypp/base/Logger.h"
-#include "zypp/parser/xml/Reader.h"
-#include "zypp/base/UserRequestException.h"
-
-#include "zypp/parser/yum/FilelistsFileReader.h"
-#include "zypp/parser/yum/FileReaderBaseImpl.h"
-
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
-
-using namespace std;
-using namespace zypp::xml;
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- ///////////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : FilelistsFileReader::Impl
- //
- class FilelistsFileReader::Impl : public BaseImpl
- {
- public:
- Impl(
- const Pathname & filelists_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc());
-
- public:
-
- /**
- * Callback provided to the XML parser.
- */
- bool consumeNode(xml::Reader & reader_r);
-
- /**
- * Creates a new \ref data::Resolvable_Ptr, swaps its contents with
- * \ref _resolvable and returns it. Used to hand-out the data object to its consumer
- * (a \ref ProcessPackage function) after it has been read.
- */
- data::Resolvable_Ptr handoutResolvable();
-
- private:
-
- /**
- * Pointer to the \ref zypp::data::Resolvable object for storing the NVRA
- * data.
- */
- zypp::data::Resolvable_Ptr _resolvable;
-
- /**
- * Changelog of \ref _resolvable.
- */
- data::Filenames _filenames;
-
- /**
- * Callback for processing package metadata. Passed in through constructor.
- */
- ProcessPackage _callback;
-
- /**
- * Progress reporting object.
- */
- ProgressData _ticks;
- };
- ///////////////////////////////////////////////////////////////////////
-
- FilelistsFileReader::Impl::Impl(
- const Pathname & filelists_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress)
- :
- _callback(callback)
- {
- _ticks.sendTo(progress);
- _ticks.name("filelist.xml.gz");
-
- Reader reader(filelists_file);
- MIL << "Reading " << filelists_file << endl;
- reader.foreachNode(bind(&FilelistsFileReader::Impl::consumeNode, this, _1));
- }
-
- // --------------------------------------------------------------------------
-
- /*
- * xpath and multiplicity of processed nodes are included in the code
- * for convenience:
- *
- * // xpath: <xpath> (?|*|+)
- *
- * if multiplicity is ommited, then the node has multiplicity 'one'.
- */
-
- // --------------------------------------------------------------------------
-
-
- bool FilelistsFileReader::Impl::consumeNode(Reader & reader_r)
- {
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /filelists
- if (reader_r->name() == "filelists")
- {
- unsigned total_packages;
- zypp::str::strtonum(reader_r->getAttribute("packages").asString(), total_packages);
- _ticks.range(total_packages);
- _ticks.toMin();
- return true;
- }
-
- // xpath: /filelists/package (+)
- if (reader_r->name() == "package")
- {
- _resolvable = new data::Resolvable;
- _filenames.clear();
-
- _resolvable->name = reader_r->getAttribute("name").asString();
- _resolvable->arch = Arch( reader_r->getAttribute("arch").asString() );
-
- return true;
- }
-
- // xpath: /filelists/package/version
- if (reader_r->name() == "version")
- {
- editionStringFromAttrs( reader_r, _resolvable->edition );
- return true;
- }
-
- // xpath: /filelists/package/file (*)
- if (reader_r->name() == "file")
- {
- // ignoring type dir/ghost reader_r->getAttribute("type").asString();
- _filenames.push_back(reader_r.nodeText().asString());
- return true;
- }
- }
-
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /filelists/package
- if (reader_r->name() == "package")
- {
- if (_callback && !_filenames.empty())
- _callback(handoutResolvable(), _filenames);
-
- if (!_ticks.incr())
- ZYPP_THROW(AbortRequestException());
-
- return true;
- }
-
- // xpath: /filelists
- if (reader_r->name() == "filelists")
- {
- _ticks.toMax();
- return true;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- data::Resolvable_Ptr FilelistsFileReader::Impl::handoutResolvable()
- {
- data::Resolvable_Ptr ret;
- ret.swap(_resolvable);
- return ret;
- }
-
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : FilelistsFileReader
- //
- ///////////////////////////////////////////////////////////////////
-
- FilelistsFileReader::FilelistsFileReader(
- const Pathname & filelists_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress)
- :
- _pimpl(new Impl(filelists_file, callback, progress))
- {}
-
- FilelistsFileReader::~FilelistsFileReader()
- {}
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/FilelistsFileReader.h
- * Interface of filelists.xml.gz file reader.
- */
-#ifndef ZYPP_PARSER_YUM_FILELISTFILEREADER_H_
-#define ZYPP_PARSER_YUM_FILELISTFILEREADER_H_
-
-#include "zypp/base/PtrTypes.h"
-#include "zypp/base/NonCopyable.h"
-#include "zypp/base/Function.h"
-#include "zypp/data/ResolvableData.h"
-
-#include "zypp/ProgressData.h"
-
-#include "zypp/parser/yum/FileReaderBase.h"
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- /**
- * Reads through a filelists.xml.gz file and collects list of file contained
- * in packages.
- *
- * After each package is read, a \ref data::Resolvable
- * and \ref data::Filenames is prepared and \ref _callback
- * is called with these two objects passed in.
- *
- * The \ref _callback is provided on construction.
- *
- * \code
- * FilelistsFileReader reader(filelists_file,
- * bind(&SomeClass::callbackfunc, &SomeClassInstance, _1, _2));
- * \endcode
- */
- class FilelistsFileReader : FileReaderBase
- {
- public:
- /**
- * Callback definition.
- */
- typedef function<bool(const data::Resolvable_Ptr &, const data::Filenames &)> ProcessPackage;
-
- /**
- * CTOR. Creates also \ref xml::Reader and starts reading.
- *
- * \param filelists_file the filelists.xml.gz file you want to read
- * \param callback function to process \ref _resolvable data.
- * \param progress progress reporting object
- *
- * \see FilelistsFileReader::ProcessPackage
- */
- FilelistsFileReader(
- const Pathname & filelists_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc());
-
- /**
- * DTOR.
- */
- ~FilelistsFileReader();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- };
-
-
- } // ns zypp
- } // ns parser
-} // ns yum
-
-#endif /*ZYPP_PARSER_YUM_FILELISTFILEREADER_H_*/
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/OtherFileReader.cc
- * Implementation of other.xml.gz file reader.
- */
-#include "zypp/base/Logger.h"
-#include "zypp/parser/xml/Reader.h"
-#include "zypp/data/ResolvableData.h"
-#include "zypp/Changelog.h"
-#include "zypp/base/UserRequestException.h"
-
-#include "zypp/parser/yum/OtherFileReader.h"
-#include "zypp/parser/yum/FileReaderBaseImpl.h"
-
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
-
-using namespace std;
-using namespace zypp::xml;
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- ///////////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : OtherFileReader::Impl
- //
- class OtherFileReader::Impl : public BaseImpl
- {
- public:
- Impl(
- const Pathname & other_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress);
-
- public:
-
- /**
- * Callback provided to the XML parser.
- */
- bool consumeNode(xml::Reader & reader_r);
-
- /**
- * Creates a new \ref data::Resolvable_Ptr, swaps its contents with
- * \ref _resolvable and returns it. Used to hand-out the data object to its consumer
- * (a \ref ProcessPackage function) after it has been read.
- */
- data::Resolvable_Ptr handoutResolvable();
-
- private:
-
- /**
- * Pointer to the \ref zypp::data::Resolvable object for storing the NVRA
- * data.
- */
- zypp::data::Resolvable_Ptr _resolvable;
-
- /**
- * Changelog of \ref _resolvable.
- */
- Changelog _changelog;
-
- /**
- * Callback for processing package metadata passed in through constructor.
- */
- ProcessPackage _callback;
-
- /**
- * Progress reporting object.
- */
- ProgressData _ticks;
- };
- ///////////////////////////////////////////////////////////////////////
-
- OtherFileReader::Impl::Impl(
- const Pathname & other_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress)
- :
- _callback(callback)
- {
- _ticks.sendTo(progress);
- _ticks.name("other.xml.gz");
-
- Reader reader(other_file);
- MIL << "Reading " << other_file << endl;
- reader.foreachNode(bind(&OtherFileReader::Impl::consumeNode, this, _1));
- }
-
- // --------------------------------------------------------------------------
-
- /*
- * xpath and multiplicity of processed nodes are included in the code
- * for convenience:
- *
- * // xpath: <xpath> (?|*|+)
- *
- * if multiplicity is ommited, then the node has multiplicity 'one'.
- */
-
- // --------------------------------------------------------------------------
-
- bool OtherFileReader::Impl::consumeNode(Reader & reader_r)
- {
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /otherdata
- if (reader_r->name() == "otherdata")
- {
- unsigned total_packages;
- zypp::str::strtonum(reader_r->getAttribute("packages").asString(), total_packages);
- _ticks.range(total_packages);
- _ticks.toMin();
- return true;
- }
-
- // xpath: /otherdata/package (+)
- if (reader_r->name() == "package")
- {
- _resolvable = new data::Resolvable;
- _changelog.clear();
-
- _resolvable->name = reader_r->getAttribute("name").asString();
- _resolvable->arch = Arch( reader_r->getAttribute("arch").asString() );
-
- return true;
- }
-
- // xpath: /otherdata/package/version
- if (reader_r->name() == "version")
- {
- editionStringFromAttrs( reader_r, _resolvable->edition );
- return true;
- }
-
- // xpath: /otherdata/package/changelog (*)
- if (reader_r->name() == "changelog")
- {
- ChangelogEntry entry(
- Date(reader_r->getAttribute("date").asString()),
- reader_r->getAttribute("author").asString(),
- reader_r.nodeText().asString());
- _changelog.push_back(entry);
- return true;
- }
- }
-
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /otherdata/package
- if (reader_r->name() == "package")
- {
- if (_callback && !_changelog.empty())
- _callback(handoutResolvable(), _changelog);
-
- if (!_ticks.incr())
- ZYPP_THROW(AbortRequestException());
-
- return true;
- }
-
- // xpath: /otherdata
- if (reader_r->name() == "otherdata")
- {
- _ticks.toMax();
- return true;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- data::Resolvable_Ptr OtherFileReader::Impl::handoutResolvable()
- {
- data::Resolvable_Ptr ret;
- ret.swap(_resolvable);
- return ret;
- }
-
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : OtherFileReader
- //
- ///////////////////////////////////////////////////////////////////
-
- OtherFileReader::OtherFileReader(
- const Pathname & other_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress)
- :
- _pimpl(new Impl(other_file, callback, progress))
- {}
-
- OtherFileReader::~OtherFileReader()
- {}
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/OtherFileReader.h
- * Interface of other.xml.gz file reader.
- */
-#ifndef OTHERFILEREADER_H_
-#define OTHERFILEREADER_H_
-
-#include "zypp/base/PtrTypes.h"
-#include "zypp/base/NonCopyable.h"
-#include "zypp/data/ResolvableData.h"
-#include "zypp/base/Function.h"
-#include "zypp/ProgressData.h"
-
-#include "zypp/parser/yum/FileReaderBase.h"
-
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- /**
- * Reads through a other.xml file and collects additional package data
- * (changelogs).
- *
- * After a package is read, a \ref data::Resolvable
- * and \ref Changelog is prepared and \ref _callback
- * is called with these two objects passed in.
- *
- * The \ref _callback is provided on construction.
- *
- * \code
- * OtherFileReader reader(other_file,
- * bind(&SomeClass::callbackfunc, &SomeClassInstance, _1, _2));
- * \endcode
- */
- class OtherFileReader : FileReaderBase
- {
- public:
- /**
- * Callback definition.
- */
- typedef function<bool(const data::Resolvable_Ptr &, const Changelog)> ProcessPackage;
-
- /**
- * CTOR. Creates also \ref xml::Reader and starts reading.
- *
- * \param other_file the other.xml.gz file you want to read
- * \param callback function to process \ref _resolvable data.
- * \param progress progress reporting object
- *
- * \see OtherFileReader::ProcessPackage
- */
- OtherFileReader(
- const Pathname & other_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc());
-
- /**
- * DTOR
- */
- ~OtherFileReader();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- };
-
-
- } // ns zypp
- } // ns parser
-} // ns yum
-
-#endif /*OTHERFILEREADER_H_*/
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/PatchFileReader.cc
- * Implementation of patch XML file reader.
- */
-#include "zypp/base/Logger.h"
-#include "zypp/parser/xml/Reader.h"
-#include "zypp/data/ResolvableData.h"
-
-#include "zypp/parser/yum/PatchFileReader.h"
-#include "zypp/parser/yum/FileReaderBaseImpl.h"
-
-#include "zypp/ZConfig.h"
-
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
-
-using namespace std;
-using namespace zypp::xml;
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- ///////////////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PatchFileReader::Impl
- //
- class PatchFileReader::Impl : public BaseImpl
- {
- public:
- /** CTOR */
- Impl(const Pathname & patch_file,
- const ProcessPatch & callback);
-
- /**
- * Callback provided to the XML reader.
- *
- * \param the xml reader object reading the file
- * \return true to tell the reader to continue, false to tell it to stop
- *
- * \see PrimaryFileReader::consumeNode(xml::Reader)
- */
- bool consumeNode(xml::Reader & reader_r);
-
- /**
- * Process <tt>atoms</tt> node and all of its children.
- *
- * \param reader_r XML file reader reading the patch file.
- * \return true if current node has been completely processed, false
- * if additional processing is required outside of the method.
- */
- bool consumeAtomsNode(xml::Reader & reader_r);
-
- /**
- * Process <tt>package</tt> node and all of its children. This method
- * uses \ref FileReaderBase::consumePackageNode(xml::Reader,data::Package_Ptr)
- * method and adds <tt>pkgfiles</tt> element processing.
- *
- * \param reader_r XML file reader reading the patch file.
- * \return true if current node has been completely processed, false
- * if additional processing is required outside of the method.
- */
- bool consumePackageNode(xml::Reader & reader_r);
-
- /**
- * Process <tt>patchrpm</tt> node and all of its children.
- *
- * \param reader_r XML file reader reading the patch file.
- * \return true if current node has been completely processed, false
- * if additional processing is required outside of the method.
- */
- bool consumePatchrpmNode(xml::Reader & reader_r);
-
- /**
- * Process <tt>deltarpm</tt> node and all of its children.
- *
- * \param reader_r XML file reader reading the patch file.
- * \return true if current node has been completely processed, false
- * if additional processing is required outside of the method.
- */
- bool consumeDeltarpmNode(xml::Reader & reader_r);
-
- /**
- * Process <tt>message</tt> node and all of its children.
- *
- * \param reader_r XML file reader reading the patch file.
- * \return true if current node has been completely processed, false
- * if additional processing is required outside of the method.
- */
- bool consumeMessageNode(xml::Reader & reader_r);
-
- /**
- * Process <tt>script</tt> node and all of its children.
- *
- * \param reader_r XML file reader reading the patch file.
- * \return true if current node has been completely processed, false
- * if additional processing is required outside of the method.
- */
- bool consumeScriptNode(xml::Reader & reader_r);
-
- /**
- * Creates a new \ref data::Patch_Ptr, swaps its contents with \ref _patch
- * and returns it. Used to hand-out the data object to its consumer
- * (a \ref ProcessPatch function) after it has been read.
- */
- data::Patch_Ptr handoutPatch();
-
- /**
- * Creates a new \ref data::ResObject_Ptr, swap its contents with
- * \ref _tmpResObj and inserts it into <tt>_patch.atoms</tt>. Used
- * after an atom is read.
- */
- void saveAtomInPatch();
-
- /**
- *
- */
- void copyPackageAtomFromTmpObj(data::Atom_Ptr & atom_ptr) const;
-
- private:
- /**
- * Callback for processing patch metadata passed in through constructor.
- */
- ProcessPatch _callback;
-
- /**
- * Pointer to the \ref zypp::data::Patch object for storing the patch
- * metada (except of depencencies).
- */
- data::Patch_Ptr _patch;
-
- /**
- * Pointer to an atom currently being read. This can be either
- * a \ref data::PackageAtom, \ref data::Message, or \ref data::Script.
- *
- * \see data::Patch::atoms
- */
- data::ResObject_Ptr _tmpResObj;
-
- /** Data object for storing patchrpm data */
- data::PatchRpm_Ptr _patchrpm;
-
- /** Data object for storing deltarpm data */
- data::DeltaRpm_Ptr _deltarpm;
- };
- ///////////////////////////////////////////////////////////////////////////
-
- PatchFileReader::Impl::Impl(
- const Pathname & patch_file,
- const ProcessPatch & callback)
- :
- _callback(callback)
- {
- Reader reader(patch_file);
- MIL << "Reading " << patch_file << endl;
- reader.foreachNode(bind(&PatchFileReader::Impl::consumeNode, this, _1));
- }
-
- // --------------------------------------------------------------------------
-
- /*
- * xpath and multiplicity of processed nodes are included in the code
- * for convenience:
- *
- * // xpath: <xpath> (?|*|+)
- *
- * if multiplicity is ommited, then the node has multiplicity 'one'.
- */
-
- // --------------------------------------------------------------------------
-
- bool PatchFileReader::Impl::consumeNode(Reader & reader_r)
- {
- if (isBeingProcessed(tag_atoms) && consumeAtomsNode(reader_r))
- return true;
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /patch
- if (reader_r->name() == "patch")
- {
- tag(tag_patch);
-
- _patch = new data::Patch;
-
- _patch->id = reader_r->getAttribute("patchid").asString();
- _patch->timestamp = Date(reader_r->getAttribute("timestamp").asString());
- // reader_r->getAttribute("timestamp").asString() ?
- return true;
- }
-
- // xpath: /patch/yum:name
- if (reader_r->name() == "yum:name")
- {
- _patch->name = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: /patch/summary
- if (reader_r->name() == "summary")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- _patch->summary.setText(reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: /patch/description
- if (reader_r->name() == "description")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- _patch->description.setText(reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: /patch/licence-to-confirm (*)
- if (reader_r->name() == "license-to-confirm")
- {
- // TODO support several licenses in several languages?
- Locale locale(reader_r->getAttribute("lang").asString());
- _patch->licenseToConfirm.setText(reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: /patch/yum:version
- if (reader_r->name() == "yum:version")
- {
- editionStringFromAttrs( reader_r, _patch->edition );
- return true;
- }
-
- // dependency block nodes
- if (consumeDependency(reader_r, _patch->deps))
- return true;
-
- // xpath: /patch/category
- if (reader_r->name() == "category")
- {
- _patch->category = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: /patch/reboot-needed (?)
- if (reader_r->name() == "reboot-needed")
- {
- _patch->rebootNeeded = true;
- return true;
- }
-
- // xpath: /patch/package-manager (?)
- if (reader_r->name() == "package-manager")
- {
- _patch->affectsPkgManager = true;
- return true;
- }
-
- // xpath: /patch/update-script (?)
- if (reader_r->name() == "update-script")
- {
- _patch->updateScript = reader_r.nodeText().asString();
- }
-
- // xpath: /patch/atoms (+)
- if (reader_r->name() == "atoms")
- {
- // remember that we are processing atoms from now on
- // xpath: /patch/atoms/*
- tag(tag_atoms);
- // no need to further process this node so not calling
- // consumeAtomsNode() here
- return true;
- }
- }
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /patch
- if (reader_r->name() == "patch")
- {
- if (!_patch->atoms.size())
- WAR << "No atoms found for patch " << _patch->name << " " << _patch->edition << endl;
-
- if (_callback)
- _callback(handoutPatch());
-
- toParentTag(); // just for the case of reuse somewhere/sometimes
-
- return true;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- bool PatchFileReader::Impl::consumeAtomsNode(Reader & reader_r)
- {
- /*
- Implementation note:
-
- !!! do _NOT_ filter out incompatible architectures of atoms !!!
-
- See https://bugzilla.novell.com/show_bug.cgi?id=300569#c11
- */
-
- // consumePackageNode
- if (isBeingProcessed(tag_package) && consumePackageNode(reader_r))
- return true;
- // consumeMessageNode
- else if (isBeingProcessed(tag_message) && consumeMessageNode(reader_r))
- return true;
- // consumeScriptNode
- else if (isBeingProcessed(tag_script) && consumeScriptNode(reader_r))
- return true;
-
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /patch/atoms/package
- if (reader_r->name() == "package")
- {
- // remember that we are processing package from now on
- // xpath: /patch/atoms/package/*
- tag(tag_package);
- // DBG << "Atom node, tagpath: " << tagPath() << endl;
- _tmpResObj = new data::PackageAtom;
- // process also the package node attributes
- consumePackageNode(reader_r);
- return true;
- }
-
- // xpath: /patch/atoms/message
- if (reader_r->name() == "message")
- {
- // remember that we are processing message from now on
- // xpath: /patch/atoms/message/*
- tag(tag_message);
- // DBG << "Message node, tagpath: " << tagPath() << endl;
- _tmpResObj = new data::Message;
- return true;
- }
-
- // xpath: /patch/atoms/script
- if (reader_r->name() == "script")
- {
- // remember that we are processing script from now on
- // xpath: /patch/atoms/script/*
- tag(tag_script);
- // DBG << "Script node, tagpath: " << tagPath() << endl;
- _tmpResObj = new data::Script;
- return true;
- }
- }
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /patch/atoms/package
- if (reader_r->name() == "package")
- {
- // DBG << "Atom " << _tmpResObj->name << " " << _tmpResObj->edition << " successfully read." << endl;
-
- saveAtomInPatch();
- toParentTag(); // back to processing of previous tag (atoms)
- return true;
- }
-
- // xpath: /patch/atoms/message
- if (reader_r->name() == "message")
- {
- // DBG << "Message " << _tmpResObj->name << " " << _tmpResObj->edition << " successfully read." << endl;
-
- saveAtomInPatch();
- toParentTag(); // back to processing of previous tag (atoms)
- return true;
- }
-
- // xpath: /patch/atoms/script
- if (reader_r->name() == "script")
- {
- // DBG << "Script " << _tmpResObj->name << " " << _tmpResObj->edition << " successfully read." << endl;
-
- saveAtomInPatch();
- toParentTag(); // back to processing of previous tag (atoms)
- return true;
- }
-
- // xpath: /patch/atoms
- if (reader_r->name() == "atoms")
- {
- toParentTag(); // back to processing of previous tag (patch)
- return true;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- bool PatchFileReader::Impl::consumePackageNode(Reader & reader_r)
- {
- /*
- Implementation note:
-
- !!! do _NOT_ filter out incompatible architectures of atoms !!!
-
- See https://bugzilla.novell.com/show_bug.cgi?id=300569#c11
- */
-
- if (isBeingProcessed(tag_patchrpm) && consumePatchrpmNode(reader_r))
- return true;
- else if (isBeingProcessed(tag_deltarpm) && consumeDeltarpmNode(reader_r))
- return true;
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /patch/atoms/package/pkgfiles
- if (reader_r->name() == "pkgfiles")
- {
- tag(tag_pkgfiles);
- return true;
- }
-
- // xpath: /patch/atoms/package/pkgfiles/patchrpm (*)
- if (reader_r->name() == "patchrpm")
- {
- tag(tag_patchrpm);
- _patchrpm = new data::PatchRpm;
- return true;
- }
-
- // xpath: /patch/atoms/package/pkgfiles/deltarpm (*)
- if (reader_r->name() == "deltarpm")
- {
- tag(tag_deltarpm);
- _deltarpm = new data::DeltaRpm;
- return true;
- }
-
- // xpath: /patch/atoms/package/license-to-confirm (*)
- if (reader_r->name() == "license-to-confirm")
- {
- DBG << "got license-to-confirm, lang: " << reader_r->getAttribute("lang").asString();
-
- // no way to determine which translation is associated
- // with another, all previous will be overwritten with
- // the last one
- // TODO introduce an identifier in YUM data
- // TODO make this rely on tag order as a temporary solution?
-
- _tmpResObj->licenseToConfirm.setText(
- reader_r.nodeText().asString(),
- Locale(reader_r->getAttribute("lang").asString()));
-
- return true;
- }
- }
-
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /patch/atoms/package/pkgfiles
- if (reader_r->name() == "pkgfiles")
- {
- toParentTag();
- return true;
- }
-
- // xpath: /patch/atoms/package/pkgfiles/patchrpm (*)
- if (reader_r->name() == "patchrpm")
- {
- data::PatchRpm_Ptr tmp;
- tmp.swap(_patchrpm);
- data::PackageAtom_Ptr patom_ptr = zypp::dynamic_pointer_cast<data::PackageAtom>(_tmpResObj);
- if (patom_ptr && Arch(patom_ptr->arch).compatibleWith( ZConfig::instance().systemArchitecture() ))
- {
- // Patch and delta rpms are standalone objects.
- // We must store the target packages NVRA.
- // We don't store incompatible archs.
- tmp->name = patom_ptr->name;
- tmp->edition = Edition(patom_ptr->edition);
- tmp->arch = Arch(patom_ptr->arch);
- patom_ptr->patchRpms.insert(tmp);
- }
- toParentTag();
- return true;
- }
-
- // xpath: /patch/atoms/package/pkgfiles/deltarpm (*)
- if (reader_r->name() == "deltarpm")
- {
- data::DeltaRpm_Ptr tmp;
- tmp.swap(_deltarpm);
- data::PackageAtom_Ptr patom_ptr = zypp::dynamic_pointer_cast<data::PackageAtom>(_tmpResObj);
- if (patom_ptr && Arch(patom_ptr->arch).compatibleWith( ZConfig::instance().systemArchitecture() ))
- {
- // Patch and delta rpms are standalone objects.
- // We must store the target packages NVRA.
- // We don't store incompatible archs.
- tmp->name = patom_ptr->name;
- tmp->edition = Edition(patom_ptr->edition);
- tmp->arch = Arch(patom_ptr->arch);
- patom_ptr->deltaRpms.insert(tmp);
- }
- toParentTag();
- return true;
- }
- }
-
- // FileReaderBase::consumePackageNode() call here, otherwise the pkgfiles
- // would not be read.
- data::Packagebase_Ptr package_ptr = zypp::dynamic_pointer_cast<data::Packagebase>(_tmpResObj);
- if (package_ptr)
- {
- // xpath: /patch/atoms/package/* (except pkgfiles/* and license-to-confirm) (*)
- if (isBeingProcessed(tag_package))
- return FileReaderBase::BaseImpl::consumePackageNode(reader_r, package_ptr);
- }
- else
- {
- ZYPP_THROW(Exception("Error in parser code. Package atom object not found."));
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- bool PatchFileReader::Impl::consumePatchrpmNode(Reader & reader_r)
- {
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /patch/atoms/package/patchrpm/location
- if (reader_r->name() == "location")
- {
- _patchrpm->location.setLocation(reader_r->getAttribute("href").asString(), 1);
- // ignoring attribute 'base'
- return true;
- }
-
- // xpath: /patch/atoms/package/patchrpm/checksum
- if (reader_r->name() == "checksum")
- {
- _patchrpm->location.setChecksum(CheckSum(
- reader_r->getAttribute("type").asString(),
- reader_r.nodeText().asString()));
- return true;
- }
-
- // xpath: /patch/atoms/package/patchrpm/time
- if (reader_r->name() == "time")
- {
- _patchrpm->buildTime =
- Date(reader_r->getAttribute("build").asString());
-
- _patchrpm->fileTime =
- Date(reader_r->getAttribute("file").asString());
-
- return true;
- }
-
- // xpath: /patch/atoms/package/patchrpm/size
- if (reader_r->name() == "size")
- {
- // size of the rpm file
- _patchrpm->location.setDownloadSize(str::strtonum<ByteCount::SizeType>(
- reader_r->getAttribute("package").asString()));
-
- // size of ??
- _patchrpm->archiveSize = str::strtonum<ByteCount::SizeType>(
- reader_r->getAttribute("archive").asString());
-
- return true;
- }
-
- // xpath: /patch/atoms/package/patchrpm/base-version (+)
- if (reader_r->name() == "base-version")
- {
- data::BaseVersion_Ptr base_ptr = new data::BaseVersion;
-
- // size of the rpm file
- base_ptr->edition = Edition(reader_r->getAttribute("ver").asString(),
- reader_r->getAttribute("rel").asString(),
- reader_r->getAttribute("epoch").asString());
-
- _patchrpm->baseVersions.insert(base_ptr);
- return true;
- }
- }
-
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /patch/atoms/package/pkgfiles/patchrpm
- if (reader_r->name() == "patchrpm")
- {
- return false;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- bool PatchFileReader::Impl::consumeDeltarpmNode(Reader & reader_r)
- {
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /patch/atoms/package/deltarpm/location
- if (reader_r->name() == "location")
- {
- _deltarpm->location.setLocation(reader_r->getAttribute("href").asString(), 1);
- // ignoring attribute 'base'
- return true;
- }
-
- // xpath: /patch/atoms/package/deltarpm/checksum
- if (reader_r->name() == "checksum")
- {
- _deltarpm->location.setChecksum(CheckSum(
- reader_r->getAttribute("type").asString(),
- reader_r.nodeText().asString()));
- return true;
- }
-
- // xpath: /patch/atoms/package/deltarpm/time
- if (reader_r->name() == "time")
- {
- _deltarpm->buildTime =
- Date(reader_r->getAttribute("build").asString());
-
- _deltarpm->fileTime =
- Date(reader_r->getAttribute("file").asString());
-
- return true;
- }
-
- // xpath: /patch/atoms/package/deltarpm/size
- if (reader_r->name() == "size")
- {
- // size of the rpm file
- _deltarpm->location.setDownloadSize(str::strtonum<ByteCount::SizeType>(
- reader_r->getAttribute("package").asString()));
-
- // size of ??
- _deltarpm->archiveSize = str::strtonum<ByteCount::SizeType>(
- reader_r->getAttribute("archive").asString());
-
- return true;
- }
-
- // xpath: /patch/atoms/package/deltarpm/base-version
- if (reader_r->name() == "base-version")
- {
- // size of the rpm file
- _deltarpm->baseVersion.edition = Edition(reader_r->getAttribute("ver").asString(),
- reader_r->getAttribute("rel").asString(),
- reader_r->getAttribute("epoch").asString());
- // checksum
- _deltarpm->baseVersion.checkSum =
- CheckSum("md5", reader_r->getAttribute("md5sum").asString());
-
- // build time
- _deltarpm->baseVersion.buildTime =
- Date(reader_r->getAttribute("buildtime").asString());
-
- // sequence info
- _deltarpm->baseVersion.sequenceInfo =
- reader_r->getAttribute("sequence_info").asString();
-
- return true;
- }
- }
-
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /patch/atoms/package/pkgfiles/deltarpm
- if (reader_r->name() == "deltarpm")
- {
- return false;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- bool PatchFileReader::Impl::consumeMessageNode(Reader & reader_r)
- {
- if (consumeDependency(reader_r, _tmpResObj->deps))
- return true;
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /patch/atoms/message/yum:name
- if (reader_r->name() == "yum:name")
- {
- _tmpResObj->name = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: /patch/atoms/message/yum:name
- if (reader_r->name() == "yum:version")
- {
- editionStringFromAttrs( reader_r, _tmpResObj->edition );
- return true;
- }
-
- // xpath: /patch/atoms/message//text
- if (reader_r->name() == "text")
- {
- data::Message_Ptr message = dynamic_pointer_cast<data::Message>(_tmpResObj);
- if (message)
- message->text.setText(
- reader_r.nodeText().asString(),
- Locale(reader_r->getAttribute("lang").asString()));
- return true;
- }
- }
-
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /patch/atoms/message
- if (reader_r->name() == "message")
- {
- return false;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- bool PatchFileReader::Impl::consumeScriptNode(Reader & reader_r)
- {
- if (consumeDependency(reader_r, _tmpResObj->deps))
- return true;
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- data::Script_Ptr script = dynamic_pointer_cast<data::Script>(_tmpResObj);
- if (!script)
- {
- WAR << "data::Script object expected, but not found" << endl;
- return true;
- }
-
- // xpath: /patch/atoms/script/yum:name
- if (reader_r->name() == "yum:name")
- {
- _tmpResObj->name = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: /patch/atoms/script/yum:version
- if (reader_r->name() == "yum:version")
- {
- editionStringFromAttrs( reader_r, _tmpResObj->edition );
- return true;
- }
-
- // xpath: /patch/atoms/script/do
- if (reader_r->name() == "do")
- {
- script->doScript = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: /patch/atoms/script/undo
- if (reader_r->name() == "undo")
- {
- script->undoScript = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: /patch/atoms/script/do-location
- if (reader_r->name() == "do-location")
- {
- // xsd:anyURI do script file path base (not used)
- // ignoring reader_r->getAttribute("xml:base").asString();
-
- // xsd:anyURI do script file path
- script->doScriptLocation.setLocation(reader_r->getAttribute("href").asString(), 1);
- return true;
- }
-
- // xpath: /patch/atoms/script/do-checksum
- if (reader_r->name() == "do-checksum")
- {
- script->doScriptLocation.setChecksum(CheckSum(
- reader_r->getAttribute("type").asString(),
- reader_r.nodeText().asString()));
- return true;
- }
-
- // xpath: /patch/atoms/script/undo-location
- if (reader_r->name() == "undo-location")
- {
- // xsd:anyURI undo script file path base (not used)
- // ignoring reader_r->getAttribute("xml:base").asString();
-
- // xsd:anyURI undo script file path
- script->undoScriptLocation.setLocation(reader_r->getAttribute("href").asString(), 1);
- return true;
- }
-
- // xpath: /patch/atoms/script/undo-checksum
- if (reader_r->name() == "undo-checksum")
- {
- script->undoScriptLocation.setChecksum(CheckSum(
- reader_r->getAttribute("type").asString(),
- reader_r.nodeText().asString()));
- return true;
- }
- }
-
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /patch/atoms/script
- if (reader_r->name() == "script")
- {
- return false;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- data::Patch_Ptr PatchFileReader::Impl::handoutPatch()
- {
- data::Patch_Ptr ret;
- ret.swap(_patch);
- return ret;
- }
-
- // --------------------------------------------------------------------------
-
- void PatchFileReader::Impl::saveAtomInPatch()
- {
- data::ResObject_Ptr tmp;
- tmp.swap(_tmpResObj);
- _patch->atoms.insert(tmp);
- }
-
-
- ///////////////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PatchFileReader::Impl
- //
- ///////////////////////////////////////////////////////////////////////////
-
- PatchFileReader::PatchFileReader(const Pathname & patch_file, ProcessPatch callback)
- : _pimpl(new PatchFileReader::Impl(patch_file, callback))
- {}
-
- PatchFileReader::~PatchFileReader()
- {}
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/PatchFileReader.h
- * Interface definition of patch XML file reader.
- */
-#ifndef PATCHFILEREADER_H_
-#define PATCHFILEREADER_H_
-
-#include "zypp/base/Function.h"
-#include "zypp/parser/yum/FileReaderBase.h"
-
-namespace zypp
-{
-
- namespace data
- {
- class Patch;
- DEFINE_PTR_TYPE(Patch);
- } // ns data
-
-
- namespace parser
- {
- namespace yum
- {
-
-
- /**
- * Reader of patch.xml files conforming to schema definition located
- * at zypp/parser/yum/schema/patch.rnc.
- *
- * \see zypp::data::Patch
- * \see zypp::parser::xml::Reader
- */
- class PatchFileReader : FileReaderBase
- {
- public:
-
- /**
- * Consumer callback definition. Function which will process the read
- * data must be of this type.
- */
- typedef function<bool(const data::Patch_Ptr &)> ProcessPatch;
-
- /**
- * CTOR. Creates also \ref xml::Reader and starts reading.
- *
- * \param patch_file patch.xml file to read.
- * \param callback Function which will process read data.
- */
- PatchFileReader(const Pathname & patch_file, ProcessPatch callback);
-
- /**
- * DTOR.
- */
- ~PatchFileReader();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- };
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-#endif /*PATCHFILEREADER_H_*/
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/PatternFileReader.cc
- * Implementation of patterns.xml file reader.
- */
-#include "zypp/base/Logger.h"
-#include "zypp/data/ResolvableData.h"
-#include "zypp/parser/xml/Reader.h"
-
-#include "zypp/parser/yum/FileReaderBaseImpl.h"
-#include "zypp/parser/yum/PatternFileReader.h"
-
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
-
-using namespace std;
-using namespace zypp::xml;
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- ///////////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PatternFileReader::Impl
- //
- class PatternFileReader::Impl : public BaseImpl
- {
- public:
- Impl(const Pathname & pattern_file,
- const ProcessPattern & callback);
-
- /**
- * Callback provided to the XML reader.
- *
- * \param the xml reader object reading the file
- * \return true to tell the reader to continue, false to tell it to stop
- *
- * \see PrimaryFileReader::consumeNode(xml::Reader)
- */
- bool consumeNode(xml::Reader & reader_r);
-
- /**
- * Creates a new \ref data::Pattern_Ptr, swaps its contents with \ref _pattern
- * and returns it. Used to hand-out the data object to its consumer
- * (a \ref ProcessPattern function) after it has been read.
- */
- data::Pattern_Ptr handoutPattern();
-
- private:
- /**
- * Callback for processing pattern metadata.
- */
- ProcessPattern _callback;
-
- /**
- * Pointer to the \ref zypp::data::Pattern object for storing the pattern
- * metada.
- */
- data::Pattern_Ptr _pattern;
- };
- //////////////////////////////////////////////////////////////////////////
-
- PatternFileReader::Impl::Impl(
- const Pathname & pattern_file,
- const ProcessPattern & callback)
- :
- _callback(callback)
- {
- Reader reader(pattern_file);
- MIL << "Reading " << pattern_file << endl;
- reader.foreachNode(bind(&PatternFileReader::Impl::consumeNode, this, _1));
- }
-
- // --------------------------------------------------------------------------
-
- /*
- * xpath and multiplicity of processed nodes are included in the code
- * for convenience:
- *
- * // xpath: <xpath> (?|*|+)
- *
- * if multiplicity is ommited, then the node has multiplicity 'one'.
- */
-
- // --------------------------------------------------------------------------
-
- bool PatternFileReader::Impl::consumeNode(Reader & reader_r)
- {
- // dependency block nodes
- if (consumeDependency(reader_r, _pattern->deps))
- return true;
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /patterns/pattern
- if (reader_r->name() == "pattern")
- {
- tag(tag_pattern); // just for the case of reuse somewhere/sometimes
- _pattern = new data::Pattern;
- return true;
- }
-
- // xpath: /patterns/pattern/name
- if (reader_r->name() == "name")
- {
- _pattern->name = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: /patterns/pattern/summary (+)
- if (reader_r->name() == "summary")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- _pattern->summary.setText(reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: /patterns/pattern/description (+)
- if (reader_r->name() == "description")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- _pattern->description.setText(reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: /patterns/pattern/default (?)
- if (reader_r->name() == "default")
- {
- _pattern->isDefault = true;
- }
-
- // xpath: /patterns/pattern/uservisible (?)
- if (reader_r->name() == "uservisible")
- {
- _pattern->userVisible = true;
- return true;
- }
-
- // xpath: /patterns/pattern/category
- if (reader_r->name() == "category")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- _pattern->category.setText(reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: /patterns/pattern/icon (?)
- if (reader_r->name() == "icon")
- {
- _pattern->icon = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: /patterns/pattern/script (?)
- if (reader_r->name() == "script")
- {
- _pattern->script = reader_r.nodeText().asString();
- return true;
- }
- }
-
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /patterns/pattern
- if (reader_r->name() == "pattern")
- {
- if (_callback)
- _callback(handoutPattern());
-
- toParentTag(); // just for the case of reuse somewhere/sometimes
-
- return true;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- data::Pattern_Ptr PatternFileReader::Impl::handoutPattern()
- {
- data::Pattern_Ptr ret;
- ret.swap(_pattern);
- return ret;
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PatternFileReader
- //
- ///////////////////////////////////////////////////////////////////
-
- PatternFileReader::PatternFileReader(const Pathname & pattern_file, ProcessPattern callback)
- : _pimpl(new PatternFileReader::Impl(pattern_file, callback))
- {}
-
-
- PatternFileReader::~PatternFileReader()
- {}
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/PatternFileReader.h
- * Interface of patterns.xml file reader.
- */
-#ifndef ZYPP_PARSER_YUM_PATTERNFILEREADER_H_
-#define ZYPP_PARSER_YUM_PATTERNFILEREADER_H_
-
-#include "zypp/parser/yum/FileReaderBase.h"
-
-namespace zypp
-{
-
- namespace data
- {
- class Pattern;
- DEFINE_PTR_TYPE(Pattern);
- } // ns data
-
-
- namespace parser
- {
- namespace yum
- {
-
-
- /**
- * Reader of patterns.xml file conforming to schema definition located
- * at zypp/parser/yum/schema/patterns.rnc.
- *
- * \see zypp::data::Pattern
- * \see zypp::parser::xml::Reader
- */
- class PatternFileReader : FileReaderBase
- {
- public:
-
- /**
- * Consumer callback definition. Function which will process the read
- * data must be of this type.
- */
- typedef function<bool(const data::Pattern_Ptr &)> ProcessPattern;
-
- /**
- * CTOR. Creates also \ref xml::Reader and starts reading.
- *
- * \param pattern_file pattern.xml file to read.
- * \param callback Function which will process read data.
- */
- PatternFileReader(const Pathname & pattern_file, ProcessPattern callback);
-
- /**
- * DTOR.
- */
- ~PatternFileReader();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- };
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-#endif /*ZYPP_PARSER_YUM_PATTERNFILEREADER_H_*/
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/PrimaryFileReader.cc
- * Implementation of primary.xml.gz file reader.
- */
-#include "zypp/base/Logger.h"
-#include "zypp/ZConfig.h"
-
-#include "zypp/parser/xml/Reader.h"
-#include "zypp/data/ResolvableData.h"
-#include "zypp/base/UserRequestException.h"
-
-#include "zypp/parser/yum/FileReaderBaseImpl.h"
-#include "zypp/parser/yum/PrimaryFileReader.h"
-
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
-
-using namespace std;
-using namespace zypp::xml;
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- ///////////////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PrimaryFileReader::Impl
- //
- class PrimaryFileReader::Impl : public BaseImpl
- {
- public:
- /** CTOR */
- Impl(const Pathname & primary_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress);
-
- /**
- * Callback provided to the XML reader.
- *
- * This is the main parsing method which gets envoked by the \ref xml::Reader
- * to process each node, one at a time. It is responsible for parsing the
- * node and calling all other consume* methods.
- *
- * \param the xml reader object reading the file
- * \return true to tell the reader to continue, false to tell it to stop
- * \throws AbortRequestException if user request for aborting the parsing
- * has been received through progress reporting callback.
- *
- * \note Semantics of this method's return value also differs from other
- * consume* methods. While this method's return value tells the the
- * xml reader to continue or stop, return value of the rest tells
- * their callers if further
- */
- bool consumeNode(xml::Reader & reader_r);
-
- private:
- /**
- * Creates a new \ref data::Package_Ptr, swaps its contents with \ref
- * _package and returns it. Used to hand-out the data object to its consumer
- * (a \ref ProcessPackage function) after it has been read.
- */
- data::Packagebase_Ptr handoutPackage();
-
- private:
- /**
- * Callback for processing package metadata passed in through constructor.
- */
- ProcessPackage _callback;
-
- /**
- * \ref zypp::data::Packagebase object for storing the package metada.
- * This can be either a data::Package or data::SrcPackage
- */
- data::Packagebase_Ptr _package;
-
- /**
- * Progress reporting object.
- */
- ProgressData _ticks;
-
- /**
- * system architecture, to filter out incompatible packages
- */
- Arch _sysarch;
- };
- ///////////////////////////////////////////////////////////////////////////
-
-
- PrimaryFileReader::Impl::Impl(
- const Pathname & primary_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress)
- :
- _callback(callback)
- , _sysarch( ZConfig::instance().systemArchitecture() )
- {
- _ticks.sendTo(progress);
-
- Reader reader(primary_file);
- MIL << "Reading " << primary_file << endl;
- reader.foreachNode(bind( &PrimaryFileReader::Impl::consumeNode, this, _1 ));
- }
-
- // --------------------------------------------------------------------------
-
- bool PrimaryFileReader::Impl::consumeNode(Reader & reader_r)
- {
-// DBG << "**node: " << reader_r->name() << " (" << reader_r->nodeType() << ")" << endl;
- if (isBeingProcessed(tag_package) && consumePackageNode(reader_r, _package))
- return true;
-
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /metadata
- if (reader_r->name() == "metadata")
- {
- unsigned total_packages;
- zypp::str::strtonum(reader_r->getAttribute("packages").asString(), total_packages);
- _ticks.range(total_packages);
- _ticks.toMin();
- return true;
- }
-
- // xpath: /metadata/package (+)
- if (reader_r->name() == "package")
- {
- tag(tag_package);
- // DBG << "got " << reader_r->getAttribute("type") << " package" << endl;
- _package = new data::Package;
-
- return consumePackageNode(reader_r, _package);
- }
- }
-
- else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
- {
- // xpath: /metadata/package (+)
- if (reader_r->name() == "package")
- {
- if (_package && _callback
- && Arch(_package->arch).compatibleWith( _sysarch ))
- {
- _callback(handoutPackage());
- }
- if (!_ticks.incr())
- ZYPP_THROW(AbortRequestException());
-
- toParentTag();
- return true;
- }
-
- // xpath: /metdata
- if (reader_r->name() == "metadata")
- {
- _ticks.toMax();
- return true;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- data::Packagebase_Ptr PrimaryFileReader::Impl::handoutPackage()
- {
- data::Packagebase_Ptr ret;
- ret.swap(_package);
- return ret;
- }
-
- ///////////////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : PrimaryFileReader
- //
- ///////////////////////////////////////////////////////////////////////////
-
- PrimaryFileReader::PrimaryFileReader(
- const Pathname & primary_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress)
- : _pimpl(new PrimaryFileReader::Impl(primary_file, callback, progress))
- {}
-
-
- PrimaryFileReader::~PrimaryFileReader()
- {}
-
-
- } // ns yum
- } // ns parser
-} //ns zypp
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/PrimaryFileReader.h
- * Interface definition of primary.xml.gz file reader.
- */
-#ifndef ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H
-#define ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H
-
-#include "zypp/ProgressData.h"
-
-#include "zypp/parser/yum/FileReaderBase.h"
-
-namespace zypp
-{
-
- namespace data
- {
- class Packagebase;
- DEFINE_PTR_TYPE(Packagebase);
- } // ns data
-
-
- namespace parser
- {
- namespace yum
- {
-
- /**
- * Reads through a primary.xml.gz file and collects package data including
- * dependencies.
- *
- * After a package is read, a \ref zypp::data::Package object is prepared
- * and \ref _callback is called with this object passed in.
- *
- * The \ref _callback is provided on construction.
- *
- * \code
- * PrimaryFileReader reader(repomd_file,
- * bind(&SomeClass::callbackfunc, &object, _1));
- * \endcode
- */
- class PrimaryFileReader : public FileReaderBase
- {
- public:
- /**
- * Callback definition.
- */
- typedef function<bool(const data::Packagebase_Ptr &)> ProcessPackage;
-
- /**
- * CTOR. Creates also \ref xml::Reader and starts reading.
- *
- * \param primary_file the primary.xml.gz file you want to read
- * \param callback function to process \ref _package data.
- * \param progress progress reporting function
- * \throws AbortRequestException if user request for aborting the parsing
- * has been received through progress reporting callback.
- *
- * \see PrimaryFileReader::ProcessPackage
- */
- PrimaryFileReader(
- const Pathname & primary_file,
- const ProcessPackage & callback,
- const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc());
-
- /**
- * DTOR.
- */
- ~PrimaryFileReader();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- };
-
-
- } // ns zypp
- } // ns parser
-} // ns yum
-
-#endif /* ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H */
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-
-#include "zypp/base/Logger.h"
-#include "zypp/parser/xml/Reader.h"
-#include "zypp/data/ResolvableData.h"
-#include "zypp/ZConfig.h"
-
-#include "zypp/parser/yum/FileReaderBaseImpl.h"
-#include "zypp/parser/yum/ProductFileReader.h"
-
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
-
-using namespace std;
-using namespace zypp::xml;
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : ProductFileReader::Impl
- //
- class ProductFileReader::Impl : public BaseImpl
- {
- public:
- Impl(const Pathname & products_file,
- const ProcessProduct & callback);
-
- /**
- * Callback provided to the XML reader.
- *
- * \param the xml reader object reading the file
- * \return true to tell the reader to continue, false to tell it to stop
- *
- * \see PrimaryFileReader::consumeNode(xml::Reader)
- */
- bool consumeNode(xml::Reader & reader_r);
-
- /**
- * Creates a new \ref data::Product_Ptr, swaps its contents with \ref _product
- * and returns it. Used to hand-out the data object to its consumer
- * (a \ref ProcessProduct function) after it has been read.
- */
- data::Product_Ptr handoutProduct();
-
- private:
- /**
- * Callback for processing product metadata.
- */
- ProcessProduct _callback;
-
- /**
- * Pointer to the \ref zypp::data::Product object for storing the product
- * metada.
- */
- data::Product_Ptr _product;
- };
- ///////////////////////////////////////////////////////////////////
-
- ProductFileReader::Impl::Impl(
- const Pathname & products_file,
- const ProcessProduct & callback)
- :
- _callback(callback)
- {
- Reader reader(products_file);
- MIL << "Reading " << products_file << endl;
- reader.foreachNode(bind(&ProductFileReader::Impl::consumeNode, this, _1));
- }
-
- // --------------------------------------------------------------------------
-
- /*
- * xpath and multiplicity of processed nodes are included in the code
- * for convenience:
- *
- * // xpath: <xpath> (?|*|+)
- *
- * if multiplicity is ommited, then the node has multiplicity 'one'.
- */
-
- // --------------------------------------------------------------------------
-
- bool ProductFileReader::Impl::consumeNode(Reader & reader_r)
- {
- // dependency block nodes
- if (_product && consumeDependency(reader_r, _product->deps))
- return true;
-
- if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
- {
- // xpath: /products/product
- if (reader_r->name() == "product")
- {
- tag(tag_product); // just for the case of reuse somewhere/sometimes
- _product = new data::Product;
- return true;
- }
-
- // xpath: /products/product/name
- if (reader_r->name() == "name")
- {
- _product->name = reader_r.nodeText().asString();
- // product type (base, add-on)
- _product->type = reader_r->getAttribute("type").asString();
- return true;
- }
-
- // xpath: /products/product/vendor
- if (reader_r->name() == "vendor")
- {
- _product->vendor = reader_r.nodeText().asString();
- }
-
- // xpath: /products/product/version
- if (reader_r->name() == "version")
- {
- editionStringFromAttrs( reader_r, _product->edition );
- }
-
- // xpath: /products/product/displayname (+)
- if (reader_r->name() == "displayname")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- _product->longName.setText(reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: /products/product/shortname (*)
- if (reader_r->name() == "shortname")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- _product->shortName.setText(reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: /products/product/description (+)
- if (reader_r->name() == "description")
- {
- Locale locale(reader_r->getAttribute("lang").asString());
- _product->description.setText(reader_r.nodeText().asString(), locale);
- return true;
- }
-
- // xpath: /products/product/distribution-name (+)
- if (reader_r->name() == "distribution-name")
- {
- _product->distributionName = reader_r.nodeText().asString();
- return true;
- }
-
- // xpath: /products/product/distribution-edition (+)
- if (reader_r->name() == "distribution-edition")
- {
- _product->distributionEdition = Edition( reader_r.nodeText().asString() );
- return true;
- }
-
- // xpath: /products/product/release-notes-url (+)
- if (reader_r->name() == "release-notes-url")
- {
- string value = reader_r.nodeText().asString();
-
- for( std::string::size_type pos = value.find("%a");
- pos != std::string::npos;
- pos = value.find("%a") )
- {
- value.replace( pos, 2, ZConfig::instance().systemArchitecture().asString() );
- }
- try
- {
- _product->releasenotesUrl = value;
- }
- catch( const Exception & excpt_r )
- {
- WAR << "Malformed url ignored: '" << value << "' " << excpt_r.asString() << endl;
- }
- return true;
- }
-
- // xpath: /products/product/update-url (*)
- if (reader_r->name() == "update-url")
- {
- string value = reader_r.nodeText().asString();
-
- try
- {
- _product->updateUrls.push_back(Url(value));
- }
- catch( const Exception & excpt_r )
- {
- WAR << "Malformed url ignored: '" << value << "' " << excpt_r.asString() << endl;
- }
- return true;
- }
-
- // xpath: /products/product/extra-url (*)
- if (reader_r->name() == "extra-url")
- {
- string value = reader_r.nodeText().asString();
-
- try
- {
- _product->extraUrls.push_back(Url(value));
- }
- catch( const Exception & excpt_r )
- {
- WAR << "Malformed url ignored: '" << value << "' " << excpt_r.asString() << endl;
- }
- return true;
- }
-
- // xpath: /products/product/optional-url (*)
- if (reader_r->name() == "optional-url")
- {
- string value = reader_r.nodeText().asString();
-
- try
- {
- _product->optionalUrls.push_back(Url(value));
- }
- catch( const Exception & excpt_r )
- {
- WAR << "Malformed url ignored: '" << value << "' " << excpt_r.asString() << endl;
- }
- return true;
- }
- }
-
- else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
- {
- // xpath: /products/product
- if (reader_r->name() == "product")
- {
- if (_callback)
- _callback(handoutProduct());
-
- toParentTag(); // just for the case of reuse somewhere/sometimes
-
- return true;
- }
- }
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- data::Product_Ptr ProductFileReader::Impl::handoutProduct()
- {
- data::Product_Ptr ret;
- ret.swap(_product);
- return ret;
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : ProductFileReader
- //
- ///////////////////////////////////////////////////////////////////
-
- ProductFileReader::ProductFileReader(const Pathname & product_file, ProcessProduct callback)
- : _pimpl(new ProductFileReader::Impl(product_file, callback))
- {}
-
-
- ProductFileReader::~ProductFileReader()
- {}
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-
-#ifndef ZYPP_PARSER_YUM_PRODUCTFILEREADER_H_
-#define ZYPP_PARSER_YUM_PRODUCTFILEREADER_H_
-
-#include "zypp/parser/yum/FileReaderBase.h"
-
-namespace zypp
-{
-
- namespace data
- {
- class Product;
- DEFINE_PTR_TYPE(Product);
- } // ns data
-
-
- namespace parser
- {
- namespace yum
- {
-
-
- /**
- * Reader of products.xml file conforming to RNC definition located
- * at zypp/parser/yum/schema/products.rnc.
- *
- * \see zypp::data::Product
- * \see zypp::parser::xml::Reader
- */
- class ProductFileReader : FileReaderBase
- {
- public:
-
- /**
- * Consumer callback definition. Function which will process the read
- * data must be of this type.
- */
- typedef function<bool(const data::Product_Ptr &)> ProcessProduct;
-
- /**
- * CTOR. Creates also \ref xml::Reader and starts reading.
- *
- * \param products_file products.xml file to read.
- * \param callback Function which will process read data.
- */
- ProductFileReader(const Pathname & products_file, ProcessProduct callback);
-
- /**
- * DTOR.
- */
- ~ProductFileReader();
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- };
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-#endif /*ZYPP_PARSER_YUM_PRODUCTFILEREADER_H_*/
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/RepoParser.cc
- * YUM repository metadata parser implementation.
- */
-#include <iostream>
-
-#include "zypp/ZConfig.h"
-#include "zypp/base/Logger.h"
-#include "zypp/PathInfo.h"
-#include "zypp/base/UserRequestException.h"
-#include "zypp/repo/yum/ResourceType.h"
-#include "zypp/data/ResolvableData.h"
-
-#include "zypp/parser/yum/RepomdFileReader.h"
-#include "zypp/parser/yum/PrimaryFileReader.h"
-#include "zypp/parser/yum/PatchesFileReader.h"
-#include "zypp/parser/yum/PatchFileReader.h"
-#include "zypp/parser/yum/PatternFileReader.h"
-#include "zypp/parser/yum/ProductFileReader.h"
-#include "zypp/parser/yum/OtherFileReader.h"
-#include "zypp/parser/yum/FilelistsFileReader.h"
-
-#include "zypp/parser/yum/RepoParser.h"
-
-
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
-
-using namespace std;
-using zypp::repo::yum::ResourceType;
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
- /**
- * Structure encapsulating YUM parser data type and filename.
- */
- struct RepoParserJob
- {
- RepoParserJob(const Pathname & filename, const ResourceType & type)
- : _filename(filename), _type(type) {}
-
- const Pathname & filename() const { return _filename; }
- const ResourceType & type() const { return _type; }
-
- private:
- /** File to be processed */
- Pathname _filename;
- /** Type of YUM file */
- ResourceType _type;
- };
-
-
- ///////////////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : RepoParser::Impl
- //
- class RepoParser::Impl : private base::NonCopyable
- {
- public:
- /** CTOR */
- Impl(
- const std::string &repo_id,
- data::ResolvableDataConsumer & consumer,
- const RepoParserOpts & options = RepoParserOpts(),
- const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc()
- );
-
- /** Implementation of \ref RepoParser::parse(Pathname) */
- void parse(const Pathname &cache_dir);
-
- /**
- * Iterates through parser \ref _jobs and executes them using
- * *FileReader classes.
- *
- * \param path location of the raw repository cache
- */
- void doJobs(const Pathname & path);
-
- /**
- * Callback for processing data returned from \ref RepomdFileReader.
- * Adds returned files to parser job list (\ref _jobs).
- *
- * \param loc location of discovered data file
- * \param dtype YUM data type
- */
- bool repomd_CB(const OnMediaLocation & loc, const ResourceType & dtype);
-
- /**
- * Callback for processing packages returned from \ref PrimaryFileReader.
- * Uses \ref _consumer to process read package data.
- *
- * \param package_r pointer to package data
- */
- bool primary_CB(const data::Packagebase_Ptr & package_r);
-
- /**
- * Callback for processing data returned from \ref PatchesFileReader.
- * Adds discovered patch*.xml files to parser \ref _jobs.
- *
- * \param loc location of discovered patch file
- * \param patch_id (not used so far)
- */
- bool patches_CB(const OnMediaLocation &loc, const std::string & patch_id);
-
- /**
- * Callback for processing data returned from \ref PatchFileReader.
- * Uses \ref _consumer to process read patch data.
- *
- * \param patch pointer to patch data
- */
- bool patch_CB(const data::Patch_Ptr & patch);
-
- /**
- * Callback for processing data returned from \ref OtherFileReader.
- * Uses \ref _consumer to process read changelog data.
- *
- * \param res_ptr resolvable to which the changelog belongs
- * \param changelog read changelog
- */
- bool other_CB(const data::Resolvable_Ptr & res_ptr, const Changelog & changelog);
-
- /**
- * Callback for processing data returned from \ref FilelistsFileReader.
- * Uses \ref _consumer to process read filelist.
- *
- * \param res_ptr resolvable to which the filelist belongs.
- * \param filenames the read filelist
- */
- bool filelist_CB(const data::Resolvable_Ptr & res_ptr, const data::Filenames & filenames);
-
- /**
- * Callback for processing data returned from \ref PatternFileReader.
- * Uses \ref _consumer to process read pattern.
- *
- * \param pattern_ptr pointer to pattern data object
- */
- bool pattern_CB(const data::Pattern_Ptr & pattern_ptr);
-
- /**
- * Callback for processing data returned from \ref ProductFileReader.
- * Uses \ref _consumer to process read product.
- *
- * \param product_ptr pointer to product data object
- */
- bool product_CB(const data::Product_Ptr & product_ptr);
-
- private:
- /** ID of the repository record in the DB (repositories.id) */
- string _repository_id;
-
- /** Object for processing the read data */
- data::ResolvableDataConsumer & _consumer;
-
- /** List of parser jobs read from repomd.xml and patches.xml files. */
- std::list<RepoParserJob> _jobs;
-
- /** Progress reporting object for overall YUM parser progress. */
- ProgressData _ticks;
-
- /** */
- const RepoParserOpts & _options;
- };
- ///////////////////////////////////////////////////////////////////////////
-
-
- RepoParser::Impl::Impl(
- const std::string & repository_id,
- data::ResolvableDataConsumer & consumer,
- const RepoParserOpts & options,
- const ProgressData::ReceiverFnc & progress)
- :
- _repository_id(repository_id), _consumer(consumer), _options(options)
- {
- _ticks.name("YUM RepoParser");
- _ticks.sendTo(progress);
- }
-
- // -------------------------------------------------------------------------
-
- bool RepoParser::Impl::repomd_CB(
- const OnMediaLocation & loc, const ResourceType & dtype)
- {
- DBG << "Adding " << dtype
- << " (" << loc.filename() << ") to RepoParser jobs " << endl;
-
- _jobs.push_back(RepoParserJob(loc.filename(), dtype));
-
- return true;
- }
-
- // -------------------------------------------------------------------------
-
- bool RepoParser::Impl::primary_CB(const data::Packagebase_Ptr & package_r)
- {
- data::Package_Ptr pkg = dynamic_pointer_cast<data::Package>(package_r);
- if (pkg)
- _consumer.consumePackage(pkg);
- else
- _consumer.consumeSourcePackage(dynamic_pointer_cast<data::SrcPackage>(package_r));
-
-/* MIL << "got package "
- << package.name << package.edition << " "
- << package.arch
- << endl;
- MIL << "checksum: " << package.checksum << endl;
- MIL << "summary: " << package.summary << endl;*/
-
- return true;
- }
-
- // -------------------------------------------------------------------------
-
- bool RepoParser::Impl::patches_CB(
- const OnMediaLocation & loc, const string & patch_id)
- {
- DBG << "Adding patch " << loc.filename() << " to RepoParser jobs " << endl;
-
- _jobs.push_back(RepoParserJob(loc.filename(), ResourceType::PATCH));
-
- return true;
- }
-
- // -------------------------------------------------------------------------
-
- bool RepoParser::Impl::patch_CB(const data::Patch_Ptr & patch)
- {
- _consumer.consumePatch( patch );
-
- MIL << "got patch "
- << patch->name << patch->edition << " "
- << patch->arch
- << endl;
-
- return true;
- }
-
- // -------------------------------------------------------------------------
-
- bool RepoParser::Impl::other_CB(
- const data::Resolvable_Ptr & res_ptr, const Changelog & changelog)
- {
- //_consumer.consumeChangelog(_repository_id, res_ptr, changelog);
-/*
- DBG << "got changelog for "
- << res_ptr->name << res_ptr->edition << " "
- << res_ptr->arch
- << endl;
-
- DBG << "last entry: " << changelog.front() << endl;
-*/
- return true;
- }
-
- // -------------------------------------------------------------------------
-
- bool RepoParser::Impl::filelist_CB(
- const data::Resolvable_Ptr & res_ptr, const data::Filenames & filenames)
- {
- //_consumer.consumeFilelist(_repository_id, res_ptr, filenames);
-/*
- DBG << "got filelist for "
- << res_ptr->name << res_ptr->edition << " "
- << res_ptr->arch
- << endl;
-
- DBG << "last entry: " << filenames.front() << endl;
-*/
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- bool RepoParser::Impl::pattern_CB(const data::Pattern_Ptr & product_ptr)
- {
- _consumer.consumePattern(product_ptr);
-
- MIL << "got pattern " << product_ptr->name << endl;
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- bool RepoParser::Impl::product_CB(const data::Product_Ptr & product_ptr)
- {
- _consumer.consumeProduct(product_ptr);
-
- MIL << "got product " << product_ptr->name
- << "-" << product_ptr->edition << endl;
-
- return true;
- }
-
- // --------------------------------------------------------------------------
-
- void RepoParser::Impl::parse(const Pathname &cache_dir)
- {
- zypp::parser::yum::RepomdFileReader(
- cache_dir + "/repodata/repomd.xml",
- bind(&RepoParser::Impl::repomd_CB, this, _1, _2));
-
- long long totalsize = 0;
- for(list<RepoParserJob>::const_iterator it = _jobs.begin();
- it != _jobs.end(); ++it)
- {
- RepoParserJob job = *it;
- totalsize += PathInfo(cache_dir + job.filename()).size();
- }
-
- MIL << "Total files size: " << totalsize << endl;
- _ticks.range(totalsize);
- _ticks.toMin();
-
- doJobs(cache_dir);
-
- _ticks.toMax();
- }
-
- // --------------------------------------------------------------------------
-
- void RepoParser::Impl::doJobs(const Pathname &cache_dir)
- {
- for(list<RepoParserJob>::const_iterator it = _jobs.begin();
- it != _jobs.end(); ++it)
- {
- RepoParserJob job = *it;
- // FIXME better way to do progress here?
- int jobsize = PathInfo(cache_dir + job.filename()).size();
-
- MIL << "going to parse " << job.type() << " file "
- << job.filename() << " (" << jobsize << " bytes)" << endl;
-
- switch(job.type().toEnum())
- {
- // parse primary.xml.gz
- case ResourceType::PRIMARY_e:
- {
- CombinedProgressData jobrcv( _ticks, jobsize );
- PrimaryFileReader(
- cache_dir + job.filename(),
- bind(&RepoParser::Impl::primary_CB, this, _1),
- jobrcv);
- break;
- }
-
- case ResourceType::PATCHES_e:
- {
- PatchesFileReader(
- cache_dir + job.filename(),
- bind(&RepoParser::Impl::patches_CB, this, _1, _2));
- // reset progress reporter max value (number of jobs changed if
- // there are patches to parse)
- _ticks.range( _ticks.max() + jobsize );
- // increase in the total bytes of the file
- if (!_ticks.incr( jobsize ))
- ZYPP_THROW(AbortRequestException());
- break;
- }
-
- case ResourceType::PATCH_e:
- {
- PatchFileReader(
- cache_dir + job.filename(),
- bind(&RepoParser::Impl::patch_CB, this, _1));
- // increase in the total bytes of the file
- if (!_ticks.incr( jobsize ))
- ZYPP_THROW(AbortRequestException());
- break;
- }
-
- case ResourceType::OTHER_e:
- {
- if (!_options.skipOther)
- {
- CombinedProgressData jobrcv( _ticks, jobsize );
- OtherFileReader(
- cache_dir + job.filename(),
- bind(&RepoParser::Impl::other_CB, this, _1, _2),
- jobrcv);
- }
- else
- {
- MIL << "skipping other.xml.gz" << endl;
- // increase in the total bytes of the file
- if (!_ticks.incr( jobsize ))
- ZYPP_THROW(AbortRequestException());
- }
- break;
- }
-
- case ResourceType::FILELISTS_e:
- {
- if (!_options.skipFilelists)
- {
- CombinedProgressData jobrcv( _ticks, jobsize );
- FilelistsFileReader(
- cache_dir + job.filename(),
- bind(&RepoParser::Impl::filelist_CB, this, _1, _2),
- jobrcv);
- }
- else
- {
- MIL << "skipping filelists.xml.gz";
- // increase in the total bytes of the file
- if (!_ticks.incr( jobsize ))
- ZYPP_THROW(AbortRequestException());
- }
- break;
- }
-
- case ResourceType::PATTERNS_e:
- {
- PatternFileReader(
- cache_dir + job.filename(),
- bind(&RepoParser::Impl::pattern_CB, this, _1));
- // increase in the total bytes of the file
- if (!_ticks.incr( jobsize ))
- ZYPP_THROW(AbortRequestException());
- break;
- }
-
- case ResourceType::PRODUCT_e:
- {
- ProductFileReader(
- cache_dir + job.filename(),
- bind(&RepoParser::Impl::product_CB, this, _1));
- // increase in the total bytes of the file
- if (!_ticks.incr( jobsize ))
- ZYPP_THROW(AbortRequestException());
- break;
- }
-
- default:
- {
- WAR << "Don't know how to read "
- << job.type() << " file "
- << job.filename() << endl;
- }
- }
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS : RepoParser
- //
- ///////////////////////////////////////////////////////////////////
-
- RepoParser::RepoParser(
- const std::string & repository_id,
- data::ResolvableDataConsumer & consumer,
- const RepoParserOpts & options,
- const ProgressData::ReceiverFnc & progress)
- :
- _pimpl(new Impl(repository_id, consumer, options, progress))
- {}
-
-
- RepoParser::~RepoParser()
- {}
-
-
- void RepoParser::parse(const Pathname & cache_dir)
- {
- _pimpl->parse(cache_dir);
- }
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp2/parser/yum/RepoParser.h
- * YUM repository metadata parser public API definition.
- */
-#ifndef ZYPP_PARSER_YUM_REPOPARSER_H_
-#define ZYPP_PARSER_YUM_REPOPARSER_H_
-
-#include "zypp/base/PtrTypes.h"
-#include "zypp/base/NonCopyable.h"
-
-#include "zypp/data/RecordId.h"
-#include "zypp/data/ResolvableDataConsumer.h"
-
-#include "zypp/ProgressData.h"
-#include "zypp/parser/yum/RepoParserOpts.h"
-
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- /**
- * Main YUM repository metada parser.
- *
- * Reads repomd.xml file to get the list of files to parse and enques them
- * as RepoParserJobs. Then uses *FileReader classes to parse the files and
- * a \ref ResolvableDataConsumer to process the read data (typically to
- * store them in a database).
- *
- *
- * \code
- *
- * cache::CacheStore store(dbdir);
- * data::RecordId repository_id = store.lookupOrAppendRepository(sourceurl, "/");
- *
- * RepoParser parser(repository_id, store, &progress_function);
- * parser.parse(source_cache_dir);
- *
- * store.commit();
- *
- * \code
- *
- * \todo make the parser configurable, e.g. exclude(FILELISTS_e)?
- *
- * \see RepomdFileReader, PrimaryFileReader, OtherFileReader
- * \see FilelistsFileReader, PatchesFileReader, PatchFileReader
- * \see PatternFileReader, ProductFileReader
- */
- class RepoParser : private base::NonCopyable
- {
- public:
-
- /**
- * CTOR
- *
- * \param repository_id repository identifier
- * \param consumer consumer of parsed data
- * \param progress progress reporting function
- */
- RepoParser(
- const std::string &repo_id,
- data::ResolvableDataConsumer & consumer,
- const RepoParserOpts & options = RepoParserOpts(),
- const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc()
- );
-
- /**
- * DTOR
- */
- ~RepoParser();
-
- /**
- * Starts parsing of repository cache dir located at \a path.
- *
- * This method uses RepomdFileReader to get a list of parser jobs
- * and calls \ref Impl::doJobs(Pathname) to do them.
- *
- * \param path location of the raw repository cache
- */
- void parse(const Pathname & path);
-
- private:
- class Impl;
- RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
- };
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-#endif /*ZYPP_PARSER_YUM_REPOPARSER_H_*/
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-#ifndef ZYPP_PARSER_YUM_REPOPARSEROPTS_H_
-#define ZYPP_PARSER_YUM_REPOPARSEROPTS_H_
-
-#include "zypp/base/DefaultIntegral.h"
-
-namespace zypp
-{
- namespace parser
- {
- namespace yum
- {
-
-
- /** YUM parser options */
- struct RepoParserOpts
- {
- /** Skip parsing of other.xml.gz */
- DefaultIntegral<bool,true> skipOther;
-
- /** Skip parsing of filelists.xml.gz */
- DefaultIntegral<bool,true> skipFilelists;
- };
-
-
- } // ns yum
- } // ns parser
-} // ns zypp
-
-#endif /*ZYPP_PARSER_YUM_REPOPARSEROPTS_H_*/
-
-// vim: set ts=2 sts=2 sw=2 et ai:
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/parser/yum/schemanames.h
- *
-*/
-
-
-#ifndef schemanames_h
-#define schemanames_h
-
-namespace zypp
-{
-namespace parser
-{
-namespace yum
-{
-/* FIXME: How do I do this properly? */
-#define SCHEMABASE "/usr/share/zypp/schema/yum/"
-#define REPOMDSCHEMA (SCHEMABASE "repomd.rng")
-#define PRIMARYSCHEMA (SCHEMABASE "suse-primary.rng")
-#define GROUPSCHEMA (SCHEMABASE "groups.rng")
-#define PATTERNSCHEMA (SCHEMABASE "patterns.rng")
-#define FILELISTSCHEMA (SCHEMABASE "filelists.rng")
-#define OTHERSCHEMA (SCHEMABASE "other.rng")
-#define PATCHSCHEMA (SCHEMABASE "patch.rng")
-#define PATCHESSCHEMA (SCHEMABASE "patches.rng")
-#define PRODUCTSCHEMA (SCHEMABASE "product.rng")
-#define REPOINDEXSCHEMA (SCHEMABASE "product.rng")
-} // namespace yum
-} // namespace parser
-} // namespace zypp
-
-
-#endif