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 (i = 0, data = repo->repodata; i < repo->nrepodata; 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", id2str(repo->pool, data->keys[j].name), 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", dep2str(pool, id));
60 dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv)
66 keyname = 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 = id2str(repo->pool, kv->id);
76 printf("%s: %s\n", keyname, kv->str);
78 case REPOKEY_TYPE_CONSTANTID:
79 printf("%s: %s\n", keyname, 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", 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), 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_DIRNUMNUMARRAY:
107 printf("%s:\n%*s", keyname, indent, "");
108 printf(" %s %d %d\n", repodata_dir2str(data, kv->id, 0), kv->num, kv->num2);
110 case REPOKEY_TYPE_DIRSTRARRAY:
112 printf("%s:\n%*s", keyname, indent, "");
113 printf(" %s\n", repodata_dir2str(data, kv->id, kv->str));
115 case REPOKEY_TYPE_FIXARRAY:
116 case REPOKEY_TYPE_FLEXARRAY:
118 printf("%s:\n", keyname);
123 printf("%s: ?\n", keyname);
131 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
133 if (key->name == REPOSITORY_SOLVABLES)
134 return SEARCH_NEXT_SOLVABLE;
135 return dump_attr(data->repo, data, key, kv);
140 * dump all attributes for Id <p>
144 dump_repoattrs(Repo *repo, Id p)
147 repo_search(repo, p, 0, 0, SEARCH_ARRAYSENTINEL|SEARCH_SUB, dump_repoattrs_cb, 0);
150 dataiterator_init(&di, repo->pool, repo, p, 0, 0, SEARCH_ARRAYSENTINEL|SEARCH_SUB);
151 while (dataiterator_step(&di))
152 dump_attr(repo, di.data, di.key, &di.kv);
158 dump_some_attrs(Repo *repo, Solvable *s)
160 const char *summary = 0;
161 unsigned int medianr = -1, downloadsize = -1;
162 unsigned int time = -1;
163 summary = repo_lookup_str(s, SOLVABLE_SUMMARY);
164 medianr = repo_lookup_num(s, SOLVABLE_MEDIANR);
165 downloadsize = repo_lookup_num (s, SOLVABLE_DOWNLOADSIZE);
166 time = repo_lookup_num(s, SOLVABLE_BUILDTIME);
167 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
173 loadcallback (Pool *pool, Repodata *data, void *vdata)
176 printf("LOADCALLBACK\n");
177 const char *location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION);
178 printf("loc %s\n", location);
179 if (location && with_attr)
181 fprintf (stderr, "Loading SOLV file %s\n", location);
182 fp = fopen (location, "r");
191 usage( const char *err )
194 fprintf (stderr, "\n** Error:\n %s\n", err);
195 fprintf( stderr, "\nUsage:\n"
196 "dumpsolv [-a] [<solvfile>]\n"
197 " -a read attributes.\n"
204 tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
207 dataiterator_init(&di, repo, p, keyname, match, flags);
208 while (dataiterator_step(&di))
210 switch (di.key->type)
212 case REPOKEY_TYPE_ID:
213 case REPOKEY_TYPE_IDARRAY:
214 if (di.data && di.data->localpool)
215 di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
217 di.kv.str = id2str(repo->pool, di.kv.id);
219 case REPOKEY_TYPE_STR:
220 case REPOKEY_TYPE_DIRSTRARRAY:
225 fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
227 id2str(repo->pool, di.key->name),
229 di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
234 int main(int argc, char **argv)
241 pool = pool_create();
242 pool_setdebuglevel(pool, 1);
243 pool_setloadcallback(pool, loadcallback, 0);
249 const char *s = argv[0];
254 case 'h': usage(NULL); break;
255 case 'a': with_attr = 1; break;
260 if (freopen (argv[0], "r", stdin) == 0)
265 repo = repo_create(pool, argv[0]);
266 if (repo_add_solv(repo, stdin))
267 printf("could not read repository\n");
274 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
275 if (repo_add_solv(repo, stdin))
276 printf("could not read repository\n");
278 printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
283 dataiterator_init(&di, repo, -1, 0, "oo", DI_SEARCHSUB|SEARCH_SUBSTRING);
284 while (dataiterator_step(&di))
285 dump_attr(di.repo, di.data, di.key, &di.kv);
290 for (j = 0; 1 && j < pool->nrepos; j++)
292 repo = pool->repos[j];
295 printf("repo %d contains %d solvables\n", j, repo->nsolvables);
296 printf("repo start: %d end: %d\n", repo->start, repo->end);
297 for (i = repo->start, n = 1; i < repo->end; i++)
299 s = pool->solvables + i;
303 printf("solvable %d (%d):\n", n, i);
305 if (s->name || s->evr || s->arch)
306 printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
308 printf("vendor: %s\n", id2str(pool, s->vendor));
309 printids(repo, "provides", s->provides);
310 printids(repo, "obsoletes", s->obsoletes);
311 printids(repo, "conflicts", s->conflicts);
312 printids(repo, "requires", s->requires);
313 printids(repo, "recommends", s->recommends);
314 printids(repo, "suggests", s->suggests);
315 printids(repo, "supplements", s->supplements);
316 printids(repo, "enhances", s->enhances);
318 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
320 dump_attrs (repo, n - 1);
323 dump_repoattrs(repo, i);
325 dump_some_attrs(repo, s);
330 tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
332 tryme(repo, 0, 0, 0, 0);
334 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);
338 printf ("\nSearchresults:\n");
340 dataiterator_init(&di, pool, 0, 0, 0, "3", SEARCH_SUB | SEARCH_SUBSTRING | SEARCH_FILES);
342 while (dataiterator_step(&di))
344 printf("%d:", di.solvid);
345 dump_attr(repo, di.data, di.key, &di.kv);
346 /*if (di.solvid == 4 && count++ == 0)
347 dataiterator_jump_to_solvable(&di, pool->solvables + 3);*/
348 //dataiterator_skip_attribute(&di);
349 //dataiterator_skip_solvable(&di);
350 //dataiterator_skip_repo(&di);