Author: kkaempf Date: Tue Aug 5 18:20:53 2008 New Revision: 10760 URL: http://svn.opensuse.org/viewcvs/zypp?rev=10760&view=rev Log: better support iterators on Python Modified: trunk/sat-solver/bindings/dependency.i trunk/sat-solver/bindings/pool.i trunk/sat-solver/bindings/python/tests/relation.py trunk/sat-solver/bindings/python/tests/repo.py trunk/sat-solver/bindings/python/tests/repodata.py trunk/sat-solver/bindings/python/tests/rpmdb.py trunk/sat-solver/bindings/python/tests/solvable.py trunk/sat-solver/bindings/repo.i trunk/sat-solver/bindings/satsolver.i trunk/sat-solver/bindings/solver.i Modified: trunk/sat-solver/bindings/dependency.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/dependency.i?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/dependency.i (original) +++ trunk/sat-solver/bindings/dependency.i Tue Aug 5 18:20:53 2008 @@ -73,6 +73,13 @@ void each() { dependency_relations_iterate( $self, dependency_relations_iterate_callback ); } #endif +#if defined(SWIGPYTHON) + %pythoncode %{ + def __iter__(self): + r = range(0,self.size()) + while r: + yield self.get(r.pop(0)) + %} +#endif } - Modified: trunk/sat-solver/bindings/pool.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/pool.i?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/pool.i (original) +++ trunk/sat-solver/bindings/pool.i Tue Aug 5 18:20:53 2008 @@ -179,6 +179,7 @@ */ void each_provider( Relation *rel ) { +#if defined(SWIGRUBY) Id p, *pp; Pool *pool = $self; if (!$self->whatprovides) @@ -186,10 +187,12 @@ FOR_PROVIDES(p, pp, rel->id) generic_xsolvables_iterate_callback( xsolvable_new( $self, p ) ); +#endif } void each_provider( const char *name ) { +#if defined(SWIGRUBY) Id p, *pp; Pool *pool = $self; if (!$self->whatprovides) @@ -197,6 +200,7 @@ FOR_PROVIDES(p, pp, str2id( $self, name, 0) ) generic_xsolvables_iterate_callback( xsolvable_new( $self, p ) ); +#endif } /* @@ -227,8 +231,19 @@ XSolvable *get( int i ) { return xsolvable_get( $self, i, NULL ); } +#if defined(SWIGRUBY) void each() { pool_xsolvables_iterate( $self, generic_xsolvables_iterate_callback ); } +#endif + +#if defined(SWIGPYTHON) + %pythoncode %{ + def __iter__(self): + r = range(0,self.size()) + while r: + yield self.get(r.pop(0)) + %} +#endif XSolvable *find( char *name, Repo *repo = NULL ) { return xsolvable_find( $self, name, repo ); } Modified: trunk/sat-solver/bindings/python/tests/relation.py URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/python/tests/relation.py?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/python/tests/relation.py (original) +++ trunk/sat-solver/bindings/python/tests/relation.py Tue Aug 5 18:20:53 2008 @@ -55,15 +55,13 @@ rel = self.pool.create_relation( "A", satsolver.REL_EQ, "1.0-0" ) assert rel print "Relation: ", rel - for i in range(0, self.repo.size()): - s = self.repo.get(i) + for s in self.repo: if not s.provides().empty(): print "%s provides %s" % (s, s.provides().get(1)) - for j in range(0,s.provides().size()): - p = s.provides().get(j) + for p in s.provides(): if p is not None: - res1 = p.cmp(rel) + res1 = cmp(p, rel) print p, " cmp ", rel, " => ", res1 res2 = p.match(rel) print p, " match ", rel, " => ", res1 Modified: trunk/sat-solver/bindings/python/tests/repo.py URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/python/tests/repo.py?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/python/tests/repo.py (original) +++ trunk/sat-solver/bindings/python/tests/repo.py Tue Aug 5 18:20:53 2008 @@ -58,8 +58,8 @@ assert pool pool.set_arch("i686") repo = pool.add_solv( "os11-biarch.solv" ) - for i in range(0,repo.size()): - print repo.get(i) + for s in repo: + print s assert True Modified: trunk/sat-solver/bindings/python/tests/repodata.py URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/python/tests/repodata.py?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/python/tests/repodata.py (original) +++ trunk/sat-solver/bindings/python/tests/repodata.py Tue Aug 5 18:20:53 2008 @@ -36,8 +36,7 @@ k = repodata.key(i) print " Key ", k.name(), " is ", k.type(), " with ", k.size(), " bytes" - for i in range(0, repo.size()): - s = repo.get(i) + for s in repo: print "Solvable %s: group %s, time %s, downloadsize %s, installsize %s" % (s, s.attr('solvable:group'), s.attr('solvable:buildtime'), s.attr('solvable:downloadsize'), s.attr('solvable:installsize')) if i == 10: break Modified: trunk/sat-solver/bindings/python/tests/rpmdb.py URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/python/tests/rpmdb.py?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/python/tests/rpmdb.py (original) +++ trunk/sat-solver/bindings/python/tests/rpmdb.py Tue Aug 5 18:20:53 2008 @@ -28,8 +28,7 @@ print repo.size(), " installed packages" name = None - for i in range(0, pool.size()): - s = pool.get(i) + for s in pool: print s if i == 7: name = s.name() Modified: trunk/sat-solver/bindings/python/tests/solvable.py URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/python/tests/solvable.py?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/python/tests/solvable.py (original) +++ trunk/sat-solver/bindings/python/tests/solvable.py Tue Aug 5 18:20:53 2008 @@ -43,8 +43,7 @@ def test_deps(self): return - for i in range(0,self.pool.size()): - s = self.pool.get(i) + for s in pool: print s show_dep( "Provides", s.provides()) show_dep( "Requires", s.requires()) Modified: trunk/sat-solver/bindings/repo.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/repo.i?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/repo.i (original) +++ trunk/sat-solver/bindings/repo.i Tue Aug 5 18:20:53 2008 @@ -82,6 +82,14 @@ void each() { repo_xsolvables_iterate( $self, generic_xsolvables_iterate_callback ); } #endif +#if defined(SWIGPYTHON) + %pythoncode %{ + def __iter__(self): + r = range(0,self.size()) + while r: + yield self.get(r.pop(0)) + %} +#endif #if defined(SWIGRUBY) /* %rename is rejected by swig for [] */ Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Tue Aug 5 18:20:53 2008 @@ -91,6 +91,7 @@ #include "covenant.h" +#if defined(SWIGRUBY) /* * iterating over (x)solvables ('yield' in Ruby) * (used by Pool, Repo and Solver) @@ -99,12 +100,11 @@ static int generic_xsolvables_iterate_callback( const XSolvable *xs ) { -#if defined(SWIGRUBY) /* FIXME: how to pass 'break' back to the caller ? */ rb_yield( SWIG_NewPointerObj((void*)xs, SWIGTYPE_p__Solvable, 0) ); -#endif return 0; } +#endif %} Modified: trunk/sat-solver/bindings/solver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/solver.i?rev=10760&r1=10759&r2=10760&view=diff ============================================================================== --- trunk/sat-solver/bindings/solver.i (original) +++ trunk/sat-solver/bindings/solver.i Tue Aug 5 18:20:53 2008 @@ -3,6 +3,7 @@ */ %{ +#if defined(SWIGRUBY) /* * iterating over updates (takes two (x)solvables) ('yield' in Ruby) */ @@ -10,10 +11,8 @@ static int update_xsolvables_iterate_callback( const XSolvable *xs_old, const XSolvable *xs_new ) { -#if defined(SWIGRUBY) /* FIXME: how to pass 'break' back to the caller ? */ rb_yield_values( 2, SWIG_NewPointerObj((void*)xs_old, SWIGTYPE_p__Solvable, 0), SWIG_NewPointerObj((void*)xs_new, SWIGTYPE_p__Solvable, 0) ); -#endif return 0; } @@ -24,10 +23,8 @@ static int solver_decisions_iterate_callback( const Decision *d ) { -#if defined(SWIGRUBY) /* FIXME: how to pass 'break' back to the caller ? */ rb_yield(SWIG_NewPointerObj((void*) d, SWIGTYPE_p__Decision, 0)); -#endif return 0; } @@ -39,12 +36,11 @@ static int solver_problems_iterate_callback( const Problem *p ) { -#if defined(SWIGRUBY) /* FIXME: how to pass 'break' back to the caller ? */ rb_yield( SWIG_NewPointerObj((void*) p, SWIGTYPE_p__Problem, 0) ); -#endif return 0; } +#endif /* SWIGRUBY */ %} @@ -273,8 +269,10 @@ int decision_count() { return $self->decisionq.count; } +#if defined(SWIGRUBY) void each_decision() { return solver_decisions_iterate( $self, solver_decisions_iterate_callback ); } +#endif #if defined(SWIGRUBY) %rename("problems?") problems_found(); @@ -291,6 +289,7 @@ int problems_found() { return $self->problems.count != 0; } +#if defined(SWIGRUBY) void each_problem( Transaction *t ) { return solver_problems_iterate( $self, t, solver_problems_iterate_callback ); } @@ -318,6 +317,7 @@ void each_suggested() { return solver_suggestions_iterate( $self, generic_xsolvables_iterate_callback); } +#endif /* SWIGRUBY */ #if defined(SWIGPERL) SV* getInstallList() -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org