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);
42 printids(Repo *repo, char *kind, Offset ido)
44 Pool *pool = repo->pool;
48 printf("%s:\n", kind);
49 ids = repo->idarraydata + ido;
50 while((id = *ids++) != 0)
51 printf(" %s\n", dep2str(pool, id));
55 printdir(Repodata *data, Id dir)
58 Id parent = dirpool_parent(&data->dirpool, dir);
61 printdir(data, parent);
64 comp = dirpool_compid(&data->dirpool, dir);
66 printf("%s", stringpool_id2str(&data->spool, comp));
68 printf("%s", id2str(data->repo->pool, comp));
72 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
76 keyname = id2str(s->repo->pool, key->name);
80 if (data && data->localpool)
81 kv->str = stringpool_id2str(&data->spool, kv->id);
83 kv->str = id2str(s->repo->pool, kv->id);
84 printf("%s: %s\n", keyname, kv->str);
86 case REPOKEY_TYPE_CONSTANTID:
87 printf("%s: %s\n", keyname, dep2str(s->repo->pool, kv->id));
89 case REPOKEY_TYPE_IDARRAY:
90 if (data && data->localpool)
91 printf("%s: %s\n", keyname, stringpool_id2str(&data->spool, kv->id));
93 printf("%s: %s\n", keyname, dep2str(s->repo->pool, kv->id));
95 case REPOKEY_TYPE_STR:
96 printf("%s: %s\n", keyname, kv->str);
98 case REPOKEY_TYPE_VOID:
99 printf("%s: (void)\n", keyname);
101 case REPOKEY_TYPE_U32:
102 case REPOKEY_TYPE_NUM:
103 case REPOKEY_TYPE_CONSTANT:
104 printf("%s: %d\n", keyname, kv->num);
106 case REPOKEY_TYPE_DIRNUMNUMARRAY:
107 printf("%s: ", keyname);
108 printdir(data, kv->id);
109 printf(" %d %d\n", kv->num, kv->num2);
111 case REPOKEY_TYPE_DIRSTRARRAY:
112 printf("%s: ", keyname);
113 printdir(data, kv->id);
114 printf("/%s\n", kv->str);
117 printf("%s: ?\n", keyname);
124 * dump all attributes for Id <p>
128 dump_repoattrs(Repo *repo, Id p)
131 repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
134 dataiterator_init(&di, repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE);
135 while (dataiterator_step(&di))
136 dump_repoattrs_cb(0, repo->pool->solvables + di.solvid, di.data, di.key,
143 dump_some_attrs(Repo *repo, Solvable *s)
145 const char *summary = 0;
146 unsigned int medianr = -1, downloadsize = -1;
147 unsigned int time = -1;
148 summary = repo_lookup_str(s, SOLVABLE_SUMMARY);
149 medianr = repo_lookup_num(s, SOLVABLE_MEDIANR);
150 downloadsize = repo_lookup_num (s, SOLVABLE_DOWNLOADSIZE);
151 time = repo_lookup_num(s, SOLVABLE_BUILDTIME);
152 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
158 loadcallback (Pool *pool, Repodata *data, void *vdata)
161 if (data->location && with_attr)
163 fprintf (stderr, "Loading SOLV file %s\n", data->location);
164 fp = fopen (data->location, "r");
166 perror(data->location);
173 usage( const char *err )
176 fprintf (stderr, "\n** Error:\n %s\n", err);
177 fprintf( stderr, "\nUsage:\n"
178 "dumpsolv [-a] [<solvfile>]\n"
179 " -a read attributes.\n"
186 tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
189 dataiterator_init(&di, repo, p, keyname, match, flags);
190 while (dataiterator_step(&di))
192 switch (di.key->type)
194 case REPOKEY_TYPE_ID:
195 case REPOKEY_TYPE_IDARRAY:
196 if (di.data && di.data->localpool)
197 di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
199 di.kv.str = id2str(repo->pool, di.kv.id);
201 case REPOKEY_TYPE_STR:
202 case REPOKEY_TYPE_DIRSTRARRAY:
207 fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
209 id2str(repo->pool, di.key->name),
211 di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
216 int main(int argc, char **argv)
227 const char *s = argv[0];
232 case 'h': usage(NULL); break;
233 case 'a': with_attr = 1; break;
238 if (freopen (argv[0], "r", stdin) == 0)
248 pool = pool_create();
249 pool_setdebuglevel(pool, 1);
250 pool_setloadcallback(pool, loadcallback, 0);
252 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
253 if (repo_add_solv(repo, stdin))
254 printf("could not read repository\n");
255 printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
257 printf("repo contains %d solvables\n", repo->nsolvables);
258 for (i = repo->start, n = 1; i < repo->end; i++)
260 s = pool->solvables + i;
264 printf("solvable %d:\n", n);
265 if (s->name || s->evr || s->arch)
266 printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
268 printf("vendor: %s\n", id2str(pool, s->vendor));
269 printids(repo, "provides", s->provides);
270 printids(repo, "obsoletes", s->obsoletes);
271 printids(repo, "conflicts", s->conflicts);
272 printids(repo, "requires", s->requires);
273 printids(repo, "recommends", s->recommends);
274 printids(repo, "suggests", s->suggests);
275 printids(repo, "supplements", s->supplements);
276 printids(repo, "enhances", s->enhances);
277 printids(repo, "freshens", s->freshens);
279 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
281 dump_attrs (repo, n - 1);
283 dump_repoattrs(repo, i);
285 dump_some_attrs(repo, s);
290 tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
292 tryme(repo, 0, 0, 0, 0);
294 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);