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", data->location ? data->location : "**EMBED**", data->nkeys);
30 for (j = 1; j < data->nkeys; j++)
31 printf("\n %s (type %d size %d storage %d)", id2str(repo->pool, data->keys[j].name), data->keys[j].type, data->keys[j].size, data->keys[j].storage);
38 printids(Repo *repo, char *kind, Offset ido)
40 Pool *pool = repo->pool;
44 printf("%s:\n", kind);
45 ids = repo->idarraydata + ido;
46 while((id = *ids++) != 0)
47 printf(" %s\n", dep2str(pool, id));
51 printdir(Repodata *data, Id dir)
54 Id parent = dirpool_parent(&data->dirpool, dir);
57 printdir(data, parent);
60 comp = dirpool_compid(&data->dirpool, dir);
62 printf("%s", stringpool_id2str(&data->spool, comp));
64 printf("%s", id2str(data->repo->pool, comp));
68 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
72 keyname = id2str(s->repo->pool, key->name);
76 if (data && data->localpool)
77 kv->str = stringpool_id2str(&data->spool, kv->id);
79 kv->str = id2str(s->repo->pool, kv->id);
80 printf("%s: %s\n", keyname, kv->str);
83 if (data && data->localpool)
84 printf("%s: %s\n", keyname, stringpool_id2str(&data->spool, kv->id));
86 printf("%s: %s\n", keyname, dep2str(s->repo->pool, kv->id));
89 printf("%s: %s\n", keyname, kv->str);
92 printf("%s\n", keyname);
97 printf("%s: %d\n", keyname, kv->num);
99 case TYPE_DIRNUMNUMARRAY:
100 printf("%s: ", keyname);
101 printdir(data, kv->id);
102 printf(" %d %d\n", kv->num, kv->num2);
104 case TYPE_DIRSTRARRAY:
105 printf("%s: ", keyname);
106 printdir(data, kv->id);
107 printf("/%s\n", kv->str);
110 printf("%s: ?\n", keyname);
117 * dump all attributes for Id <p>
121 dump_repoattrs(Repo *repo, Id p)
124 repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
127 dataiterator_init(&di, repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE);
128 while (dataiterator_step(&di))
129 dump_repoattrs_cb(0, repo->pool->solvables + di.solvid, di.data, di.key,
136 dump_some_attrs(Repo *repo, Solvable *s)
138 Id name = str2id (repo->pool, "summary", 0);
139 const char *summary = 0;
140 unsigned int medianr = -1, downloadsize = -1;
141 unsigned int time = -1;
143 summary = repo_lookup_str (s, name);
144 if ((name = str2id (repo->pool, "medianr", 0)))
145 medianr = repo_lookup_num (s, name);
146 if ((name = str2id (repo->pool, "downloadsize", 0)))
147 downloadsize = repo_lookup_num (s, name);
148 if ((name = str2id (repo->pool, "time", 0)))
149 time = repo_lookup_num (s, name);
151 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
157 loadcallback (Pool *pool, Repodata *data, void *vdata)
160 if (data->location && with_attr)
162 fprintf (stderr, "Loading SOLV file %s\n", data->location);
163 fp = fopen (data->location, "r");
165 perror(data->location);
172 usage( const char *err )
175 fprintf (stderr, "\n** Error:\n %s\n", err);
176 fprintf( stderr, "\nUsage:\n"
177 "dumpsolv [-a] [<solvfile>]\n"
178 " -a read attributes.\n"
185 tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
188 dataiterator_init(&di, repo, p, keyname, match, flags);
189 while (dataiterator_step(&di))
191 switch (di.key->type)
195 if (di.data && di.data->localpool)
196 di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
198 di.kv.str = id2str(repo->pool, di.kv.id);
201 case TYPE_DIRSTRARRAY:
206 fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
208 id2str(repo->pool, di.key->name),
210 di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
215 int main(int argc, char **argv)
226 const char *s = argv[0];
231 case 'h': usage(NULL); break;
232 case 'a': with_attr = 1; break;
237 if (freopen (argv[0], "r", stdin) == 0)
247 pool = pool_create();
248 pool_setdebuglevel(pool, 1);
249 pool_setloadcallback(pool, loadcallback, 0);
251 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
252 if (repo_add_solv(repo, stdin))
253 printf("could not read repository\n");
254 dump_repodata (repo);
255 printf("repo contains %d solvables\n", repo->nsolvables);
256 for (i = repo->start, n = 1; i < repo->end; i++)
258 s = pool->solvables + i;
262 printf("solvable %d:\n", n);
263 if (s->name || s->evr || s->arch)
264 printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
266 printf("vendor: %s\n", id2str(pool, s->vendor));
267 printids(repo, "provides", s->provides);
268 printids(repo, "obsoletes", s->obsoletes);
269 printids(repo, "conflicts", s->conflicts);
270 printids(repo, "requires", s->requires);
271 printids(repo, "recommends", s->recommends);
272 printids(repo, "suggests", s->suggests);
273 printids(repo, "supplements", s->supplements);
274 printids(repo, "enhances", s->enhances);
275 printids(repo, "freshens", s->freshens);
277 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
279 dump_attrs (repo, n - 1);
281 dump_repoattrs(repo, i);
283 dump_some_attrs(repo, s);
288 tryme(repo, 0, str2id (repo->pool, "medianr", 0), 0, 0);
290 tryme(repo, 0, 0, 0, 0);
292 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);