add pool_selection2str() and use it in the bindings
authorMichael Schroeder <mls@suse.de>
Mon, 29 Oct 2012 11:54:39 +0000 (12:54 +0100)
committerMichael Schroeder <mls@suse.de>
Mon, 29 Oct 2012 11:54:39 +0000 (12:54 +0100)
bindings/solv.i
src/libsolv.ver
src/solverdebug.c
src/solverdebug.h

index 021ca6f..4401752 100644 (file)
@@ -784,11 +784,11 @@ typedef struct {
   %rename("str") __str__;
 #endif
   const char *__str__() {
-    int i;
-    char *s = pool_tmpjoin($self->pool, 0, 0, 0);
-    for (i = 0; i < $self->q.count; i += 2)
-      s = pool_tmpappend($self->pool, s, " | ", solver_select2str($self->pool, $self->q.elements[i] & SOLVER_SELECTMASK, $self->q.elements[i + 1]));
-    return *s ? s + 3 : s;
+    return pool_selection2str($self->pool, &$self->q, 0);
+  }
+  const char *__repr__() {
+    const char *str = pool_selection2str($self->pool, &$self->q, ~0);
+    return pool_tmpjoin($self->pool, "<Selection ", str, ">");
   }
 }
 
index 1ad371a..1b21ea4 100644 (file)
@@ -86,6 +86,7 @@ SOLV_1.0 {
                pool_queuetowhatprovides;
                pool_rel2id;
                pool_search;
+               pool_selection2str;
                pool_set_flag;
                pool_set_installed;
                pool_set_languages;
index 3c4af96..130e04f 100644 (file)
@@ -801,6 +801,7 @@ solver_select2str(Pool *pool, Id select, Id what)
 {
   const char *s;
   char *b;
+  select &= SOLVER_SELECTMASK;
   if (select == SOLVER_SOLVABLE)
     return pool_solvid2str(pool, what);
   if (select == SOLVER_SOLVABLE_NAME)
@@ -897,7 +898,8 @@ pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
       break;
     }
   s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
-  if ((how & flagmask & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
+  how &= flagmask;
+  if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
     return s;
   o = strlen(s);
   s = pool_tmpappend(pool, s, " ", 0);
@@ -926,6 +928,46 @@ pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
 }
 
 const char *
+pool_selection2str(Pool *pool, Queue *selection, Id flagmask)
+{
+  char *s;
+  const char *s2;
+  int i;
+  s = pool_tmpjoin(pool, 0, 0, 0);
+  for (i = 0; i < selection->count; i++)
+    {
+      Id how = selection->elements[i];
+      if (*s)
+       s = pool_tmpappend(pool, s, " | ", 0);
+      s2 = solver_select2str(pool, how & SOLVER_SELECTMASK, selection->elements[i + 1]);
+      s = pool_tmpappend(pool, s, s2, 0);
+      pool_freetmpspace(pool, s2);
+      how &= flagmask & SOLVER_SETMASK;
+      if (how)
+       {
+         int o = strlen(s);
+         s = pool_tmpappend(pool, s, " ", 0);
+           s = pool_tmpappend(pool, s, ",setev", 0);
+         if (how & SOLVER_SETEVR)
+           s = pool_tmpappend(pool, s, ",setevr", 0);
+         if (how & SOLVER_SETARCH)
+           s = pool_tmpappend(pool, s, ",setarch", 0);
+         if (how & SOLVER_SETVENDOR)
+           s = pool_tmpappend(pool, s, ",setvendor", 0);
+         if (how & SOLVER_SETREPO)
+           s = pool_tmpappend(pool, s, ",setrepo", 0);
+         if (how & SOLVER_NOAUTOSET)
+           s = pool_tmpappend(pool, s, ",noautoset", 0);
+         if (s[o + 1] != ',')
+           s = pool_tmpappend(pool, s, ",?", 0);
+         s[o + 1] = '[';
+         s = pool_tmpappend(pool, s, "]", 0);
+       }
+    }
+  return s;
+}
+
+const char *
 solver_problemruleinfo2str(Solver *solv, SolverRuleinfo type, Id source, Id target, Id dep)
 {
   Pool *pool = solv->pool;
index a1d6663..2b67b89 100644 (file)
@@ -35,7 +35,8 @@ extern void solver_printtrivial(Solver *solv);
 extern void transaction_print(Transaction *trans);
 
 extern const char *solver_select2str(Pool *pool, Id select, Id what);
-extern const char *pool_job2str(Pool *pool, Id how, Id what, int withflags);
+extern const char *pool_job2str(Pool *pool, Id how, Id what, Id flagmask);
+extern const char *pool_selection2str(Pool *pool, Queue *selection, Id flagmask);
 extern const char *solver_problemruleinfo2str(Solver *solv, SolverRuleinfo type, Id source, Id target, Id dep);
 extern const char *solver_solutionelement2str(Solver *solv, Id p, Id rp);
 extern const char *policy_illegal2str(Solver *solv, int illegal, Solvable *s, Solvable *rs);