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"
19 dump_repodata (Repo *repo)
23 if (repo->nrepodata == 0)
25 printf("repo refers to %d subfiles:\n", repo->nrepodata);
26 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
29 printf("%s has %d keys, %d schemata\n", data->location ? data->location : "**EMBED**", data->nkeys, data->nschemata);
30 for (j = 1; j < data->nkeys; j++)
31 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);
33 printf(" localpool has %d strings, size is %d\n", data->spool.nstrings, data->spool.sstrings);
34 if (data->dirpool.ndirs)
35 printf(" localpool has %d directories\n", data->dirpool.ndirs);
36 if (data->addedfileprovides)
38 printf(" added file provides:\n");
39 for (j = 0; data->addedfileprovides[j]; j++)
40 printf(" %s\n", id2str(repo->pool, data->addedfileprovides[j]));
48 printids(Repo *repo, char *kind, Offset ido)
50 Pool *pool = repo->pool;
54 printf("%s:\n", kind);
55 ids = repo->idarraydata + ido;
56 while((id = *ids++) != 0)
57 printf(" %s\n", dep2str(pool, id));
61 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
65 keyname = id2str(s->repo->pool, key->name);
69 if (data && data->localpool)
70 kv->str = stringpool_id2str(&data->spool, kv->id);
72 kv->str = id2str(s->repo->pool, kv->id);
73 printf("%s: %s\n", keyname, kv->str);
75 case REPOKEY_TYPE_CONSTANTID:
76 printf("%s: %s\n", keyname, dep2str(s->repo->pool, kv->id));
78 case REPOKEY_TYPE_IDARRAY:
79 if (data && data->localpool)
80 printf("%s: %s\n", keyname, stringpool_id2str(&data->spool, kv->id));
82 printf("%s: %s\n", keyname, dep2str(s->repo->pool, kv->id));
84 case REPOKEY_TYPE_STR:
85 printf("%s: %s\n", keyname, kv->str);
87 case REPOKEY_TYPE_VOID:
88 printf("%s: (void)\n", keyname);
90 case REPOKEY_TYPE_U32:
91 case REPOKEY_TYPE_NUM:
92 case REPOKEY_TYPE_CONSTANT:
93 printf("%s: %d\n", keyname, kv->num);
95 case REPOKEY_TYPE_DIRNUMNUMARRAY:
96 printf("%s: %s %d %d\n", keyname, repodata_dir2str(data, kv->id, 0), kv->num, kv->num2);
98 case REPOKEY_TYPE_DIRSTRARRAY:
99 printf("%s: %s\n", keyname, repodata_dir2str(data, kv->id, kv->str));
102 printf("%s: ?\n", keyname);
109 * dump all attributes for Id <p>
113 dump_repoattrs(Repo *repo, Id p)
116 repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
119 dataiterator_init(&di, repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE);
120 while (dataiterator_step(&di))
121 dump_repoattrs_cb(0, repo->pool->solvables + di.solvid, di.data, di.key,
128 dump_some_attrs(Repo *repo, Solvable *s)
130 const char *summary = 0;
131 unsigned int medianr = -1, downloadsize = -1;
132 unsigned int time = -1;
133 summary = repo_lookup_str(s, SOLVABLE_SUMMARY);
134 medianr = repo_lookup_num(s, SOLVABLE_MEDIANR);
135 downloadsize = repo_lookup_num (s, SOLVABLE_DOWNLOADSIZE);
136 time = repo_lookup_num(s, SOLVABLE_BUILDTIME);
137 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
143 loadcallback (Pool *pool, Repodata *data, void *vdata)
146 if (data->location && with_attr)
148 fprintf (stderr, "Loading SOLV file %s\n", data->location);
149 fp = fopen (data->location, "r");
151 perror(data->location);
158 usage( const char *err )
161 fprintf (stderr, "\n** Error:\n %s\n", err);
162 fprintf( stderr, "\nUsage:\n"
163 "dumpsolv [-a] [<solvfile>]\n"
164 " -a read attributes.\n"
171 tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
174 dataiterator_init(&di, repo, p, keyname, match, flags);
175 while (dataiterator_step(&di))
177 switch (di.key->type)
179 case REPOKEY_TYPE_ID:
180 case REPOKEY_TYPE_IDARRAY:
181 if (di.data && di.data->localpool)
182 di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
184 di.kv.str = id2str(repo->pool, di.kv.id);
186 case REPOKEY_TYPE_STR:
187 case REPOKEY_TYPE_DIRSTRARRAY:
192 fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
194 id2str(repo->pool, di.key->name),
196 di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
201 int main(int argc, char **argv)
212 const char *s = argv[0];
217 case 'h': usage(NULL); break;
218 case 'a': with_attr = 1; break;
223 if (freopen (argv[0], "r", stdin) == 0)
233 pool = pool_create();
234 pool_setdebuglevel(pool, 1);
235 pool_setloadcallback(pool, loadcallback, 0);
237 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
238 if (repo_add_solv(repo, stdin))
239 printf("could not read repository\n");
240 printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
242 printf("repo contains %d solvables\n", repo->nsolvables);
243 for (i = repo->start, n = 1; i < repo->end; i++)
245 s = pool->solvables + i;
249 printf("solvable %d:\n", n);
250 if (s->name || s->evr || s->arch)
251 printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
253 printf("vendor: %s\n", id2str(pool, s->vendor));
254 printids(repo, "provides", s->provides);
255 printids(repo, "obsoletes", s->obsoletes);
256 printids(repo, "conflicts", s->conflicts);
257 printids(repo, "requires", s->requires);
258 printids(repo, "recommends", s->recommends);
259 printids(repo, "suggests", s->suggests);
260 printids(repo, "supplements", s->supplements);
261 printids(repo, "enhances", s->enhances);
262 printids(repo, "freshens", s->freshens);
264 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
266 dump_attrs (repo, n - 1);
268 dump_repoattrs(repo, i);
270 dump_some_attrs(repo, s);
275 tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
277 tryme(repo, 0, 0, 0, 0);
279 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);