- cleanup bindings example code a bit
authorMichael Schroeder <mls@suse.de>
Wed, 11 Jan 2012 15:15:55 +0000 (16:15 +0100)
committerMichael Schroeder <mls@suse.de>
Wed, 11 Jan 2012 15:15:55 +0000 (16:15 +0100)
bindings/solv.i
examples/p5solv
examples/pysolv
examples/rbsolv

index 2a47ef0e35ca3dcff74f7f5109e13e47c0d8df90..0aa91051fb7419804f6f61ea394b8d1eb66d0a0c 100644 (file)
@@ -1871,11 +1871,15 @@ typedef struct {
       return new_XSolvable(e->solv->pool, e->rp);
     }
     SWIGINTERN int Solutionelement_jobidx_get(Solutionelement *e) {
+      if (e->type != SOLVER_SOLUTION_JOB)
+        return -1;
       return (e->p - 1) / 2;
     }
   %}
   %newobject Job;
   Job *Job() {
+    if ($self->type == SOLVER_SOLUTION_JOB)
+      return new_Job($self->solv->pool, SOLVER_NOOP, 0);
     if ($self->type == SOLVER_SOLUTION_INFARCH || $self->type == SOLVER_SOLUTION_DISTUPGRADE)
       return new_Job($self->solv->pool, SOLVER_INSTALL|SOLVER_SOLVABLE, $self->p);
     if ($self->type == SOLVER_SOLUTION_REPLACE || $self->type == SOLVER_SOLUTION_REPLACE_DOWNGRADE || $self->type == SOLVER_SOLUTION_REPLACE_ARCHCHANGE || $self->type == SOLVER_SOLUTION_REPLACE_VENDORCHANGE)
index 4de66cc262ee4fa8b2134d2c91b105b998a11539..7aeb79f899cb125484d47510c6ce39b5baf6f57c 100755 (executable)
@@ -772,29 +772,8 @@ if ($cmd eq 'install' || $cmd eq 'erase' || $cmd eq 'up' || $cmd eq 'dup' || $cm
       my @solutions = $problem->solutions();
       for my $solution (@solutions) {
        print "  Solution $solution->{'id'}:\n";
-       for my $element ($solution->elements()) {
-         my $etype = $element->{'type'};
-         if ($etype == $solv::Solver::SOLVER_SOLUTION_JOB) {
-           print "  - do not ask to ".$jobs[$element->{'jobidx'}]->str()."\n";
-         } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_INFARCH) {
-           if ($element->{'solvable'}->isinstalled()) {
-             print "  - keep ".$element->{'solvable'}->str()." despite the inferior architecture\n";
-           } else {
-             print "  - install ".$element->{'solvable'}->str()." despite the inferior architecture\n";
-           }
-         } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_DISTUPGRADE) {
-           if ($element->{'solvable'}->isinstalled()) {
-             print "  - keep obsolete ".$element->{'solvable'}->str()."\n";
-           } else {
-             print "  - install ".$element->{'solvable'}->str()." from excluded repository\n";
-           }
-         } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_REPLACE) {
-           print "  - allow replacement of ".$element->{'solvable'}->str()." with ".$element->{'replacement'}->str()."\n";
-         } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_ERASE) {
-           print "  - allow deinstallation of ".$element->{'solvable'}->str()."\n";
-         } else {
-           print "  - allow something else\n";
-         }
+       for my $element ($solution->elements(1)) {
+         print "  - ".$element->str()."\n";
         }
         print "\n";
       }
@@ -809,11 +788,10 @@ if ($cmd eq 'install' || $cmd eq 'erase' || $cmd eq 'up' || $cmd eq 'dup' || $cm
       exit(1) if $sol eq 'q';
       my $solution = $solutions[$sol - 1];
       for my $element ($solution->elements()) {
-        my $etype = $element->{'type'};
-        if ($etype == $solv::Solver::SOLVER_SOLUTION_JOB) {
-         $jobs[$element->{'jobidx'}] = $pool->Job($solv::Job::SOLVER_NOOP, 0);
+        my $newjob = $element->Job();
+        if ($element->{'type'} == $solv::Solver::SOLVER_SOLUTION_JOB) {
+         $jobs[$element->{'jobidx'}] = $newjob;
         } else {
-         my $newjob = $element->Job();
          push @jobs, $newjob if $newjob && !grep {$_ == $newjob} @jobs;
        }
       }
index a63c5e4d1172394b2fd8d8519cc41c1e1097d4af..7c628da5a76b2a7c9816471a93fd8139ce0407f9 100755 (executable)
@@ -848,14 +848,14 @@ if cmd == 'install' or cmd == 'erase' or cmd == 'up' or cmd == 'dup' or cmd == '
     solver = None
     while True:
         solver = pool.Solver()
-       solver.set_flag(Solver.SOLVER_FLAG_IGNORE_ALREADY_RECOMMENDED, 1);
-       solver.set_flag(Solver.SOLVER_FLAG_SPLITPROVIDES, 1);
+        solver.set_flag(Solver.SOLVER_FLAG_IGNORE_ALREADY_RECOMMENDED, 1);
+        solver.set_flag(Solver.SOLVER_FLAG_SPLITPROVIDES, 1);
         if cmd == 'erase':
-           solver.set_flag(Solver.SOLVER_FLAG_ALLOW_UNINSTALL, 1);
+            solver.set_flag(Solver.SOLVER_FLAG_ALLOW_UNINSTALL, 1);
         if cmd == 'dup' and len(jobs) == 1 and jobs[0].how == (Job.SOLVER_DISTUPGRADE | Job.SOLVER_SOLVABLE_ALL):
-           solver.set_flag(Solver.SOLVER_FLAG_ALLOW_DOWNGRADE, 1);
-           solver.set_flag(Solver.SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
-           solver.set_flag(Solver.SOLVER_FLAG_ALLOW_ARCHCHANGE, 1);
+            solver.set_flag(Solver.SOLVER_FLAG_ALLOW_DOWNGRADE, 1);
+            solver.set_flag(Solver.SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
+            solver.set_flag(Solver.SOLVER_FLAG_ALLOW_ARCHCHANGE, 1);
         problems = solver.solve(jobs)
         if not problems:
             break
@@ -867,36 +867,9 @@ if cmd == 'install' or cmd == 'erase' or cmd == 'up' or cmd == 'dup' or cmd == '
             solutions = problem.solutions()
             for solution in solutions:
                 print "  Solution %d:" % solution.id
-                elements = solution.elements()
+                elements = solution.elements(True)
                 for element in elements:
-                    etype = element.type
-                    if etype == Solver.SOLVER_SOLUTION_JOB:
-                        print "  - do not ask to", jobs[element.jobidx]
-                    elif etype == Solver.SOLVER_SOLUTION_INFARCH:
-                        if element.solvable.isinstalled():
-                            print "  - keep %s despite the inferior architecture" % element.solvable
-                        else:
-                            print "  - install %s despite the inferior architecture" % element.solvable
-                    elif etype == Solver.SOLVER_SOLUTION_DISTUPGRADE:
-                        if element.solvable.isinstalled():
-                            print "  - keep obsolete %s" % element.solvable
-                        else:
-                            print "  - install %s from excluded repository" % element.solvable
-                    elif etype == Solver.SOLVER_SOLUTION_REPLACE:
-                        illegal = element.illegalreplace()
-                        if illegal & solver.POLICY_ILLEGAL_DOWNGRADE:
-                            print "  - allow downgrade of %s to %s" % (element.solvable, element.replacement)
-                        if illegal & solver.POLICY_ILLEGAL_ARCHCHANGE:
-                            print "  - allow architecture change of %s to %s" % (element.solvable, element.replacement)
-                        if illegal & solver.POLICY_ILLEGAL_VENDORCHANGE:
-                            if element.replacement.vendorid:
-                                print "  - allow vendor change from '%s' (%s) to '%s' (%s)" % (element.solvable.vendor, element.solvable, element.replacement.vendor, element.replacement)
-                            else:
-                                print "  - allow vendor change from '%s' (%s) to no vendor (%s)" % (element.solvable.vendor, element.solvable, element.replacement)
-                        if illegal == 0:
-                            print "  - allow replacement of %s with %s" % (element.solvable, element.replacement)
-                    elif etype == Solver.SOLVER_SOLUTION_ERASE:
-                        print "  - allow deinstallation of %s" % element.solvable
+                    print "  - %s" % element.str
                 print
             sol = ''
             while not (sol == 's' or sol == 'q' or (sol.isdigit() and int(sol) >= 1 and int(sol) <= len(solutions))):
@@ -909,11 +882,10 @@ if cmd == 'install' or cmd == 'erase' or cmd == 'up' or cmd == 'dup' or cmd == '
                 sys.exit(1)
             solution = solutions[int(sol) - 1]
             for element in solution.elements():
-                etype = element.type
-                if etype == Solver.SOLVER_SOLUTION_JOB:
-                    jobs[element.jobidx] = pool.Job(Job.SOLVER_NOOP, 0)
+                newjob = element.Job()
+                if element.type == Solver.SOLVER_SOLUTION_JOB:
+                    jobs[element.jobidx] = newjob
                 else:
-                    newjob = element.Job()
                     if newjob and newjob not in jobs:
                         jobs.append(newjob)
                         
index ef6f02175959765b5120619026b0f48562a6ced7..a53f191375a99228378d56df3a58980a46a8c7e7 100755 (executable)
@@ -790,11 +790,11 @@ if cmd == 'install' || cmd == 'erase' || cmd == 'up' || cmd == 'dup' || cmd == '
       abort if sol == 'q'
       solution = solutions[sol.to_i - 1]
       for element in solution.elements
+        newjob = element.Job()
         if element.type == Solv::Solver::SOLVER_SOLUTION_JOB
-          jobs[element.jobidx] = pool.Job(Solv::Job::SOLVER_NOOP, 0)
+          jobs[element.jobidx] = newjob
        else
-          newjob = element.Job()
-          jobs.push(newjob) if newjob && !jobs.find {|j| j.how == newjob.how && j.what == newjob.what}
+          jobs.push(newjob) if newjob && !jobs.include?(newjob)
        end
       end
     end