adapt repo_products (/etc/products.d/*.prod parsing) to current definition
[platform/upstream/libsolv.git] / tools / rpmdb2solv.c
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * rpmdb2solv
10  * 
11  * Reads rpm database (and evtl. more, like product metadata) to build
12  * a .solv file of 'installed' solvables.
13  * 
14  */
15
16 #include <sys/types.h>
17 #include <limits.h>
18 #include <fcntl.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23
24 #include "pool.h"
25 #include "repo.h"
26 #include "repo_rpmdb.h"
27 #include "repo_products.h"
28 #include "repo_solv.h"
29 #include "common_write.h"
30
31 int
32 main(int argc, char **argv)
33 {
34   Pool *pool = pool_create();
35   Repo *repo, *ref = 0;
36   Repodata *repodata;
37   FILE *fp;
38   Pool *refpool;
39   int c;
40   int extrapool = 0;
41   int nopacks = 0;
42   const char *root = 0;
43   const char *basefile = 0;
44   const char *proddir = 0;
45
46   /*
47    * parse arguments
48    */
49   
50   while ((c = getopt (argc, argv, "nxb:r:p:")) >= 0)
51     switch (c)
52       {
53       case 'r':
54         root = optarg;
55         break;
56       case 'b':
57         basefile = optarg;
58         break;
59       case 'n':
60         nopacks = 1;
61         break;
62       case 'p':
63         proddir = optarg;
64         break;
65       case 'x':
66         extrapool = 1;
67         break;
68       default:
69         exit(1);
70       }
71   
72   /*
73    * ???
74    */
75   
76   if (optind < argc)
77     {
78       if (extrapool)
79         refpool = pool_create();
80       else
81         refpool = pool;
82       if ((fp = fopen(argv[optind], "r")) == NULL)
83         {
84           perror(argv[optind]);
85           exit(1);
86         }
87       ref = repo_create(refpool, "ref");
88       repo_add_solv(ref, fp);
89       repo_disable_paging(ref);
90       fclose(fp);
91     }
92
93   /*
94    * create 'installed' repository
95    * add products
96    * add rpmdb
97    * write .solv
98    */
99
100   repo = repo_create(pool, "installed");
101   repodata = repo_add_repodata(repo, 0);
102
103   if (!nopacks)
104     repo_add_rpmdb(repo, repodata, ref, root);
105
106   if (proddir)
107     repo_add_products(repo, repodata, proddir);
108
109   if (repodata)
110     repodata_internalize(repodata);
111
112   if (ref)
113     {
114       if (ref->pool != pool)
115         pool_free(ref->pool);
116       else
117         repo_free(ref, 1);
118       ref = 0;
119     }
120
121   tool_write(repo, basefile, 0);
122   pool_free(pool);
123
124   exit(0);
125 }