Imported Upstream version 0.7.19
[platform/upstream/libsolv.git] / tools / rpmdb2solv.c
index aa978d8..93dd1dc 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
+#ifdef ENABLE_RPMDB_LIBRPM
+#include <rpm/rpmmacro.h>
+#endif
+
+
 #include "pool.h"
 #include "repo.h"
 #include "repo_rpmdb.h"
@@ -41,12 +46,13 @@ static void
 usage(int status)
 {
   fprintf(stderr, "\nUsage:\n"
-         "rpmdb2solv [-n] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
+         "rpmdb2solv [-P] [-C] [-n] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
          " -n : No packages, do not read rpmdb, useful to only parse products\n"
-         " -b <basefile> : Write .solv to <basefile>.solv instead of stdout\n"
          " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
          " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
          " -o <solv> : Write .solv to file instead of stdout\n"
+          " -P : print percentage done\n"
+          " -C : include the changelog\n"
         );
   exit(status);
 }
@@ -61,8 +67,9 @@ main(int argc, char **argv)
   Repodata *data;
   int c, percent = 0;
   int nopacks = 0;
+  int add_changelog = 0;
   const char *root = 0;
-  const char *basefile = 0;
+  const char *dbpath = 0;
   const char *refname = 0;
 #ifdef ENABLE_SUSEREPO
   char *proddir = 0;
@@ -82,7 +89,7 @@ main(int argc, char **argv)
    * parse arguments
    */
   
-  while ((c = getopt(argc, argv, "APhnkxXb:r:p:o:")) >= 0)
+  while ((c = getopt(argc, argv, "ACD:PhnkxXr:p:o:")) >= 0)
     switch (c)
       {
       case 'h':
@@ -91,8 +98,8 @@ main(int argc, char **argv)
       case 'r':
         root = optarg;
         break;
-      case 'b':
-        basefile = optarg;
+      case 'D':
+        dbpath = optarg;
         break;
       case 'n':
        nopacks = 1;
@@ -126,6 +133,9 @@ main(int argc, char **argv)
         pubkeys = 1;
         break;
 #endif
+      case 'C':
+       add_changelog = 1;
+       break;
       default:
        usage(1);
       }
@@ -159,13 +169,33 @@ main(int argc, char **argv)
 
   if (root && *root)
     pool_set_rootdir(pool, root);
+#ifdef ENABLE_PUBKEY
+  if (dbpath && *dbpath && (!nopacks || pubkeys))
+#else
+  if (dbpath && *dbpath && !nopacks)
+#endif
+    {
+#ifdef ENABLE_RPMDB_LIBRPM
+      char *macro = solv_dupjoin("_dbpath ", dbpath, 0);
+      rpmDefineMacro(NULL, macro, 0);
+      free(macro);
+#else
+      fprintf(stderr, "cannot set dbpath without librpm\n");
+      exit(1);
+#endif
+    }
 
   repo = repo_create(pool, "installed");
   data = repo_add_repodata(repo, 0);
 
   if (!nopacks)
     {
-      if (repo_add_rpmdb_reffp(repo, reffp, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0)))
+      int flags = REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE;
+      if (percent)
+       flags |= RPMDB_REPORT_PROGRESS;
+      if (add_changelog)
+       flags |= RPM_ADD_WITH_CHANGELOG;
+      if (repo_add_rpmdb_reffp(repo, reffp, flags))
        {
          fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
          exit(1);
@@ -220,7 +250,7 @@ main(int argc, char **argv)
     repo_add_autopattern(repo, ADD_NO_AUTOPRODUCTS);
 #endif
 
-  tool_write(repo, basefile, 0);
+  tool_write(repo, stdout);
   pool_free(pool);
   exit(0);
 }