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_id2str(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_NUM:
102 case REPOKEY_TYPE_CONSTANT:
103 printf("%s: %d\n", keyname, kv->num);
105 case REPOKEY_TYPE_BINARY:
107 printf("%s: %02x..%02x len %d\n", keyname, (unsigned char)kv->str[0], (unsigned char)kv->str[kv->num - 1], kv->num);
109 printf("%s: len 0\n", keyname);
111 case REPOKEY_TYPE_DIRNUMNUMARRAY:
113 printf("%s:\n%*s", keyname, indent, "");
114 printf(" %s %d %d\n", repodata_dir2str(data, kv->id, 0), kv->num, kv->num2);
116 case REPOKEY_TYPE_DIRSTRARRAY:
118 printf("%s:\n%*s", keyname, indent, "");
119 printf(" %s\n", repodata_dir2str(data, kv->id, kv->str));
121 case REPOKEY_TYPE_FIXARRAY:
122 case REPOKEY_TYPE_FLEXARRAY:
124 printf("%s:\n", keyname);
129 printf("%s: ?\n", keyname);
137 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
139 if (key->name == REPOSITORY_SOLVABLES)
140 return SEARCH_NEXT_SOLVABLE;
141 return dump_attr(data->repo, data, key, kv);
146 * dump all attributes for Id <p>
150 dump_repoattrs(Repo *repo, Id p)
153 repo_search(repo, p, 0, 0, SEARCH_ARRAYSENTINEL|SEARCH_SUB, dump_repoattrs_cb, 0);
156 dataiterator_init(&di, repo->pool, repo, p, 0, 0, SEARCH_ARRAYSENTINEL|SEARCH_SUB);
157 while (dataiterator_step(&di))
158 dump_attr(repo, di.data, di.key, &di.kv);
164 dump_some_attrs(Repo *repo, Solvable *s)
166 const char *summary = 0;
167 unsigned int medianr = -1, downloadsize = -1;
168 unsigned int time = -1;
169 summary = repo_lookup_str(s, SOLVABLE_SUMMARY);
170 medianr = repo_lookup_num(s, SOLVABLE_MEDIANR);
171 downloadsize = repo_lookup_num (s, SOLVABLE_DOWNLOADSIZE);
172 time = repo_lookup_num(s, SOLVABLE_BUILDTIME);
173 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
179 loadcallback (Pool *pool, Repodata *data, void *vdata)
183 const char *location;
185 printf("LOADCALLBACK\n");
186 location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION);
187 printf("loc %s\n", location);
188 if (!location || !with_attr)
190 fprintf (stderr, "Loading SOLV file %s\n", location);
191 fp = fopen (location, "r");
197 r = repo_add_solv_flags(data->repo, fp, REPO_USE_LOADING|REPO_LOCALPOOL);
206 fprintf( stderr, "\nUsage:\n"
207 "dumpsolv [-a] [<solvfile>]\n"
208 " -a read attributes.\n"
215 tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
218 dataiterator_init(&di, repo, p, keyname, match, flags);
219 while (dataiterator_step(&di))
221 switch (di.key->type)
223 case REPOKEY_TYPE_ID:
224 case REPOKEY_TYPE_IDARRAY:
225 if (di.data && di.data->localpool)
226 di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
228 di.kv.str = pool_id2str(repo->pool, di.kv.id);
230 case REPOKEY_TYPE_STR:
231 case REPOKEY_TYPE_DIRSTRARRAY:
236 fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
238 pool_id2str(repo->pool, di.key->name),
240 di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
245 int main(int argc, char **argv)
252 pool = pool_create();
253 pool_setdebuglevel(pool, 1);
254 pool_setloadcallback(pool, loadcallback, 0);
256 while ((c = getopt(argc, argv, "ha")) >= 0)
271 for (; optind < argc; optind++)
273 if (freopen(argv[optind], "r", stdin) == 0)
275 perror(argv[optind]);
278 repo = repo_create(pool, argv[optind]);
279 if (repo_add_solv(repo, stdin))
280 printf("could not read repository\n");
284 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
285 if (repo_add_solv(repo, stdin))
286 printf("could not read repository\n");
288 printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
293 dataiterator_init(&di, repo, -1, 0, "oo", DI_SEARCHSUB|SEARCH_SUBSTRING);
294 while (dataiterator_step(&di))
295 dump_attr(di.repo, di.data, di.key, &di.kv);
305 printf("repo %d contains %d solvables\n", j, repo->nsolvables);
306 printf("repo start: %d end: %d\n", repo->start, repo->end);
307 FOR_REPO_SOLVABLES(repo, i, s)
311 printf("solvable %d (%d):\n", n, i);
313 if (s->name || s->evr || s->arch)
314 printf("name: %s %s %s\n", pool_id2str(pool, s->name), pool_id2str(pool, s->evr), pool_id2str(pool, s->arch));
316 printf("vendor: %s\n", pool_id2str(pool, s->vendor));
317 printids(repo, "provides", s->provides);
318 printids(repo, "obsoletes", s->obsoletes);
319 printids(repo, "conflicts", s->conflicts);
320 printids(repo, "requires", s->requires);
321 printids(repo, "recommends", s->recommends);
322 printids(repo, "suggests", s->suggests);
323 printids(repo, "supplements", s->supplements);
324 printids(repo, "enhances", s->enhances);
326 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
328 dump_repoattrs(repo, i);
330 dump_some_attrs(repo, s);
334 tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
336 tryme(repo, 0, 0, 0, 0);
338 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);
342 printf ("\nSearchresults:\n");
344 dataiterator_init(&di, pool, 0, 0, 0, "3", SEARCH_SUB | SEARCH_SUBSTRING | SEARCH_FILES);
346 while (dataiterator_step(&di))
348 printf("%d:", di.solvid);
349 dump_attr(repo, di.data, di.key, &di.kv);
350 /*if (di.solvid == 4 && count++ == 0)
351 dataiterator_jump_to_solvable(&di, pool->solvables + 3);*/
352 /* dataiterator_skip_attribute(&di); */
353 /* dataiterator_skip_solvable(&di); */
354 /* dataiterator_skip_repo(&di); */