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 printf("%s: %s\n", keyname, dep2str(s->repo->pool, kv->id));
86 printf("%s: %s\n", keyname, kv->str);
89 printf("%s\n", keyname);
94 printf("%s: %d\n", keyname, kv->num);
96 case TYPE_DIRNUMNUMARRAY:
97 printf("%s: ", keyname);
98 printdir(data, kv->id);
99 printf(" %d %d\n", kv->num, kv->num2);
101 case TYPE_DIRSTRARRAY:
102 printf("%s: ", keyname);
103 printdir(data, kv->id);
104 printf("/%s\n", kv->str);
107 printf("%s: ?\n", keyname);
114 * dump all attributes for Id <p>
118 dump_repoattrs(Repo *repo, Id p)
121 repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
124 dataiterator_init(&di, repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE);
125 while (dataiterator_step(&di))
126 dump_repoattrs_cb(0, repo->pool->solvables + di.solvid, di.data, di.key,
133 dump_some_attrs(Repo *repo, Solvable *s)
135 Id name = str2id (repo->pool, "summary", 0);
136 const char *summary = 0;
137 unsigned int medianr = -1, downloadsize = -1;
138 unsigned int time = -1;
140 summary = repo_lookup_str (s, name);
141 if ((name = str2id (repo->pool, "medianr", 0)))
142 medianr = repo_lookup_num (s, name);
143 if ((name = str2id (repo->pool, "downloadsize", 0)))
144 downloadsize = repo_lookup_num (s, name);
145 if ((name = str2id (repo->pool, "time", 0)))
146 time = repo_lookup_num (s, name);
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)
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);
198 case 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 dump_repodata (repo);
252 printf("repo contains %d solvables\n", repo->nsolvables);
253 for (i = repo->start, n = 1; i < repo->end; i++)
255 s = pool->solvables + i;
259 printf("solvable %d:\n", n);
260 if (s->name || s->evr || s->arch)
261 printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
263 printf("vendor: %s\n", id2str(pool, s->vendor));
264 printids(repo, "provides", s->provides);
265 printids(repo, "obsoletes", s->obsoletes);
266 printids(repo, "conflicts", s->conflicts);
267 printids(repo, "requires", s->requires);
268 printids(repo, "recommends", s->recommends);
269 printids(repo, "suggests", s->suggests);
270 printids(repo, "supplements", s->supplements);
271 printids(repo, "enhances", s->enhances);
272 printids(repo, "freshens", s->freshens);
274 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
276 dump_attrs (repo, n - 1);
278 dump_repoattrs(repo, i);
280 dump_some_attrs(repo, s);
285 tryme(repo, 0, str2id (repo->pool, "medianr", 0), 0, 0);
287 tryme(repo, 0, 0, 0, 0);
289 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);