2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 static int with_attr = 0;
16 #include "repo_solv.h"
18 static int dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv);
21 dump_repodata (Repo *repo)
25 if (repo->nrepodata == 0)
27 for (i = 0; i < 32; i++)
28 if (repo->rpmdbcookie[i])
32 printf("rpmdb cookie: ");
33 for (i = 0; i < 32; i++)
34 printf("%02x", repo->rpmdbcookie[i]);
37 printf("repo contains %d repodata sections:\n", repo->nrepodata);
38 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
41 printf("\nrepodata %d has %d keys, %d schemata\n", i + 1, data->nkeys - 1, data->nschemata - 1);
42 for (j = 1; j < data->nkeys; j++)
43 printf(" %s (type %s size %d storage %d)\n", id2str(repo->pool, data->keys[j].name), id2str(repo->pool, data->keys[j].type), data->keys[j].size, data->keys[j].storage);
45 printf(" localpool has %d strings, size is %d\n", data->spool.nstrings, data->spool.sstrings);
46 if (data->dirpool.ndirs)
47 printf(" localpool has %d directories\n", data->dirpool.ndirs);
49 repodata_search(data, REPOENTRY_META, 0, dump_repoattrs_cb, 0);
55 printids(Repo *repo, char *kind, Offset ido)
57 Pool *pool = repo->pool;
61 printf("%s:\n", kind);
62 ids = repo->idarraydata + ido;
63 while((id = *ids++) != 0)
64 printf(" %s\n", dep2str(pool, id));
68 dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv)
74 keyname = id2str(repo->pool, key->name);
75 for (kvp = kv; (kvp = kvp->path) != 0; indent += 2)
80 if (data && data->localpool)
81 kv->str = stringpool_id2str(&data->spool, kv->id);
83 kv->str = id2str(repo->pool, kv->id);
84 printf("%s: %s\n", keyname, kv->str);
86 case REPOKEY_TYPE_CONSTANTID:
87 printf("%s: %s\n", keyname, dep2str(repo->pool, kv->id));
89 case REPOKEY_TYPE_IDARRAY:
91 printf("%s:\n%*s", keyname, indent, "");
92 if (data && data->localpool)
93 printf(" %s\n", stringpool_id2str(&data->spool, kv->id));
95 printf(" %s\n", dep2str(repo->pool, kv->id));
97 case REPOKEY_TYPE_STR:
98 printf("%s: %s\n", keyname, kv->str);
100 case REPOKEY_TYPE_MD5:
101 case REPOKEY_TYPE_SHA1:
102 case REPOKEY_TYPE_SHA256:
103 printf("%s: %s (%s)\n", keyname, repodata_chk2str(data, key->type, (unsigned char *)kv->str), id2str(repo->pool, key->type));
105 case REPOKEY_TYPE_VOID:
106 printf("%s: (void)\n", keyname);
108 case REPOKEY_TYPE_U32:
109 case REPOKEY_TYPE_NUM:
110 case REPOKEY_TYPE_CONSTANT:
111 printf("%s: %d\n", keyname, kv->num);
113 case REPOKEY_TYPE_DIRNUMNUMARRAY:
115 printf("%s:\n%*s", keyname, indent, "");
116 printf(" %s %d %d\n", repodata_dir2str(data, kv->id, 0), kv->num, kv->num2);
118 case REPOKEY_TYPE_DIRSTRARRAY:
120 printf("%s:\n%*s", keyname, indent, "");
121 printf(" %s\n", repodata_dir2str(data, kv->id, kv->str));
123 case REPOKEY_TYPE_FIXARRAY:
124 case REPOKEY_TYPE_FLEXARRAY:
126 printf("%s:\n", keyname);
131 printf("%s: ?\n", keyname);
139 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
141 if (key->name == REPOSITORY_SOLVABLES)
142 return SEARCH_NEXT_SOLVABLE;
143 return dump_attr(data->repo, data, key, kv);
148 * dump all attributes for Id <p>
152 dump_repoattrs(Repo *repo, Id p)
155 repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
158 dataiterator_init(&di, repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE);
159 while (dataiterator_step(&di))
160 dump_attr(repo, di.data, di.key, &di.kv);
166 dump_some_attrs(Repo *repo, Solvable *s)
168 const char *summary = 0;
169 unsigned int medianr = -1, downloadsize = -1;
170 unsigned int time = -1;
171 summary = repo_lookup_str(s, SOLVABLE_SUMMARY);
172 medianr = repo_lookup_num(s, SOLVABLE_MEDIANR);
173 downloadsize = repo_lookup_num (s, SOLVABLE_DOWNLOADSIZE);
174 time = repo_lookup_num(s, SOLVABLE_BUILDTIME);
175 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
181 loadcallback (Pool *pool, Repodata *data, void *vdata)
184 printf("LOADCALLBACK\n");
185 const char *location = repodata_lookup_str(data, REPOENTRY_META, REPOSITORY_LOCATION);
186 printf("loc %s\n", location);
187 if (location && with_attr)
189 fprintf (stderr, "Loading SOLV file %s\n", location);
190 fp = fopen (location, "r");
199 usage( const char *err )
202 fprintf (stderr, "\n** Error:\n %s\n", err);
203 fprintf( stderr, "\nUsage:\n"
204 "dumpsolv [-a] [<solvfile>]\n"
205 " -a read attributes.\n"
212 tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
215 dataiterator_init(&di, repo, p, keyname, match, flags);
216 while (dataiterator_step(&di))
218 switch (di.key->type)
220 case REPOKEY_TYPE_ID:
221 case REPOKEY_TYPE_IDARRAY:
222 if (di.data && di.data->localpool)
223 di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
225 di.kv.str = id2str(repo->pool, di.kv.id);
227 case REPOKEY_TYPE_STR:
228 case REPOKEY_TYPE_DIRSTRARRAY:
233 fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
235 id2str(repo->pool, di.key->name),
237 di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
242 int main(int argc, char **argv)
249 pool = pool_create();
250 pool_setdebuglevel(pool, 1);
251 pool_setloadcallback(pool, loadcallback, 0);
257 const char *s = argv[0];
262 case 'h': usage(NULL); break;
263 case 'a': with_attr = 1; break;
268 if (freopen (argv[0], "r", stdin) == 0)
273 repo = repo_create(pool, argv[0]);
274 if (repo_add_solv(repo, stdin))
275 printf("could not read repository\n");
282 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
283 if (repo_add_solv(repo, stdin))
284 printf("could not read repository\n");
286 printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
291 dataiterator_init(&di, repo, -1, 0, "oo", DI_SEARCHSUB|SEARCH_SUBSTRING);
292 while (dataiterator_step(&di))
293 dump_attr(di.repo, di.data, di.key, &di.kv);
298 for (j = 0; 1 && j < pool->nrepos; j++)
300 repo = pool->repos[j];
303 printf("repo %d contains %d solvables %d non-solvables\n", j, repo->nsolvables, repo->nextra);
304 printf("repo start: %d end: %d\n", repo->start, repo->end);
305 for (i = repo->start, n = 1; i < repo->end; i++)
307 s = pool->solvables + i;
311 printf("solvable %d (%d):\n", n, i);
312 if (s->name || s->evr || s->arch)
313 printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
315 printf("vendor: %s\n", id2str(pool, s->vendor));
316 printids(repo, "provides", s->provides);
317 printids(repo, "obsoletes", s->obsoletes);
318 printids(repo, "conflicts", s->conflicts);
319 printids(repo, "requires", s->requires);
320 printids(repo, "recommends", s->recommends);
321 printids(repo, "suggests", s->suggests);
322 printids(repo, "supplements", s->supplements);
323 printids(repo, "enhances", s->enhances);
325 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
327 dump_attrs (repo, n - 1);
329 dump_repoattrs(repo, i);
331 dump_some_attrs(repo, s);
335 for (i = 0; i < repo->nextra; i++)
337 printf("\nextra %d:\n", i);
339 dataiterator_init(&di, repo, -1 - i, 0, 0, SEARCH_EXTRA | SEARCH_NO_STORAGE_SOLVABLE);
340 while (dataiterator_step(&di))
341 dump_attr(repo, di.data, di.key, &di.kv);
344 tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
346 tryme(repo, 0, 0, 0, 0);
348 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);
352 printf ("\nSearchresults:\n");
354 dataiterator_init(&di, pool->repos[0], 0, 0, "3", SEARCH_EXTRA | SEARCH_SUBSTRING | SEARCH_ALL_REPOS | SEARCH_FILES);
356 while (dataiterator_step(&di))
358 printf("%d:", di.solvid);
359 dump_attr(repo, di.data, di.key, &di.kv);
360 /*if (di.solvid == 4 && count++ == 0)
361 dataiterator_jump_to_solvable(&di, pool->solvables + 3);*/
362 //dataiterator_skip_attribute(&di);
363 //dataiterator_skip_solvable(&di);
364 //dataiterator_skip_repo(&di);