poldek: poldek/pkgset.c, poldek/poldek.h, poldek/poldek_ts.c, pold...

mis mis at pld-linux.org
Sun May 20 23:44:33 CEST 2007


Author: mis                          Date: Sun May 20 21:44:33 2007 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- new option --dependency-graph to draw dependency graph with graphviz

---- Files affected:
poldek/poldek:
   pkgset.c (1.91 -> 1.92) , poldek.h (1.34 -> 1.35) , poldek_ts.c (1.59 -> 1.60) , poldek_ts.h (1.36 -> 1.37) 
poldek/poldek/cli:
   op_verify.c (1.15 -> 1.16) 

---- Diffs:

================================================================
Index: poldek/poldek/pkgset.c
diff -u poldek/poldek/pkgset.c:1.91 poldek/poldek/pkgset.c:1.92
--- poldek/poldek/pkgset.c:1.91	Mon Jan  8 18:22:00 2007
+++ poldek/poldek/pkgset.c	Sun May 20 23:44:28 2007
@@ -664,3 +664,79 @@
         msgn(0, _("No unsatisfied dependencies found"));
     return nerr == 0;
 }
+
+int packages_dot_dependency_graph(tn_array *pkgs, struct pkgset *ps,
+                                  const char *dotfile)
+{
+    int i, j, n_unmet = 0;
+    tn_buf *nbuf;
+    tn_array *errs;
+    FILE *stream;
+
+    nbuf = n_buf_new(1024 * 8);
+    
+    for (i=0; i < n_array_size(pkgs); i++) {
+        struct pkg *pkg = n_array_nth(pkgs, i);
+
+        if ((errs = pkgset_get_unsatisfied_reqs(ps, pkg))) {
+            for (j=0; j < n_array_size(errs); j++) {
+                struct pkg_unreq *unreq = n_array_nth(errs, j);
+                n_buf_printf(nbuf, "\"%s\" -> \"UNMET\" [ label = \"%s\" ];\n",
+                             pkg_id(pkg), unreq->req);
+                n_unmet++;
+            }
+        }
+        
+        if (pkg->reqpkgs == NULL || n_array_size(pkg->reqpkgs) == 0) {
+            n_buf_printf(nbuf, "\"%s\";\n", pkg_id(pkg));
+            continue;
+        }
+        
+        for (j=0; j < n_array_size(pkg->reqpkgs); j++) {
+            struct reqpkg *rp = n_array_nth(pkg->reqpkgs, j);
+
+            n_buf_printf(nbuf, "\"%s\" -> \"%s\" [ label = \"%s\" ];\n",
+                         pkg_id(pkg), pkg_id(rp->pkg), capreq_snprintf_s(rp->req));
+            
+            if (rp->flags & REQPKG_MULTI) {
+                int n = 0;
+                while (rp->adds[n]) {
+                    n_buf_printf(nbuf, "\"%s\" -> \"%s\" [ label = \"%s\" ];\n",
+                                 pkg_id(pkg), pkg_id(rp->adds[n]->pkg),
+                                 capreq_snprintf_s(rp->req));
+                    n++;
+                }
+            }
+        }
+        
+        
+    }
+
+    if ((stream = fopen(dotfile, "w")) == NULL) {
+        logn(LOGERR, _("%s: open failed: %m"), dotfile);
+        n_buf_free(nbuf);
+        return 0;
+    }
+
+    fprintf(stream, "digraph repo {\n"
+            "rankdir=LR;\n"
+            "ordering=out\n"
+            "mclimit=2.0\n"
+            "charset=\"utf-8\"\n"
+            "graph [fontsize=10];\n"
+            "edge  [fontsize=8,color=\"gray\"]\n"
+            "node  [fontsize=10];\n"
+            "node [shape = ellipse];\n");
+
+    if (n_unmet > 0) 
+        fprintf(stream, "node [shape = box] UNMET;\nnode [shape = ellipse];\n");
+
+    fprintf(stream, "%s", (char*)n_buf_ptr(nbuf));
+    fprintf(stream, "\n}\n");
+    fclose(stream);
+    n_buf_free(nbuf);
+    msgn(0, "Graph saved as %s\n", dotfile);
+    return 1;
+}
+
+

================================================================
Index: poldek/poldek/poldek.h
diff -u poldek/poldek/poldek.h:1.34 poldek/poldek/poldek.h:1.35
--- poldek/poldek/poldek.h:1.34	Sun Aug 20 20:14:58 2006
+++ poldek/poldek/poldek.h	Sun May 20 23:44:28 2007
@@ -34,6 +34,7 @@
 #define POLDEK_CONF_IGNORE          12
 #define POLDEK_CONF_PM              13
 #define POLDEK_CONF_DESTINATION     14
+#define POLDEK_CONF_DEPGRAPHFILE    15
 
 #define POLDEK_CONF_LOGFILE         20
 #define POLDEK_CONF_LOGTTY          21

================================================================
Index: poldek/poldek/poldek_ts.c
diff -u poldek/poldek/poldek_ts.c:1.59 poldek/poldek/poldek_ts.c:1.60
--- poldek/poldek/poldek_ts.c:1.59	Sun Dec 17 18:33:25 2006
+++ poldek/poldek/poldek_ts.c	Sun May 20 23:44:28 2007
@@ -261,6 +261,7 @@
         cp_str(&ts->cachedir, ctx->ts->cachedir);
         cp_str(&ts->dumpfile, ctx->ts->dumpfile);
         cp_str(&ts->prifile, ctx->ts->prifile);
+        cp_str(&ts->depgraphfile, ctx->ts->depgraphfile);
         
         ts->rpmacros = n_array_dup(ctx->ts->rpmacros, (tn_fn_dup)strdup);
         ts->rpmopts = n_array_dup(ctx->ts->rpmopts, (tn_fn_dup)strdup);
@@ -496,6 +497,13 @@
                 ts->prifile = poldek__conf_path(ts->prifile, vs);
             }
             break;
+
+        case POLDEK_CONF_DEPGRAPHFILE:
+            if ((vs = va_arg(ap, char*))) {
+                DBGF("dotfile %s\n", vs);
+                ts->depgraphfile = poldek__conf_path(ts->depgraphfile, vs);
+            }
+            break;
         
         case POLDEK_CONF_RPMMACROS:
             if ((vs = va_arg(ap, char*)))
@@ -1116,6 +1124,12 @@
     if (ts->getop(ts, POLDEK_OP_VRFY_DEPS)) {
         msgn(0, _("Verifying dependencies..."));
         if (!packages_verify_dependecies(pkgs, ts->ctx->ps))
+            nerr++;
+    }
+
+    if (ts->getop(ts, POLDEK_OP_DEPGRAPH)) {
+        msgn(0, _("Dotting dependency graph..."));
+        if (!packages_dot_dependency_graph(pkgs, ts->ctx->ps, ts->depgraphfile))
             nerr++;
     }
 

================================================================
Index: poldek/poldek/poldek_ts.h
diff -u poldek/poldek/poldek_ts.h:1.36 poldek/poldek/poldek_ts.h:1.37
--- poldek/poldek/poldek_ts.h:1.36	Sun Dec 17 22:53:37 2006
+++ poldek/poldek/poldek_ts.h	Sun May 20 23:44:28 2007
@@ -34,6 +34,7 @@
     POLDEK_OP_VRFY_FILECNFLS,    /* --verify=file-conflicts */
     POLDEK_OP_VRFY_FILEORPHANS,  /* --verify=file-orphans */
     POLDEK_OP_VRFY_FILEMISSDEPS, /* --verify=file-missing-deps */
+    POLDEK_OP_DEPGRAPH,          /* --dependency-graph */
 
     POLDEK_OP_LDFULLFILELIST,    /* internal, load whole file database */
     
@@ -109,6 +110,7 @@
     char               *cachedir;      /* cache directory        */
     char               *dumpfile;      /* file to dump fqpns     */
     char               *prifile;       /* file with package priorities (split*) */
+    char               *depgraphfile;  /* dot file path for graphviz depgraph */
     tn_array           *rpmopts;       /* rpm cmdline opts (char *opts[]) */
     tn_array           *rpmacros;      /* rpm macros to pass to cmdline (char *opts[]) */
     tn_array           *hold_patterns;

================================================================
Index: poldek/poldek/cli/op_verify.c
diff -u poldek/poldek/cli/op_verify.c:1.15 poldek/poldek/cli/op_verify.c:1.16
--- poldek/poldek/cli/op_verify.c:1.15	Sun Dec 17 18:33:25 2006
+++ poldek/poldek/cli/op_verify.c	Sun May 20 23:44:28 2007
@@ -42,6 +42,7 @@
 #define OPT_FILECNFLS   (OPT_GID + 2)
 #define OPT_FILEORPHANS (OPT_GID + 3)
 #define OPT_ALL         (OPT_GID + 4)
+#define OPT_DEPGRAPH    (OPT_GID + 5)
 
 /* The options we understand. */
 static struct argp_option options[] = {
@@ -59,7 +60,8 @@
     
 {"verify-all",  OPT_ALL, 0, OPTION_HIDDEN,
 N_("Verify dependencies, conflicts, file conflicts and orphaned directories"),
-     OPT_GID },
+        OPT_GID },
+{"dependency-graph", OPT_DEPGRAPH, "FILE", 0, N_("Print dot dependency graph into FILE"), OPT_GID },
 { 0, 0, 0, 0, 0, 0 },
 };
 
@@ -207,6 +209,13 @@
             ts->setop(ts, POLDEK_OP_VRFY_FILECNFLS, 1);
             ts->setop(ts, POLDEK_OP_VRFY_FILEORPHANS, 1);
             rt->set_major_mode(rt, mode, "verify-all");
+            break;
+
+        case OPT_DEPGRAPH:
+            arg_s->verify = 1;
+            ts->setop(ts, POLDEK_OP_DEPGRAPH, 1);
+            rt->set_major_mode(rt, mode, "depgraph");
+            poldek_ts_configure(ts, POLDEK_CONF_DEPGRAPHFILE, arg);
             break;
 
         default:
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/poldek/poldek/pkgset.c?r1=1.91&r2=1.92&f=u
    http://cvs.pld-linux.org/poldek/poldek/poldek.h?r1=1.34&r2=1.35&f=u
    http://cvs.pld-linux.org/poldek/poldek/poldek_ts.c?r1=1.59&r2=1.60&f=u
    http://cvs.pld-linux.org/poldek/poldek/poldek_ts.h?r1=1.36&r2=1.37&f=u
    http://cvs.pld-linux.org/poldek/poldek/cli/op_verify.c?r1=1.15&r2=1.16&f=u



More information about the pld-cvs-commit mailing list