2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
10 #include <sys/types.h>
19 #include "repo_solv.h"
20 #include "repo_susetags.h"
21 #include "repo_content.h"
23 #include "repo_autopattern.h"
25 #include "common_write.h"
26 #include "solv_xfopen.h"
31 fprintf(stderr, "\nUsage:\n"
32 "susetags2solv [-c <content>][-d <descrdir>][-h][-n <name>]\n"
33 " reads a 'susetags' repository from <stdin> and writes a .solv file to <stdout>\n"
34 " -c <contentfile> : parse given contentfile (for product information)\n"
35 " -d <descrdir> : do not read from stdin, but use data in descrdir\n"
36 " -h : print help & exit\n"
41 /* content file query */
43 doquery(Pool *pool, Repo *repo, const char *arg)
49 snprintf(qbuf, sizeof(qbuf), "susetags:%s", arg);
50 id = pool_str2id(pool, qbuf, 0);
53 str = repo_lookup_str(repo, SOLVID_META, id);
59 main(int argc, char **argv)
61 const char *contentfile = 0;
62 const char *descrdir = 0;
63 const char *query = 0;
64 const char *mergefile = 0;
74 while ((c = getopt(argc, argv, "hc:d:q:M:X")) >= 0)
103 pool = pool_create();
104 repo = repo_create(pool, "<susetags>");
106 repo_add_repodata(repo, 0);
110 FILE *fp = fopen(contentfile, "r");
116 if (repo_add_content(repo, fp, REPO_REUSE_REPODATA))
118 fprintf(stderr, "susetags2solv: %s: %s\n", contentfile, pool_errstr(pool));
121 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
126 * descrdir path given, open files and read from there
133 struct dirent **files;
135 ndirs = scandir(descrdir, &files, 0, alphasort);
142 /* bring packages to front */
143 for (i = 0; i < ndirs; i++)
145 char *fn = files[i]->d_name;
146 if (!strcmp(fn, "packages") || !strcmp(fn, "packages.gz"))
151 fprintf(stderr, "found no packages file\n");
156 struct dirent *de = files[i];
157 memmove(files + 1, files, i * sizeof(de));
161 fnp = solv_malloc(strlen(descrdir) + 128);
162 for (i = 0; i < ndirs; i++)
164 char *fn = files[i]->d_name;
166 if (!strcmp(fn, "packages") || !strcmp(fn, "packages.gz"))
169 sprintf(fnp, "%s/%s", descrdir, fn);
170 fp = solv_xfopen(fnp, 0);
176 if (repo_add_susetags(repo, fp, defvendor, 0, flags | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | SUSETAGS_RECORD_SHARES))
178 fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool));
183 else if (!strcmp(fn, "packages.DU") || !strcmp(fn, "packages.DU.gz"))
186 sprintf(fnp, "%s/%s", descrdir, fn);
187 fp = solv_xfopen(fnp, 0);
193 if (repo_add_susetags(repo, fp, defvendor, 0, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
195 fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool));
200 else if (!strcmp(fn, "packages.FL") || !strcmp(fn, "packages.FL.gz"))
203 sprintf(fnp, "%s/%s", descrdir, fn);
204 FILE *fp = solv_xfopen(fnp, 0);
210 if (repo_add_susetags(repo, fp, defvendor, 0, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
212 fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool));
217 /* ignore for now. reactivate when filters work */
221 else if (!strncmp(fn, "packages.", 9))
226 sprintf(fnp, "%s/%s", descrdir, fn);
227 p = strrchr(fnp, '.');
228 if (p && !strcmp(p, ".gz"))
231 p = strrchr(fnp, '.');
233 if (!p || !p[1] || strlen(p + 1) > 5)
236 sprintf(fnp, "%s/%s", descrdir, fn);
237 fp = solv_xfopen(fnp, 0);
243 if (repo_add_susetags(repo, fp, defvendor, lang, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
245 fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool));
251 for (i = 0; i < ndirs; i++)
255 repo_internalize(repo);
259 /* read data from stdin */
260 if (repo_add_susetags(repo, stdin, defvendor, 0, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
262 fprintf(stderr, "susetags2solv: %s\n", pool_errstr(pool));
266 repo_internalize(repo);
269 FILE *fp = fopen(mergefile, "r");
275 if (repo_add_solv(repo, fp, 0))
277 fprintf(stderr, "susetags2solv: %s\n", pool_errstr(pool));
284 repo_add_autopattern(repo, 0);
288 doquery(pool, repo, query);
290 tool_write(repo, stdout);