Added pool iterator by kind and by name.
authorMichael Andres <ma@suse.de>
Wed, 5 Dec 2007 13:33:41 +0000 (13:33 +0000)
committerMichael Andres <ma@suse.de>
Wed, 5 Dec 2007 13:33:41 +0000 (13:33 +0000)
Added patch, KindOfResolvable and ResTraits

examples/python/list_available_resolvables.py
examples/python/list_installed_resolvables.py
examples/python/list_resolvables.py
swig/Kind.i
swig/Patch.i [new file with mode: 0644]
swig/ResObject.i
swig/ResPool.i
swig/ResTraits.i [new file with mode: 0644]
swig/Resolver.i
swig/zypp.i

index f282773..39f5f38 100755 (executable)
@@ -18,7 +18,7 @@ for repo in repos:
 print "Available items: %d" % ( Z.pool().size() )
 
 for item in Z.pool():
-    print "* %s:%s-%s.%s\t(%s)" % ( item.resolvable().kindToS(),
+    print "* %s:%s-%s.%s\t(%s)" % ( item.resolvable().kind(),
                                     item.resolvable().name(),
                                     item.resolvable().edition(),
                                     item.resolvable().arch(),
index 6182b86..f4ded7e 100755 (executable)
@@ -8,7 +8,7 @@ Z.addResolvables( Z.target().resolvables(), True );
 print "Installed items: %d" % ( Z.pool().size() )
 
 for item in Z.pool():
-    print "i %s:%s-%s.%s" % ( item.resolvable().kindToS(),
+    print "i %s:%s-%s.%s" % ( item.resolvable().kind(),
                               item.resolvable().name(),
                               item.resolvable().edition(),
                               item.resolvable().arch() )
index b484cc8..15a8170 100755 (executable)
@@ -26,7 +26,7 @@ for item in Z.pool():
     else:
       t = "*"
     print "%s %s:%s-%s.%s\t(%s)" % ( t,
-                                     item.resolvable().kindToS(),
+                                     item.resolvable().kind(),
                                      item.resolvable().name(),
                                      item.resolvable().edition(),
                                      item.resolvable().arch(),
index 97c5688..1d61911 100644 (file)
@@ -1,66 +1,37 @@
 
-%typemap(in) Resolvable::Kind {
-
-  VALUE kindstring = rb_funcall( $input, rb_intern("to_s"), 0, 0);
-  kindstring = rb_funcall( kindstring, rb_intern("downcase"), 0, 0);
-  std::string s(RSTRING(pathstring)->ptr);
-
-  // FIXME make the string lowercase first
-
-  if ( s == "patch" )
-  {
-    $1 == Patch::Kind;
-  }
-  if ( s == "package" )
-  {
-    $1 == Package::Kind;
-  }
-  if ( s == "script" )
-  {
-    $1 == Script::Kind;
-  }
-  if ( s == "message" )
-  {
-    $1 == Message::Kind;
-  }
-  if ( s == "pattern" )
-  {
-    $1 == Pattern::Kind;
-  }
-  if ( s == "Selection" )
-  {
-    $1 == Selection::Kind;
-  }
-
-}
-
-%typemap(out) Kind {
-  const char *s = $1.asString().c_str();
-  $result = ID2SYM(rb_intern(s));
-}
-
-%extend Resolvable::TraitsType::KindType {
-    const char* toS() {
-       return "unknown";
-    }
-}
-
-%extend Resolvable
+template<class _Tp>
+class KindOf
 {
-    // FIXME: this is just a workaround since the whole code above does not work
-    const char* kindToS()
-    {
-       if (isKind<Package>(self))
-           return "package";
-       else if (isKind<Patch>(self))
-           return "patch";
-       else if (isKind<Product>(self))
-           return "product";
-       else if (isKind<Pattern>(self))
-           return "pattern";
-       else if (isKind<Language>(self))
-           return "language";
-       return "unknown";
-    }
-}
-
+      public:
+        /** DefaultCtor: empty string */
+        KindOf()
+        {}
+        /** Ctor from string.
+         * Lowercase version of \a value_r is used as identification.
+        */
+        explicit
+        KindOf( const std::string & value_r )
+        : _value( str::toLower(value_r) )
+        {}
+        /** Dtor */
+        ~KindOf()
+        {}
+      public:
+        /** Identification string. */
+        const std::string & asString() const
+        { return _value; }
+
+        /** Order on KindOf (arbitrary).
+         * Not necessarily lexicographical.
+         * \todo Enable class _Tp to define the order,
+         * Fix logical operators below to use compare,
+        */
+        int compare( const KindOf & rhs ) const
+        { return _value.compare( rhs._value ); }
+
+      private:
+        /** */
+        std::string _value;
+};
+
+%template(KindOfResolvable) KindOf<Resolvable>;
diff --git a/swig/Patch.i b/swig/Patch.i
new file mode 100644 (file)
index 0000000..488754b
--- /dev/null
@@ -0,0 +1,41 @@
+class Patch   : public ResObject
+{
+  public:
+    typedef detail::PatchImplIf      Impl;
+    typedef Patch                    Self;
+    typedef ResTraits<Self>          TraitsType;
+    typedef TraitsType::PtrType      Ptr;
+    typedef TraitsType::constPtrType constPtr;
+
+  public:
+    typedef Impl::AtomList AtomList;
+
+  public:
+    /** Patch ID */
+    std::string id() const;
+    /** Patch time stamp */
+    Date timestamp() const;
+    /** Patch category (recommended, security,...) */
+    std::string category() const;
+    /** Does the system need to reboot to finish the update process? */
+    bool reboot_needed() const;
+    /** Does the patch affect the package manager itself? */
+    bool affects_pkg_manager() const;
+    /** The list of all atoms building the patch */
+    AtomList atoms() const;
+    /** Is the patch installation interactive? (does it need user input?) */
+    bool interactive() const;
+
+
+  protected:
+    /** Ctor */
+    Patch( const NVRAD & nvrad_r );
+    /** Dtor */
+    virtual ~Patch();
+
+  private:
+    /** Access implementation */
+    virtual Impl & pimpl() = 0;
+    /** Access implementation */
+    virtual const Impl & pimpl() const = 0;
+};
index 90d8a97..824b31f 100644 (file)
@@ -31,6 +31,7 @@ class ResObject : public Resolvable
 };
 
 
+#if 0
 %extend intrusive_ptr<const ResObject>
 {
     // FIXME: this is just a workaround, see Kind.i
@@ -54,4 +55,4 @@ class ResObject : public Resolvable
        return compareByNVRA(*self, other);
     }
 }
-
+#endif
index a49480a..8deda8d 100644 (file)
@@ -1,9 +1,5 @@
-#ifdef SWIGPERL5
-#else
-%template(PoolItemSet) std::set<PoolItem_Ref>;
-%apply std::set<PoolItem_Ref>::const_iterator { ResPool::const_iterator };
+
 %apply unsigned { ResPool::size_type };
-#endif
 
 class ResPool
 {
@@ -202,6 +198,7 @@ iter3(ResPool, PoolItem_Ref*);
 #endif
 
 #ifdef SWIGPYTHON
+%template(PoolItemSet) std::set<PoolItem_Ref>;
 %newobject ResPool::const_iterator(PyObject **PYTHON_SELF);
 %extend  ResPool {
   swig::PySwigIterator* iterator(PyObject **PYTHON_SELF)
@@ -209,8 +206,20 @@ iter3(ResPool, PoolItem_Ref*);
     return swig::make_output_iterator(self->begin(), self->begin(),
                                       self->end(), *PYTHON_SELF);
   }
+  swig::PySwigIterator* kinditerator(PyObject **PYTHON_SELF, const ResObject::Kind & kind_r)
+  {
+    return swig::make_output_iterator(self->byKindBegin( kind_r ), self->byKindBegin( kind_r ),
+                                      self->byKindEnd( kind_r ), *PYTHON_SELF);
+  }
+  swig::PySwigIterator* nameiterator(PyObject **PYTHON_SELF, const std::string &name)
+  {
+    return swig::make_output_iterator(self->byNameBegin( name ), self->byNameBegin( name ),
+                                      self->byNameEnd( name ), *PYTHON_SELF);
+  }
 %pythoncode {
   def __iter__(self): return self.iterator()
+  def byKindIterator(self, kind): return self.kinditerator(kind)
+  def byNameIterator(self, name): return self.nameiterator(name)
 }
 }
 
diff --git a/swig/ResTraits.i b/swig/ResTraits.i
new file mode 100644 (file)
index 0000000..d58e827
--- /dev/null
@@ -0,0 +1,38 @@
+
+/** Base of ResTraits. Defines the Resolvable::Kind type. */
+struct ResolvableTraits
+{
+    typedef KindOf<Resolvable>  KindType;
+};
+
+/** ResTraits. Defines common types and the Kind value. */
+template<typename _Res>
+  struct ResTraits : public ResolvableTraits
+  {
+      typedef intrusive_ptr<_Res>       PtrType;
+      typedef intrusive_ptr<const _Res> constPtrType;
+  };
+
+%template(ResTraitsResolvable) ResTraits<Resolvable>;
+
+%pythoncode
+{
+  def KindOfPackage():
+    return KindOfResolvable( "package" )
+  def KindOfSrcPackage():
+    return KindOfResolvable( "srcpackage" )
+  def KindOfPatch():
+    return KindOfResolvable( "patch" )
+  def KindOfPattern():
+    return KindOfResolvable( "pattern" )
+  def KindOfProduct():
+    return KindOfResolvable( "product" )
+  def KindOfAtom():
+    return KindOfResolvable( "atom" )
+  def KindOfScript():
+    return KindOfResolvable( "script" )
+  def KindOfMessage():
+    return KindOfResolvable( "message" )
+  def KindOfLanguage():
+    return KindOfResolvable( "language" )
+}
index a83d6bc..bc756da 100644 (file)
@@ -11,7 +11,7 @@ class Resolver
       bool verifySystem (bool considerNewHardware);
       bool establishPool (void);
       bool freshenPool (void);
-      bool resolvePool (void);      
+      bool resolvePool (void);
       bool resolvePool (bool tryAllPossibilities);
       bool resolveDependencies( void );
       void undo( void );
@@ -19,7 +19,7 @@ class Resolver
       void doUpgrade( UpgradeStatistics & opt_stats_r );
       std::list<PoolItem_Ref> problematicUpdateItems( void ) const;
       ResolverProblemList problems();
-      std::list<std::string> problemDescription( void ) const;      
+      std::list<std::string> problemDescription( void ) const;
       void applySolutions( const ProblemSolutionList & solutions );
 
       Arch architecture() const;
@@ -27,14 +27,14 @@ class Resolver
       void setForceResolve (const bool force);
       const bool forceResolve();
       void setPreferHighestVersion (const bool highestVersion);
-      const bool preferHighestVersion();      
+      const bool preferHighestVersion();
       bool transactResObject( ResObject::constPtr robj, bool install = true);
       //bool transactResKind( Resolvable::Kind kind );
       void transactReset( ResStatus::TransactByValue causer );
       void addRequire (const Capability & capability);
-      void addConflict (const Capability & capability);      
+      void addConflict (const Capability & capability);
       void setTimeout( int seconds );
-      int timeout();      
+      int timeout();
       void setMaxSolverPasses (int count);
       int maxSolverPasses ();
       bool createSolverTestcase (const std::string & dumpPath = "/var/log/YaST2/solverTestcase");
@@ -48,3 +48,5 @@ class Resolver
       solver::detail::Resolver_Ptr _pimpl;
 };
 
+typedef intrusive_ptr<Resolver> Resolver_Ptr;
+%template(Resolver_Ptr) intrusive_ptr<Resolver>;
index 9c73dd5..4375d7f 100644 (file)
@@ -90,6 +90,7 @@ class intrusive_ptr {
 %include "ResStore.i"
 %include "Edition.i"
 %include "Kind.i"
+%include "ResTraits.i"
 %include "Date.i"
 %include "Capability.i"
 %include "CapSet.i"
@@ -111,6 +112,7 @@ class intrusive_ptr {
 %include "NVRA.i"
 %include "NVRAD.i"
 %include "Package.i"
+%include "Patch.i"
 %include "PublicKey.i"
 %include "KeyRing.i"
 %include "Target.i"