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 printf("repo contains %d repodata sections:\n", repo->nrepodata);
28 FOR_REPODATAS(repo, i, data)
31 printf("\nrepodata %d has %d keys, %d schemata\n", i + 1, data->nkeys - 1, data->nschemata - 1);
32 for (j = 1; j < data->nkeys; j++)
33 printf(" %s (type %s size %d storage %d)\n", pool_id2str(repo->pool, data->keys[j].name), pool_id2str(repo->pool, data->keys[j].type), data->keys[j].size, data->keys[j].storage);
35 printf(" localpool has %d strings, size is %d\n", data->spool.nstrings, data->spool.sstrings);
36 if (data->dirpool.ndirs)
37 printf(" localpool has %d directories\n", data->dirpool.ndirs);
39 repodata_search(data, SOLVID_META, 0, SEARCH_ARRAYSENTINEL|SEARCH_SUB, dump_repoattrs_cb, 0);
46 printids(Repo *repo, char *kind, Offset ido)
48 Pool *pool = repo->pool;
52 printf("%s:\n", kind);
53 ids = repo->idarraydata + ido;
54 while((id = *ids++) != 0)
55 printf(" %s\n", pool_dep2str(pool, id));
60 dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv)
66 keyname = pool_id2str(repo->pool, key->name);
67 for (kvp = kv; (kvp = kvp->parent) != 0; indent += 2)
72 if (data && data->localpool)
73 kv->str = stringpool_id2str(&data->spool, kv->id);
75 kv->str = pool_dep2str(repo->pool, kv->id);
76 printf("%s: %s\n", keyname, kv->str);
78 case REPOKEY_TYPE_CONSTANTID:
79 printf("%s: %s\n", keyname, pool_dep2str(repo->pool, kv->id));
81 case REPOKEY_TYPE_IDARRAY:
83 printf("%s:\n%*s", keyname, indent, "");
84 if (data && data->localpool)
85 printf(" %s\n", stringpool_id2str(&data->spool, kv->id));
87 printf(" %s\n", pool_dep2str(repo->pool, kv->id));
89 case REPOKEY_TYPE_STR:
90 printf("%s: %s\n", keyname, kv->str);
92 case REPOKEY_TYPE_MD5:
93 case REPOKEY_TYPE_SHA1:
94 case REPOKEY_TYPE_SHA256:
95 printf("%s: %s (%s)\n", keyname, repodata_chk2str(data, key->type, (unsigned char *)kv->str), pool_id2str(repo->pool, key->type));
97 case REPOKEY_TYPE_VOID:
98 printf("%s: (void)\n", keyname);
100 case REPOKEY_TYPE_U32:
101 case REPOKEY_TYPE_CONSTANT:
102 printf("%s: %u\n", keyname, kv->num);
104 case REPOKEY_TYPE_NUM:
105 printf("%s: %llu\n", keyname, SOLV_KV_NUM64(kv));
107 case REPOKEY_TYPE_BINARY:
109 printf("%s: %02x..%02x len %u\n", keyname, (unsigned char)kv->str[0], (unsigned char)kv->str[kv->num - 1], kv->num);
111 printf("%s: len 0\n", keyname);
113 case REPOKEY_TYPE_DIRNUMNUMARRAY:
115 printf("%s:\n%*s", keyname, indent, "");
116 printf(" %s %u %u\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_ARRAYSENTINEL|SEARCH_SUB, dump_repoattrs_cb, 0);
158 dataiterator_init(&di, repo->pool, repo, p, 0, 0, SEARCH_ARRAYSENTINEL|SEARCH_SUB);
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)
185 const char *location;
187 printf("LOADCALLBACK\n");
188 location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION);
189 printf("loc %s\n", location);
190 if (!location || !with_attr)
192 fprintf (stderr, "Loading SOLV file %s\n", location);
193 fp = fopen (location, "r");
199 r = repo_add_solv(data->repo, fp, REPO_USE_LOADING|REPO_LOCALPOOL);
208 fprintf( stderr, "\nUsage:\n"
209 "dumpsolv [-a] [<solvfile>]\n"
210 " -a read attributes.\n"
217 tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
220 dataiterator_init(&di, repo, p, keyname, match, flags);
221 while (dataiterator_step(&di))
223 switch (di.key->type)
225 case REPOKEY_TYPE_ID:
226 case REPOKEY_TYPE_IDARRAY:
227 if (di.data && di.data->localpool)
228 di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
230 di.kv.str = pool_id2str(repo->pool, di.kv.id);
232 case REPOKEY_TYPE_STR:
233 case REPOKEY_TYPE_DIRSTRARRAY:
238 fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
240 pool_id2str(repo->pool, di.key->name),
242 di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
247 int main(int argc, char **argv)
254 pool = pool_create();
255 pool_setdebuglevel(pool, 1);
256 pool_setloadcallback(pool, loadcallback, 0);
258 while ((c = getopt(argc, argv, "ha")) >= 0)
273 for (; optind < argc; optind++)
275 if (freopen(argv[optind], "r", stdin) == 0)
277 perror(argv[optind]);
280 repo = repo_create(pool, argv[optind]);
281 if (repo_add_solv(repo, stdin, 0))
282 printf("could not read repository: %s\n", pool_errstr(pool));
286 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
287 if (repo_add_solv(repo, stdin, 0))
288 printf("could not read repository: %s\n", pool_errstr(pool));
290 printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
295 dataiterator_init(&di, repo, -1, 0, "oo", DI_SEARCHSUB|SEARCH_SUBSTRING);
296 while (dataiterator_step(&di))
297 dump_attr(di.repo, di.data, di.key, &di.kv);
307 printf("repo %d contains %d solvables\n", j, repo->nsolvables);
308 printf("repo start: %d end: %d\n", repo->start, repo->end);
309 FOR_REPO_SOLVABLES(repo, i, s)
313 printf("solvable %d (%d):\n", n, i);
315 if (s->name || s->evr || s->arch)
316 printf("name: %s %s %s\n", pool_id2str(pool, s->name), pool_id2str(pool, s->evr), pool_id2str(pool, s->arch));
318 printf("vendor: %s\n", pool_id2str(pool, s->vendor));
319 printids(repo, "provides", s->provides);
320 printids(repo, "obsoletes", s->obsoletes);
321 printids(repo, "conflicts", s->conflicts);
322 printids(repo, "requires", s->requires);
323 printids(repo, "recommends", s->recommends);
324 printids(repo, "suggests", s->suggests);
325 printids(repo, "supplements", s->supplements);
326 printids(repo, "enhances", s->enhances);
328 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
330 dump_repoattrs(repo, i);
332 dump_some_attrs(repo, s);
336 tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
338 tryme(repo, 0, 0, 0, 0);
340 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);
344 printf ("\nSearchresults:\n");
346 dataiterator_init(&di, pool, 0, 0, 0, "3", SEARCH_SUB | SEARCH_SUBSTRING | SEARCH_FILES);
348 while (dataiterator_step(&di))
350 printf("%d:", di.solvid);
351 dump_attr(repo, di.data, di.key, &di.kv);
352 /*if (di.solvid == 4 && count++ == 0)
353 dataiterator_jump_to_solvable(&di, pool->solvables + 3);*/
354 /* dataiterator_skip_attribute(&di); */
355 /* dataiterator_skip_solvable(&di); */
356 /* dataiterator_skip_repo(&di); */