From: Michael Andres Date: Sun, 15 Jan 2006 20:55:18 +0000 (+0000) Subject: backup X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~3337 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f2f32773cfe485e7384da4f1f9551dc34b01e1a6;p=platform%2Fupstream%2Flibzypp.git backup --- diff --git a/configure.ac b/configure.ac index 9385ce7..7f917a9 100644 --- a/configure.ac +++ b/configure.ac @@ -196,6 +196,7 @@ AC_OUTPUT( \ zypp/solver/detail/Makefile \ zypp/solver/temporary/Makefile \ zypp/source/Makefile \ + zypp/source/susetags/Makefile \ zypp/source/yum/Makefile \ zypp/media/Makefile \ zypp/media/proxyinfo/Makefile \ diff --git a/devel/devel.ma/Parse.cc b/devel/devel.ma/Parse.cc index 6b6cf4e..fecfe3b 100644 --- a/devel/devel.ma/Parse.cc +++ b/devel/devel.ma/Parse.cc @@ -9,19 +9,32 @@ #include #include -#include -#include -#include -#include -#include - -#include +#include using std::endl; /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + // + // Just for the stats + // + //////////////////////////////////////////////////////////////////////////// + struct Measure + { + time_t _begin; + Measure() + : _begin( time(NULL) ) + { + USR << "START MEASURE..." << endl; + } + ~Measure() + { + USR << "DURATION: " << (time(NULL)-_begin) << " sec." << endl; + } + }; + //////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// namespace parser { ///////////////////////////////////////////////////////////////// @@ -30,87 +43,8 @@ namespace zypp { ///////////////////////////////////////////////////////////////// - struct PackagesParser : public Parser - { - std::list result; - - shared_ptr pkgImpl; - NVRAD nvrad; - - bool pkgPending() const - { return pkgImpl; } - - void collectPkg( const shared_ptr & nextPkg_r - = shared_ptr() ) - { - if ( pkgPending() ) - { - result.push_back( detail::makeResolvableFromImpl( nvrad, pkgImpl ) ); - } - pkgImpl = nextPkg_r; - } - - void newPkg() - { - collectPkg( shared_ptr(new detail::PackageImpl) ); - } - - void collectDeps( const std::list & depstr_r, CapSet & capset ) - { - for ( std::list::const_iterator it = depstr_r.begin(); - it != depstr_r.end(); ++it ) - { - capset.insert( CapFactory().parse( ResTraits::kind, *it ) ); - } - } - /* Consume SingleTag data. */ - virtual void consume( const STag & stag_r ) - { - if ( stag_r.stag.isPlain( "Pkg" ) ) - { - std::vector words; - str::split( stag_r.value, std::back_inserter(words) ); - if ( str::split( stag_r.value, std::back_inserter(words) ) != 4 ) - ZYPP_THROW( ParseException( "Pkg" ) ); - - newPkg(); - nvrad = NVRAD( words[0], Edition(words[1],words[2]), Arch(words[4]) ); - } - } - - /* Consume MulitTag data. */ - virtual void consume( const MTag & mtag_r ) - { - if ( ! pkgPending() ) - return; - - if ( mtag_r.stag.isPlain( "Prv" ) ) - { - collectDeps( mtag_r.value, nvrad.provides ); - } - else if ( mtag_r.stag.isPlain( "Prq" ) ) - { - collectDeps( mtag_r.value, nvrad.prerequires ); - } - else if ( mtag_r.stag.isPlain( "Req" ) ) - { - collectDeps( mtag_r.value, nvrad.requires ); - } - else if ( mtag_r.stag.isPlain( "Con" ) ) - { - collectDeps( mtag_r.value, nvrad.conflicts ); - } - else if ( mtag_r.stag.isPlain( "Obs" ) ) - { - collectDeps( mtag_r.value, nvrad.obsoletes ); - } - } - - virtual void parseEnd() - { collectPkg(); } - }; ///////////////////////////////////////////////////////////////// } // namespace tagfile @@ -127,32 +61,9 @@ namespace zypp // //////////////////////////////////////////////////////////////////////////// -using std::endl; using namespace zypp; -using namespace zypp::parser::tagfile; - -//////////////////////////////////////////////////////////////////////////// -// -// Just for the stats -// -//////////////////////////////////////////////////////////////////////////// -struct Measure -{ - time_t _begin; - Measure() - : _begin( time(NULL) ) - { - USR << "START MEASURE..." << endl; - } - ~Measure() - { - USR << "DURATION: " << (time(NULL)-_begin) << " sec." << endl; - } -}; -//////////////////////////////////////////////////////////////////////////// - - using namespace std; + //////////////////////////////////////////////////////////////////////////// // // Main @@ -165,12 +76,15 @@ int main( int argc, char* argv[] ) if (argc >= 2 ) infile = argv[1]; - PackagesParser p; - p.parse( infile ); - - SEC << p.result.size() << endl; - MIL << *p.result.front() << endl; - MIL << p.result.front()->deps() << endl; + try + { + std::list result( source::susetags::parsePackages( infile ) ); + SEC << result.size() << endl; + } + catch( Exception & excpt ) + { + ZYPP_RETHROW( excpt ); + } INT << "===[END]============================================" << endl; return 0; diff --git a/zypp/CapFactory.cc b/zypp/CapFactory.cc index 9489610..323d658 100644 --- a/zypp/CapFactory.cc +++ b/zypp/CapFactory.cc @@ -184,6 +184,12 @@ namespace zypp return name_r.find( ":/" ) != std::string::npos; } + /** Test for a HalCap. \a name_r starts with "hal(". */ + static bool isHalSpec( const std::string & name_r ) + { + return name_r.substr(0,4) == "hal("; + } + /** Try to build a non versioned cap from \a name_r . * * The CapabilityImpl is built here and inserted into _uset. @@ -247,6 +253,38 @@ namespace zypp return buildNamed( refers_r, name_r ); } + + /** Try to build a hal cap from \a name_r . + * + * The CapabilityImpl is built here and inserted into _uset. + * The final Capability must be created by CapFactory, as it + * is a friend of Capability. Here we can't access the ctor. + * + * \todo Fix incaccuracy. + */ + static CapabilityImpl::Ptr Impl::buildHal( const Resolvable::Kind & refers_r, + const std::string & name_r, + Rel op_r = Rel::ANY, + const std::string & value_r = std::string() ) + { + if ( op_r != Rel::ANY ) + { + ZYPP_THROW( Exception("Unsupported kind of Hal Capability") ); + } + + //split: hal(name) [op string] + str::regex rx( "hal\\(([^)]*)\\)" ); + str::smatch what; + if( str::regex_match( name_r.begin(), name_r.end(), what, rx ) ) + { + // Hal always refers to 'System' kind of Resolvable. + return usetInsert + ( new capability::HalCap( ResTraits::kind, + what[1].str() ) ); + } + // otherwise + ZYPP_THROW( Exception("Unsupported kind of Hal Capability") ); + } }; /////////////////////////////////////////////////////////////////// @@ -274,18 +312,6 @@ namespace zypp CapFactory::~CapFactory() {} -#if 0 - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CapFactory::parse - // METHOD TYPE : Capability - // - Capability CapFactory::parse( const std::string & strval_r ) const - { - return parse( strval_r, Resolvable::Kind() ); - } -#endif - /////////////////////////////////////////////////////////////////// // // METHOD NAME : CapFactory::parse @@ -296,36 +322,43 @@ namespace zypp try { - // strval_r has at least two words which could make 'op edition'? - // improve regex! - str::regex rx( "(.*[^ \t])([ \t]+)([^ \t]+)([ \t]+)([^ \t]+)" ); - str::smatch what; - if( str::regex_match( strval_r.begin(), strval_r.end(),what, rx ) ) + if ( Impl::isHalSpec( strval_r ) ) { - Rel op; - Edition edition; - try - { - op = Rel(what[3].str()); - edition = Edition(what[5].str()); - } - catch ( Exception & excpt ) + return Capability( Impl::buildHal( refers_r, strval_r ) ); + } + else + { + // strval_r has at least two words which could make 'op edition'? + // improve regex! + str::regex rx( "(.*[^ \t])([ \t]+)([^ \t]+)([ \t]+)([^ \t]+)" ); + str::smatch what; + if( str::regex_match( strval_r.begin(), strval_r.end(),what, rx ) ) { - // So they don't make valid 'op edition' - ZYPP_CAUGHT( excpt ); - DBG << "Trying named cap for: " << strval_r << endl; - // See whether it makes a named cap. - return Capability( Impl::buildNamed( refers_r, strval_r ) ); + Rel op; + Edition edition; + try + { + op = Rel(what[3].str()); + edition = Edition(what[5].str()); + } + catch ( Exception & excpt ) + { + // So they don't make valid 'op edition' + ZYPP_CAUGHT( excpt ); + DBG << "Trying named cap for: " << strval_r << endl; + // See whether it makes a named cap. + return Capability( Impl::buildNamed( refers_r, strval_r ) ); + } + + // Valid 'op edition' + return Capability ( Impl::buildVersioned( refers_r, + what[1].str(), op, edition ) ); } + //else + // not a VersionedCap - // Valid 'op edition' - return Capability ( Impl::buildVersioned( refers_r, - what[1].str(), op, edition ) ); + return Capability( Impl::buildNamed( refers_r, strval_r ) ); } - //else - // not a VersionedCap - - return Capability( Impl::buildNamed( refers_r, strval_r ) ); } catch ( Exception & excpt ) { @@ -345,6 +378,10 @@ namespace zypp const std::string & edition_r ) const try { + if ( Impl::isHalSpec( name_r ) ) + { + return Capability( Impl::buildHal( refers_r, name_r, Rel(op_r), edition_r ) ); + } // Try creating Rel and Edition, then parse return parse( refers_r, name_r, Rel(op_r), Edition(edition_r) ); } @@ -365,6 +402,10 @@ namespace zypp const Edition & edition_r ) const try { + if ( Impl::isHalSpec( name_r ) ) + { + return Capability( Impl::buildHal( refers_r, name_r, op_r, edition_r.asString() ) ); + } return Capability ( Impl::buildVersioned( refers_r, name_r, op_r, edition_r ) ); } @@ -376,6 +417,22 @@ namespace zypp /////////////////////////////////////////////////////////////////// // + // METHOD NAME : CapFactory::halEvalCap + // METHOD TYPE : Capability + // + Capability CapFactory::halEvalCap() const + try + { + return Capability( Impl::buildHal( Resolvable::Kind(), "hal()" ) ); + } + catch ( Exception & excpt ) + { + ZYPP_RETHROW( excpt ); + return Capability(); // not reached + } + + /////////////////////////////////////////////////////////////////// + // // METHOD NAME : CapFactory::encode // METHOD TYPE : std::string // diff --git a/zypp/CapFactory.h b/zypp/CapFactory.h index 436acfe..fd8c2b1 100644 --- a/zypp/CapFactory.h +++ b/zypp/CapFactory.h @@ -70,6 +70,11 @@ namespace zypp Rel op_r, const Edition & edition_r ) const; + /** Special Capability, triggering evaluation of Hal + * capabilities when matched. + */ + Capability halEvalCap() const; + public: /** Provide a parsable string representation of \a cap_r. */ std::string encode( const Capability & cap_r ) const; diff --git a/zypp/Capability.h b/zypp/Capability.h index 4316d43..89873b4 100644 --- a/zypp/Capability.h +++ b/zypp/Capability.h @@ -52,7 +52,7 @@ namespace zypp * parsed.rel, * parsed.epoch ) ); * } - * catch ( const Exception & excpt_r ) + * catch ( Exception & excpt_r ) * { * ERR << excpt_r << endl; * ... Or maybe just WAR, or ? diff --git a/zypp/ResTraits.cc b/zypp/ResTraits.cc index d89201c..474a56b 100644 --- a/zypp/ResTraits.cc +++ b/zypp/ResTraits.cc @@ -31,6 +31,9 @@ namespace zypp template<> const ResolvableTraits::KindType ResTraits ::kind( "Message" ); + template<> + const ResolvableTraits::KindType ResTraits ::kind( "System" ); + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/ResTraits.h b/zypp/ResTraits.h index ba6bfdc..07ef40f 100644 --- a/zypp/ResTraits.h +++ b/zypp/ResTraits.h @@ -30,6 +30,8 @@ namespace zypp class Script; class Message; + class System; + /** Base of ResTraits. Defines the Resolvable::Kind type. */ struct ResolvableTraits { diff --git a/zypp/source/Makefile.am b/zypp/source/Makefile.am index 70cb5e8..46e9a78 100644 --- a/zypp/source/Makefile.am +++ b/zypp/source/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## ################################################## -SUBDIRS = yum +SUBDIRS = susetags yum ## ################################################## @@ -18,6 +18,8 @@ noinst_LTLIBRARIES = lib@PACKAGE@_source.la lib@PACKAGE@_source_la_SOURCES = \ Source.cc -lib@PACKAGE@_source_la_LIBADD = yum/lib@PACKAGE@_source_yum.la +lib@PACKAGE@_source_la_LIBADD = \ + susetags/lib@PACKAGE@_source_susetags.la \ + yum/lib@PACKAGE@_source_yum.la ## ################################################## diff --git a/zypp/source/susetags/.cvsignore b/zypp/source/susetags/.cvsignore new file mode 100644 index 0000000..5c94a2f --- /dev/null +++ b/zypp/source/susetags/.cvsignore @@ -0,0 +1,8 @@ +Makefile.in +Makefile +.deps +.libs +*.o +*.lo +*.a +*.la diff --git a/zypp/source/susetags/Makefile.am b/zypp/source/susetags/Makefile.am new file mode 100644 index 0000000..69940b7 --- /dev/null +++ b/zypp/source/susetags/Makefile.am @@ -0,0 +1,22 @@ +## Process this file with automake to produce Makefile.in +## ################################################## + +SUBDIRS = + +## ################################################## + +sourceincludedir = $(pkgincludedir)/source + +sourceinclude_HEADERS = \ + PackagesParser.h + +noinst_LTLIBRARIES = lib@PACKAGE@_source_susetags.la + +## ################################################## + +lib@PACKAGE@_source_susetags_la_SOURCES = \ + PackagesParser.cc + +lib@PACKAGE@_source_susetags_la_LIBADD = + +## ################################################## diff --git a/zypp/source/susetags/PackagesParser.cc b/zypp/source/susetags/PackagesParser.cc new file mode 100644 index 0000000..09ab159 --- /dev/null +++ b/zypp/source/susetags/PackagesParser.cc @@ -0,0 +1,136 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/source/susetags/PackagesParser.cc + * +*/ +#include +#include "zypp/base/Logger.h" + +#include "zypp/source/susetags/PackagesParser.h" +#include "zypp/parser/tagfile/Parser.h" +#include "zypp/Package.h" +#include "zypp/detail/PackageImpl.h" +#include "zypp/CapFactory.h" +#include "zypp/CapSet.h" + + +using std::endl; + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace source + { ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace susetags + { ///////////////////////////////////////////////////////////////// + + using namespace parser::tagfile; + + struct PackagesParser : public parser::tagfile::Parser + { + std::list result; + + shared_ptr pkgImpl; + NVRAD nvrad; + + bool pkgPending() const + { return pkgImpl; } + + void collectPkg( const shared_ptr & nextPkg_r + = shared_ptr() ) + { + if ( pkgPending() ) + { + result.push_back( detail::makeResolvableFromImpl( nvrad, pkgImpl ) ); + } + pkgImpl = nextPkg_r; + } + + void newPkg() + { + collectPkg( shared_ptr(new detail::PackageImpl) ); + } + + void collectDeps( const std::list & depstr_r, CapSet & capset ) + { + for ( std::list::const_iterator it = depstr_r.begin(); + it != depstr_r.end(); ++it ) + { + capset.insert( CapFactory().parse( ResTraits::kind, *it ) ); + } + } + + /* Consume SingleTag data. */ + virtual void consume( const STag & stag_r ) + { + if ( stag_r.stag.isPlain( "Pkg" ) ) + { + std::vector words; + str::split( stag_r.value, std::back_inserter(words) ); + + if ( str::split( stag_r.value, std::back_inserter(words) ) != 4 ) + ZYPP_THROW( ParseException( "Pkg" ) ); + + newPkg(); + nvrad = NVRAD( words[0], Edition(words[1],words[2]), Arch(words[4]) ); + } + } + + /* Consume MulitTag data. */ + virtual void consume( const MTag & mtag_r ) + { + if ( ! pkgPending() ) + return; + + if ( mtag_r.stag.isPlain( "Prv" ) ) + { + collectDeps( mtag_r.value, nvrad.provides ); + } + else if ( mtag_r.stag.isPlain( "Prq" ) ) + { + collectDeps( mtag_r.value, nvrad.prerequires ); + } + else if ( mtag_r.stag.isPlain( "Req" ) ) + { + collectDeps( mtag_r.value, nvrad.requires ); + } + else if ( mtag_r.stag.isPlain( "Con" ) ) + { + collectDeps( mtag_r.value, nvrad.conflicts ); + } + else if ( mtag_r.stag.isPlain( "Obs" ) ) + { + collectDeps( mtag_r.value, nvrad.obsoletes ); + } + } + + virtual void parseEnd() + { collectPkg(); } + }; + + //////////////////////////////////////////////////////////////////////////// + + std::list parsePackages( const Pathname & file_r ) + { + PackagesParser p; + p.parse( file_r ); + return p.result; + } + + ///////////////////////////////////////////////////////////////// + } // namespace susetags + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// + } // namespace source + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// diff --git a/zypp/source/susetags/PackagesParser.h b/zypp/source/susetags/PackagesParser.h new file mode 100644 index 0000000..9175dbd --- /dev/null +++ b/zypp/source/susetags/PackagesParser.h @@ -0,0 +1,45 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/source/susetags/PackagesParser.h + * +*/ +#ifndef ZYPP_SOURCE_SUSETAGS_PACKAGESPARSER_H +#define ZYPP_SOURCE_SUSETAGS_PACKAGESPARSER_H + +#include +#include + +#include "zypp/Pathname.h" +#include "zypp/Package.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace source + { ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace susetags + { ///////////////////////////////////////////////////////////////// + + /** \deprecated Just temporary. + * \throws ParseException and others. + */ + std::list parsePackages( const Pathname & file_r ); + + ///////////////////////////////////////////////////////////////// + } // namespace susetags + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// + } // namespace source + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_SOURCE_SUSETAGS_PACKAGESPARSER_H