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: %s %d %d\n", keyname, repodata_dir2str(data, kv->id, 0), kv->num, kv->num2);
109 case REPOKEY_TYPE_DIRSTRARRAY:
110 printf("%s: %s\n", keyname, repodata_dir2str(data, kv->id, kv->str));
113 printf("%s: ?\n", keyname);
120 * dump all attributes for Id <p>
124 dump_repoattrs(Repo *repo, Id p)
127 repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
130 dataiterator_init(&di, repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE);
131 while (dataiterator_step(&di))
132 dump_repoattrs_cb(0, repo->pool->solvables + di.solvid, di.data, di.key,
139 dump_some_attrs(Repo *repo, Solvable *s)
141 const char *summary = 0;
142 unsigned int medianr = -1, downloadsize = -1;
143 unsigned int time = -1;
144 summary = repo_lookup_str(s, SOLVABLE_SUMMARY);
145 medianr = repo_lookup_num(s, SOLVABLE_MEDIANR);
146 downloadsize = repo_lookup_num (s, SOLVABLE_DOWNLOADSIZE);
147 time = repo_lookup_num(s, SOLVABLE_BUILDTIME);
148 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
154 loadcallback (Pool *pool, Repodata *data, void *vdata)
157 if (data->location && with_attr)
159 fprintf (stderr, "Loading SOLV file %s\n", data->location);
160 fp = fopen (data->location, "r");
162 perror(data->location);
169 usage( const char *err )
172 fprintf (stderr, "\n** Error:\n %s\n", err);
173 fprintf( stderr, "\nUsage:\n"
174 "dumpsolv [-a] [<solvfile>]\n"
175 " -a read attributes.\n"
182 tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
185 dataiterator_init(&di, repo, p, keyname, match, flags);
186 while (dataiterator_step(&di))
188 switch (di.key->type)
190 case REPOKEY_TYPE_ID:
191 case REPOKEY_TYPE_IDARRAY:
192 if (di.data && di.data->localpool)
193 di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
195 di.kv.str = id2str(repo->pool, di.kv.id);
197 case REPOKEY_TYPE_STR:
198 case REPOKEY_TYPE_DIRSTRARRAY:
203 fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
205 id2str(repo->pool, di.key->name),
207 di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
212 int main(int argc, char **argv)
223 const char *s = argv[0];
228 case 'h': usage(NULL); break;
229 case 'a': with_attr = 1; break;
234 if (freopen (argv[0], "r", stdin) == 0)
244 pool = pool_create();
245 pool_setdebuglevel(pool, 1);
246 pool_setloadcallback(pool, loadcallback, 0);
248 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
249 if (repo_add_solv(repo, stdin))
250 printf("could not read repository\n");
251 printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
253 printf("repo contains %d solvables\n", repo->nsolvables);
254 for (i = repo->start, n = 1; i < repo->end; i++)
256 s = pool->solvables + i;
260 printf("solvable %d:\n", n);
261 if (s->name || s->evr || s->arch)
262 printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
264 printf("vendor: %s\n", id2str(pool, s->vendor));
265 printids(repo, "provides", s->provides);
266 printids(repo, "obsoletes", s->obsoletes);
267 printids(repo, "conflicts", s->conflicts);
268 printids(repo, "requires", s->requires);
269 printids(repo, "recommends", s->recommends);
270 printids(repo, "suggests", s->suggests);
271 printids(repo, "supplements", s->supplements);
272 printids(repo, "enhances", s->enhances);
273 printids(repo, "freshens", s->freshens);
275 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
277 dump_attrs (repo, n - 1);
279 dump_repoattrs(repo, i);
281 dump_some_attrs(repo, s);
286 tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
288 tryme(repo, 0, 0, 0, 0);
290 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);