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 \
#include <zypp/base/String.h>
#include <zypp/base/PtrTypes.h>
-#include <zypp/parser/tagfile/Parser.h>
-#include <zypp/Package.h>
-#include <zypp/CapSet.h>
-#include <zypp/CapFactory.h>
-#include <zypp/detail/PackageImpl.h>
-
-#include <zypp/NVRA.h>
+#include <zypp/source/susetags/PackagesParser.h>
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
{ /////////////////////////////////////////////////////////////////
{ /////////////////////////////////////////////////////////////////
- struct PackagesParser : public Parser
- {
- std::list<Package::Ptr> result;
-
- shared_ptr<detail::PackageImpl> pkgImpl;
- NVRAD nvrad;
-
- bool pkgPending() const
- { return pkgImpl; }
-
- void collectPkg( const shared_ptr<detail::PackageImpl> & nextPkg_r
- = shared_ptr<detail::PackageImpl>() )
- {
- if ( pkgPending() )
- {
- result.push_back( detail::makeResolvableFromImpl( nvrad, pkgImpl ) );
- }
- pkgImpl = nextPkg_r;
- }
-
- void newPkg()
- {
- collectPkg( shared_ptr<detail::PackageImpl>(new detail::PackageImpl) );
- }
-
- void collectDeps( const std::list<std::string> & depstr_r, CapSet & capset )
- {
- for ( std::list<std::string>::const_iterator it = depstr_r.begin();
- it != depstr_r.end(); ++it )
- {
- capset.insert( CapFactory().parse( ResTraits<Package>::kind, *it ) );
- }
- }
- /* Consume SingleTag data. */
- virtual void consume( const STag & stag_r )
- {
- if ( stag_r.stag.isPlain( "Pkg" ) )
- {
- std::vector<std::string> 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
//
////////////////////////////////////////////////////////////////////////////
-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
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<Package::Ptr> result( source::susetags::parsePackages( infile ) );
+ SEC << result.size() << endl;
+ }
+ catch( Exception & excpt )
+ {
+ ZYPP_RETHROW( excpt );
+ }
INT << "===[END]============================================" << endl;
return 0;
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.
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<System>::kind,
+ what[1].str() ) );
+ }
+ // otherwise
+ ZYPP_THROW( Exception("Unsupported kind of Hal Capability") );
+ }
};
///////////////////////////////////////////////////////////////////
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
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 )
{
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) );
}
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 ) );
}
///////////////////////////////////////////////////////////////////
//
+ // 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
//
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;
* parsed.rel,
* parsed.epoch ) );
* }
- * catch ( const Exception & excpt_r )
+ * catch ( Exception & excpt_r )
* {
* ERR << excpt_r << endl;
* ... Or maybe just WAR, or ?
template<>
const ResolvableTraits::KindType ResTraits<Message> ::kind( "Message" );
+ template<>
+ const ResolvableTraits::KindType ResTraits<System> ::kind( "System" );
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
class Script;
class Message;
+ class System;
+
/** Base of ResTraits. Defines the Resolvable::Kind type. */
struct ResolvableTraits
{
## Process this file with automake to produce Makefile.in
## ##################################################
-SUBDIRS = yum
+SUBDIRS = susetags yum
## ##################################################
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
## ##################################################
--- /dev/null
+Makefile.in
+Makefile
+.deps
+.libs
+*.o
+*.lo
+*.a
+*.la
--- /dev/null
+## 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 =
+
+## ##################################################
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/source/susetags/PackagesParser.cc
+ *
+*/
+#include <iostream>
+#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<Package::Ptr> result;
+
+ shared_ptr<detail::PackageImpl> pkgImpl;
+ NVRAD nvrad;
+
+ bool pkgPending() const
+ { return pkgImpl; }
+
+ void collectPkg( const shared_ptr<detail::PackageImpl> & nextPkg_r
+ = shared_ptr<detail::PackageImpl>() )
+ {
+ if ( pkgPending() )
+ {
+ result.push_back( detail::makeResolvableFromImpl( nvrad, pkgImpl ) );
+ }
+ pkgImpl = nextPkg_r;
+ }
+
+ void newPkg()
+ {
+ collectPkg( shared_ptr<detail::PackageImpl>(new detail::PackageImpl) );
+ }
+
+ void collectDeps( const std::list<std::string> & depstr_r, CapSet & capset )
+ {
+ for ( std::list<std::string>::const_iterator it = depstr_r.begin();
+ it != depstr_r.end(); ++it )
+ {
+ capset.insert( CapFactory().parse( ResTraits<Package>::kind, *it ) );
+ }
+ }
+
+ /* Consume SingleTag data. */
+ virtual void consume( const STag & stag_r )
+ {
+ if ( stag_r.stag.isPlain( "Pkg" ) )
+ {
+ std::vector<std::string> 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<Package::Ptr> parsePackages( const Pathname & file_r )
+ {
+ PackagesParser p;
+ p.parse( file_r );
+ return p.result;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace susetags
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace source
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/source/susetags/PackagesParser.h
+ *
+*/
+#ifndef ZYPP_SOURCE_SUSETAGS_PACKAGESPARSER_H
+#define ZYPP_SOURCE_SUSETAGS_PACKAGESPARSER_H
+
+#include <iosfwd>
+#include <list>
+
+#include "zypp/Pathname.h"
+#include "zypp/Package.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace source
+ { /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace susetags
+ { /////////////////////////////////////////////////////////////////
+
+ /** \deprecated Just temporary.
+ * \throws ParseException and others.
+ */
+ std::list<Package::Ptr> parsePackages( const Pathname & file_r );
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace susetags
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace source
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SOURCE_SUSETAGS_PACKAGESPARSER_H