backup
authorMichael Andres <ma@suse.de>
Sun, 15 Jan 2006 20:55:18 +0000 (20:55 +0000)
committerMichael Andres <ma@suse.de>
Sun, 15 Jan 2006 20:55:18 +0000 (20:55 +0000)
12 files changed:
configure.ac
devel/devel.ma/Parse.cc
zypp/CapFactory.cc
zypp/CapFactory.h
zypp/Capability.h
zypp/ResTraits.cc
zypp/ResTraits.h
zypp/source/Makefile.am
zypp/source/susetags/.cvsignore [new file with mode: 0644]
zypp/source/susetags/Makefile.am [new file with mode: 0644]
zypp/source/susetags/PackagesParser.cc [new file with mode: 0644]
zypp/source/susetags/PackagesParser.h [new file with mode: 0644]

index 9385ce7..7f917a9 100644 (file)
@@ -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   \
index 6b6cf4e..fecfe3b 100644 (file)
@@ -9,19 +9,32 @@
 #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
   { /////////////////////////////////////////////////////////////////
@@ -30,87 +43,8 @@ namespace zypp
     { /////////////////////////////////////////////////////////////////
 
 
-      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
@@ -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<Package::Ptr> result( source::susetags::parsePackages( infile ) );
+      SEC << result.size() << endl;
+    }
+  catch( Exception & excpt )
+    {
+      ZYPP_RETHROW( excpt );
+    }
 
   INT << "===[END]============================================" << endl;
   return 0;
index 9489610..323d658 100644 (file)
@@ -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<System>::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
   //
index 436acfe..fd8c2b1 100644 (file)
@@ -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;
index 4316d43..89873b4 100644 (file)
@@ -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 ?
index d89201c..474a56b 100644 (file)
@@ -31,6 +31,9 @@ namespace zypp
   template<>
     const ResolvableTraits::KindType ResTraits<Message>  ::kind( "Message" );
 
+  template<>
+    const ResolvableTraits::KindType ResTraits<System>  ::kind( "System" );
+
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index ba6bfdc..07ef40f 100644 (file)
@@ -30,6 +30,8 @@ namespace zypp
   class Script;
   class Message;
 
+  class System;
+
   /** Base of ResTraits. Defines the Resolvable::Kind type. */
   struct ResolvableTraits
   {
index 70cb5e8..46e9a78 100644 (file)
@@ -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 (file)
index 0000000..5c94a2f
--- /dev/null
@@ -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 (file)
index 0000000..69940b7
--- /dev/null
@@ -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 (file)
index 0000000..09ab159
--- /dev/null
@@ -0,0 +1,136 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ 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
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/source/susetags/PackagesParser.h b/zypp/source/susetags/PackagesParser.h
new file mode 100644 (file)
index 0000000..9175dbd
--- /dev/null
@@ -0,0 +1,45 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ 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