Author: kkaempf Date: Sun Dec 30 22:11:52 2007 New Revision: 8165 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8165&view=rev Log: add Problems (to be moved to sat-solver, replacing the printXXX() functions) Added: trunk/sat-solver/bindings/ruby/tests/problems.rb Modified: trunk/sat-solver/bindings/ruby/tests/decisions.rb trunk/sat-solver/bindings/satsolver.i Modified: trunk/sat-solver/bindings/ruby/tests/decisions.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/decisions.rb?rev=8165&r1=8164&r2=8165&view=diff ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/decisions.rb (original) +++ trunk/sat-solver/bindings/ruby/tests/decisions.rb Sun Dec 30 22:11:52 2007 @@ -7,13 +7,13 @@ def test_decision pool = SatSolver::Pool.new assert pool - pool.arch = "i686" installed = pool.create_repo( 'system' ) assert installed installed.create_solvable( 'A', '0.0-0' ) installed.create_solvable( 'B', '1.0-0' ) - installed.create_solvable( 'C', '2.0-0' ) + solv = installed.create_solvable( 'C', '2.0-0' ) + solv.requires << SatSolver::Relation.new( pool, "D", SatSolver::REL_EQ, "3.0-0" ) installed.create_solvable( 'D', '3.0-0' ) repo = pool.create_repo( 'test' ) @@ -24,12 +24,12 @@ solv1.obsoletes << SatSolver::Relation.new( pool, "C" ) solv1.requires << SatSolver::Relation.new( pool, "B", SatSolver::REL_GE, "2.0-0" ) - solv2 = repo.create_solvable( 'B', '2.0-0', 'noarch' ) + solv2 = repo.create_solvable( 'B', '2.0-0' ) assert solv2 - solv3 = repo.create_solvable( 'CC', '3.3-0', 'noarch' ) + solv3 = repo.create_solvable( 'CC', '3.3-0' ) solv3.requires << SatSolver::Relation.new( pool, "A", SatSolver::REL_GT, "0.0-0" ) - repo.create_solvable( 'DD', '4.4-0', 'noarch' ) + repo.create_solvable( 'DD', '4.4-0' ) transaction = pool.create_transaction Added: trunk/sat-solver/bindings/ruby/tests/problems.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/problems.rb?rev=8165&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/problems.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/problems.rb Sun Dec 30 22:11:52 2007 @@ -0,0 +1,73 @@ +$: << "../../../build/bindings/ruby" +# test Problems +require 'test/unit' +require 'satsolver' + +class ProblemTest < Test::Unit::TestCase + def test_problems + pool = SatSolver::Pool.new + assert pool + + installed = pool.create_repo( 'system' ) + assert installed + installed.create_solvable( 'A', '0.0-0' ) + installed.create_solvable( 'B', '1.0-0' ) + solv = installed.create_solvable( 'C', '2.0-0' ) + solv.requires << SatSolver::Relation.new( pool, "D", SatSolver::REL_EQ, "3.0-0" ) + installed.create_solvable( 'D', '3.0-0' ) + + repo = pool.create_repo( 'test' ) + assert repo + + solv1 = repo.create_solvable( 'A', '1.0-0' ) + assert solv1 + solv1.obsoletes << SatSolver::Relation.new( pool, "C" ) + solv1.requires << SatSolver::Relation.new( pool, "B", SatSolver::REL_GT, "2.0-0" ) + + solv2 = repo.create_solvable( 'B', '2.0-0' ) + assert solv2 + + solv3 = repo.create_solvable( 'CC', '3.3-0' ) +# solv3.requires << SatSolver::Relation.new( pool, "Z" ) + repo.create_solvable( 'DD', '4.4-0' ) + + + transaction = pool.create_transaction + transaction.install( solv1 ) + transaction.remove( "Z" ) + + solver = pool.create_solver( installed ) +# solver.allow_uninstall = 1; +# @pool.debug = 255 + solver.solve( transaction ) + puts "#{solver.problem_count} problems found" + assert solver.problem_count > 0 + i = 0 + solver.each_problem( transaction ) { |p| + i += 1 + case p.reason + when SatSolver::SOLVER_PROBLEM_UPDATE_RULE + reason = "problem with installed" + when SatSolver::SOLVER_PROBLEM_JOB_RULE + reason = "conflicting requests" + when SatSolver::SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP + reason = "nothing provides requested" + when SatSolver::SOLVER_PROBLEM_NOT_INSTALLABLE + reason = "not installable" + when SatSolver::SOLVER_PROBLEM_NOTHING_PROVIDES_DEP + reason = "nothing provides rel required by source" + when SatSolver::SOLVER_PROBLEM_SAME_NAME + reason = "cannot install both" + when SatSolver::SOLVER_PROBLEM_PACKAGE_CONFLICT + reason = "source conflicts with rel provided by target" + when SatSolver::SOLVER_PROBLEM_PACKAGE_OBSOLETES + reason = "source obsoletes rel provided by target" + when SatSolver::SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE + reason = "source requires rel but no providers are installable" + else + reason = "**unknown**" + end + puts "#{i}: [#{reason}] Source #{p.source}, Rel #{p.relation}, Target #{p.target}" + } + end +end Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=8165&r1=8164&r2=8165&view=diff ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Sun Dec 30 22:11:52 2007 @@ -37,7 +37,7 @@ Pool *pool; } Relation; -static Relation *relation_new( Id id, Pool *pool ) +static Relation *relation_new( Pool *pool, Id id ) { if (!id) return NULL; Relation *relation = (Relation *)malloc( sizeof( Relation )); @@ -172,8 +172,22 @@ } typedef struct _Problem { + int reason; + Solvable *source; + Relation *relation; + Solvable *target; } Problem; +static Problem *problem_new( int reason, Solvable *source, Relation *relation, Solvable *target ) +{ + Problem *p = (Problem *)malloc( sizeof( Problem )); + p->reason = reason; + p->source = source; + p->relation = relation; + p->target = target; + return p; +} + %} /*-------------------------------------------------------------*/ @@ -534,8 +548,6 @@ #define REL_WITH 18 #define REL_NAMESPACE 18 - Relation( Id id, Pool *pool) - { return relation_new( id, pool ); } %feature("autodoc", "1"); Relation( Pool *pool, const char *name, int op = 0, const char *evr = NULL ) { @@ -544,7 +556,7 @@ if (evr) evr_id = str2id( pool, evr, 1 ); Id rel = rel2id( pool, name_id, evr_id, op, 1 ); - return relation_new( rel, pool ); + return relation_new( pool, rel ); } ~Relation() { free( $self ); } @@ -627,7 +639,7 @@ if ( !*ids ) break; if ( i == 0 ) { - return relation_new( *ids, $self->solvable->repo->pool ); + return relation_new( $self->solvable->repo->pool, *ids ); } ++ids; } @@ -639,7 +651,7 @@ { Id *ids = $self->solvable->repo->idarraydata + *($self->relations); while (*ids) { - rb_yield( SWIG_NewPointerObj((void*) relation_new( *ids, $self->solvable->repo->pool ), SWIGTYPE_p__Relation, 0) ); + rb_yield( SWIG_NewPointerObj((void*) relation_new( $self->solvable->repo->pool, *ids ), SWIGTYPE_p__Relation, 0) ); ++ids; } } @@ -853,6 +865,29 @@ } /*-------------------------------------------------------------*/ +/* Problem */ + +%extend Problem { + %constant int SOLVER_PROBLEM_UPDATE_RULE = 1; + %constant int SOLVER_PROBLEM_JOB_RULE = 2; + %constant int SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP = 3; + %constant int SOLVER_PROBLEM_NOT_INSTALLABLE = 4; + %constant int SOLVER_PROBLEM_NOTHING_PROVIDES_DEP = 5; + %constant int SOLVER_PROBLEM_SAME_NAME = 6; + %constant int SOLVER_PROBLEM_PACKAGE_CONFLICT = 7; + %constant int SOLVER_PROBLEM_PACKAGE_OBSOLETES = 8; + %constant int SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE = 8; + int reason() + { return $self->reason; } + Solvable *source() + { return $self->source; } + Relation *relation() + { return $self->relation; } + Solvable *target() + { return $self->target; } +} + +/*-------------------------------------------------------------*/ /* Solver */ %extend Solver { @@ -918,7 +953,7 @@ Solvable *s, *r; int op; Decision *d; - +#if 0 if (installed) { FOR_REPO_SOLVABLES(installed, p, s) { if ($self->decisionmap[p] >= 0) @@ -932,35 +967,45 @@ rb_yield(SWIG_NewPointerObj((void*) d, SWIGTYPE_p__Decision, 0)); } } - +#endif int i; for ( i = 0; i < $self->decisionq.count; i++) { p = $self->decisionq.elements[i]; + r = NULL; if (p < 0) { /* remove */ - continue; + p = -p; + s = pool_id2solvable( pool, p ); + if (obsoletesmap[p]) { + op = DEC_OBSOLETE; + r = pool_id2solvable( pool, obsoletesmap[p] ); + } + else { + op = DEC_REMOVE; + } } else if (p == SYSTEMSOLVABLE) { continue; } - s = pool->solvables + p; - r = NULL; - if (installed && s->repo == installed) - continue; - - if (!obsoletesmap[p]) { - op = DEC_INSTALL; - } else { - op = DEC_UPDATE; - int j; - for (j = installed->start; j < installed->end; j++) { - if (obsoletesmap[j] == p) { - r = pool_id2solvable( pool, j ); - break; + s = pool->solvables + p; + if (installed && s->repo == installed) + continue; + + if (!obsoletesmap[p]) { + op = DEC_INSTALL; + } + else { + op = DEC_UPDATE; + int j; + for (j = installed->start; j < installed->end; j++) { + if (obsoletesmap[j] == p) { + r = pool_id2solvable( pool, j ); + break; + } } - } + } } d = decision_new( op, s, r ); rb_yield(SWIG_NewPointerObj((void*) d, SWIGTYPE_p__Decision, 0)); @@ -974,8 +1019,26 @@ #endif int problems_found() { return $self->problems.count != 0; } - void print_decisions() - { printdecisions( $self ); } +#if defined(SWIGRUBY) + void each_problem( Transaction *t ) + { + Pool *pool = $self->pool; + Queue *transaction = &(t->queue); + + Id problem = 0; + while ((problem = solver_next_problem( $self, problem )) != 0) { + Id prule; + Id dep, source, target; + Problem *p; + int reason; + + prule = solver_findproblemrule( $self, problem ); + reason = solver_problemruleinfo( $self, transaction, prule, &dep, &source, &target ); + p = problem_new( reason, pool_id2solvable( pool, source ), relation_new( pool, dep ), pool_id2solvable( pool, target ) ); + rb_yield( SWIG_NewPointerObj((void*) p, SWIGTYPE_p__Problem, 0) ); + } + } +#endif #if defined(SWIGRUBY) void each_to_install() -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org