bindings: add stringification shortcut for problems
authorMichael Schroeder <mls@suse.de>
Fri, 20 Sep 2013 13:15:59 +0000 (15:15 +0200)
committerMichael Schroeder <mls@suse.de>
Fri, 20 Sep 2013 13:15:59 +0000 (15:15 +0200)
Also fixes bugs in the rbsolv example.

bindings/solv.i
doc/libsolv-bindings.3
doc/libsolv-bindings.txt
doc/libsolv-constantids.3
doc/libsolv-history.3
doc/libsolv-pool.3
doc/libsolv.3
examples/p5solv
examples/pysolv
examples/rbsolv

index 7c0db0a..77d744a 100644 (file)
@@ -2396,6 +2396,17 @@ rb_eval_string(
       queue_push(&q, i);
     return q;
   }
+#if defined(SWIGPERL)
+  %rename("str") __str__;
+#endif
+  const char *__str__() {
+    Id type, source, target, dep;
+    Id r = solver_findproblemrule($self->solv, $self->id);
+    if (!r)
+      return "";
+    type = solver_ruleinfo($self->solv, r, &source, &target, &dep);
+    return solver_problemruleinfo2str($self->solv, type, source, target, dep);
+  }
 }
 
 %extend Solution {
index 77e64c1..8dc8a42 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: Libsolv-Bindings
 .\"    Author: [see the "Author" section]
 .\" Generator: DocBook XSL Stylesheets v1.78.0 <http://docbook.sf.net/>
-.\"      Date: 08/21/2013
+.\"      Date: 09/20/2013
 .\"    Manual: LIBSOLV
 .\"    Source: libsolv
 .\"  Language: English
 .\"
-.TH "LIBSOLV\-BINDINGS" "3" "08/21/2013" "libsolv" "LIBSOLV"
+.TH "LIBSOLV\-BINDINGS" "3" "09/20/2013" "libsolv" "LIBSOLV"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -3665,6 +3665,21 @@ my \fI$cnt\fR \fB=\fR \fI$problem\fR\fB\->solution_count()\fR;
 .\}
 .sp
 Return the number of solutions without creating solution objects\&.
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fB<stringification>\fR
+my \fI$str\fR \fB=\fR \fI$problem\fR\fB\->str\fR;
+\fIstr\fR \fB= str(\fR\fIproblem\fR\fB)\fR
+\fIstr\fR \fB=\fR \fIproblem\fR\fB\&.to_s\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Return a string describing the problem\&. This is a convenience function, it is a shorthand for calling findproblemrule(), then ruleinfo() on the problem rule and problemstr() on the ruleinfo object\&.
 .SH "THE RULE CLASS"
 .sp
 Rules are the basic block of sat solving\&. Each package dependency gets translated into one or multiple rules\&.
index 062761f..8f5f980 100644 (file)
@@ -2276,6 +2276,15 @@ the solution class for more information.
 
 Return the number of solutions without creating solution objects.
 
+       <stringification>
+       my $str = $problem->str;
+       str = str(problem)
+       str = problem.to_s
+
+Return a string describing the problem. This is a convenience function, it is
+a shorthand for calling findproblemrule(), then ruleinfo() on the problem
+rule and problemstr() on the ruleinfo object.
+
 The Rule Class
 --------------
 Rules are the basic block of sat solving. Each package dependency gets translated
index 92b5a4e..225ae7f 100644 (file)
@@ -1,13 +1,13 @@
 '\" t
 .\"     Title: Libsolv-Constantids
 .\"    Author: [see the "Author" section]
-.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
-.\"      Date: 06/18/2013
+.\" Generator: DocBook XSL Stylesheets v1.78.0 <http://docbook.sf.net/>
+.\"      Date: 09/20/2013
 .\"    Manual: LIBSOLV
 .\"    Source: libsolv
 .\"  Language: English
 .\"
-.TH "LIBSOLV\-CONSTANTIDS" "3" "06/18/2013" "libsolv" "LIBSOLV"
+.TH "LIBSOLV\-CONSTANTIDS" "3" "09/20/2013" "libsolv" "LIBSOLV"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index 2f3df53..c4b33fc 100644 (file)
@@ -1,13 +1,13 @@
 '\" t
 .\"     Title: Libsolv-History
 .\"    Author: [see the "Author" section]
-.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
-.\"      Date: 06/11/2013
+.\" Generator: DocBook XSL Stylesheets v1.78.0 <http://docbook.sf.net/>
+.\"      Date: 09/20/2013
 .\"    Manual: LIBSOLV
 .\"    Source: libsolv
 .\"  Language: English
 .\"
-.TH "LIBSOLV\-HISTORY" "3" "06/11/2013" "libsolv" "LIBSOLV"
+.TH "LIBSOLV\-HISTORY" "3" "09/20/2013" "libsolv" "LIBSOLV"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index db66aa5..748f112 100644 (file)
@@ -1,13 +1,13 @@
 '\" t
 .\"     Title: Libsolv-Pool
 .\"    Author: [see the "Author" section]
-.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
-.\"      Date: 06/14/2013
+.\" Generator: DocBook XSL Stylesheets v1.78.0 <http://docbook.sf.net/>
+.\"      Date: 09/20/2013
 .\"    Manual: LIBSOLV
 .\"    Source: libsolv
 .\"  Language: English
 .\"
-.TH "LIBSOLV\-POOL" "3" "06/14/2013" "libsolv" "LIBSOLV"
+.TH "LIBSOLV\-POOL" "3" "09/20/2013" "libsolv" "LIBSOLV"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index 88180b9..da81c49 100644 (file)
@@ -1,13 +1,13 @@
 '\" t
 .\"     Title: Libsolv
 .\"    Author: [see the "Author" section]
-.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
-.\"      Date: 06/14/2013
+.\" Generator: DocBook XSL Stylesheets v1.78.0 <http://docbook.sf.net/>
+.\"      Date: 09/20/2013
 .\"    Manual: LIBSOLV
 .\"    Source: libsolv
 .\"  Language: English
 .\"
-.TH "LIBSOLV" "3" "06/14/2013" "libsolv" "LIBSOLV"
+.TH "LIBSOLV" "3" "09/20/2013" "libsolv" "LIBSOLV"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index ac2e730..77d580a 100755 (executable)
@@ -627,9 +627,7 @@ while (1) {
   last unless @problems;
   for my $problem (@problems) {
     print "Problem $problem->{id}/".@problems.":\n";
-    my $r = $problem->findproblemrule();
-    my $ri = $r->info();
-    print $ri->problemstr()."\n";
+    print $problem->str()."\n";
     my @solutions = $problem->solutions();
     for my $solution (@solutions) {
       print "  Solution $solution->{id}:\n";
index a658eab..fe217e1 100755 (executable)
@@ -768,9 +768,7 @@ while True:
         break
     for problem in problems:
         print "Problem %d/%d:" % (problem.id, len(problems))
-        r = problem.findproblemrule()
-        ri = r.info()
-        print ri.problemstr()
+        print problem
         solutions = problem.solutions()
         for solution in solutions:
             print "  Solution %d:" % solution.id
index 6119190..c67a4c4 100755 (executable)
@@ -527,7 +527,7 @@ end
 for reposdir in reposdirs do
   next unless FileTest.directory?(reposdir)
   for reponame in Dir["#{reposdir}/*.repo"].sort do
-    cfg = IniFile.new(reponame)
+    cfg = IniFile.load(reponame)
     cfg.each_section do |ali|
       repoattr = { 'alias' => ali, 'enabled' => 0, 'priority' => 99, 'autorefresh' => 1, 'type' => 'rpm-md', 'metadata_expire' => 900}
       repoattr.update(cfg[ali])
@@ -641,7 +641,7 @@ while true
   break if problems.empty?
   for problem in problems
     puts "Problem #{problem.id}/#{problems.count}:"
-    puts problem.findproblemrule.info.problemstr
+    puts problem
     solutions = problem.solutions
     for solution in solutions
       puts "  Solution #{solution.id}:"
@@ -712,7 +712,7 @@ for cl in trans.classify(Solv::Transaction::SOLVER_TRANSACTION_SHOW_OBSOLETES |
 end
 puts "install size change: #{trans.calc_installsizechange()} K\n\n"
 
-while true:
+while true
   print("OK to continue (y/n)? ")
   STDOUT.flush
   yn = STDIN.gets.strip