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 for (i = 0; i < 32; i++)
26 if (repo->rpmdbcookie[i])
30 printf("rpmdb cookie: ");
31 for (i = 0; i < 32; i++)
32 printf("%02x", repo->rpmdbcookie[i]);
35 printf("repo refers to %d subfiles:\n", repo->nrepodata);
36 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
39 printf("%s has %d keys, %d schemata\n", data->location ? data->location : "**EMBED**", data->nkeys, data->nschemata);
40 for (j = 1; j < data->nkeys; j++)
41 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);
43 printf(" localpool has %d strings, size is %d\n", data->spool.nstrings, data->spool.sstrings);
44 if (data->dirpool.ndirs)
45 printf(" localpool has %d directories\n", data->dirpool.ndirs);
46 if (data->addedfileprovides)
48 printf(" added file provides:\n");
49 for (j = 0; data->addedfileprovides[j]; j++)
50 printf(" %s\n", id2str(repo->pool, data->addedfileprovides[j]));
58 printids(Repo *repo, char *kind, Offset ido)
60 Pool *pool = repo->pool;
64 printf("%s:\n", kind);
65 ids = repo->idarraydata + ido;
66 while((id = *ids++) != 0)
67 printf(" %s\n", dep2str(pool, id));
71 dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv)
75 keyname = id2str(repo->pool, key->name);
79 if (data && data->localpool)
80 kv->str = stringpool_id2str(&data->spool, kv->id);
82 kv->str = id2str(repo->pool, kv->id);
83 printf("%s: %s\n", keyname, kv->str);
85 case REPOKEY_TYPE_CONSTANTID:
86 printf("%s: %s\n", keyname, dep2str(repo->pool, kv->id));
88 case REPOKEY_TYPE_IDARRAY:
89 if (data && data->localpool)
90 printf("%s: %s\n", keyname, stringpool_id2str(&data->spool, kv->id));
92 printf("%s: %s\n", keyname, dep2str(repo->pool, kv->id));
94 case REPOKEY_TYPE_STR:
95 printf("%s: %s\n", keyname, kv->str);
97 case REPOKEY_TYPE_MD5:
98 case REPOKEY_TYPE_SHA1:
99 case REPOKEY_TYPE_SHA256:
100 printf("%s: %s\n", keyname, repodata_chk2str(data, key->type, (unsigned char *)kv->str));
102 case REPOKEY_TYPE_VOID:
103 printf("%s: (void)\n", keyname);
105 case REPOKEY_TYPE_U32:
106 case REPOKEY_TYPE_NUM:
107 case REPOKEY_TYPE_CONSTANT:
108 printf("%s: %d\n", keyname, kv->num);
110 case REPOKEY_TYPE_DIRNUMNUMARRAY:
111 printf("%s: %s %d %d\n", keyname, repodata_dir2str(data, kv->id, 0), kv->num, kv->num2);
113 case REPOKEY_TYPE_DIRSTRARRAY:
114 printf("%s: %s\n", keyname, repodata_dir2str(data, kv->id, kv->str));
116 case REPOKEY_TYPE_COUNTED:
117 printf("%s: %s\n", keyname, kv->eof == 0 ? "open" : kv->eof == 1 ? "next" : "close");
120 printf("%s: ?\n", keyname);
127 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
129 return dump_attr(s->repo, data, key, kv);
133 * dump all attributes for Id <p>
137 dump_repoattrs(Repo *repo, Id p)
140 repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
143 dataiterator_init(&di, repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE);
144 while (dataiterator_step(&di))
145 dump_attr(repo, di.data, di.key, &di.kv);
151 dump_some_attrs(Repo *repo, Solvable *s)
153 const char *summary = 0;
154 unsigned int medianr = -1, downloadsize = -1;
155 unsigned int time = -1;
156 summary = repo_lookup_str(s, SOLVABLE_SUMMARY);
157 medianr = repo_lookup_num(s, SOLVABLE_MEDIANR);
158 downloadsize = repo_lookup_num (s, SOLVABLE_DOWNLOADSIZE);
159 time = repo_lookup_num(s, SOLVABLE_BUILDTIME);
160 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
166 loadcallback (Pool *pool, Repodata *data, void *vdata)
169 if (data->location && with_attr)
171 fprintf (stderr, "Loading SOLV file %s\n", data->location);
172 fp = fopen (data->location, "r");
174 perror(data->location);
181 usage( const char *err )
184 fprintf (stderr, "\n** Error:\n %s\n", err);
185 fprintf( stderr, "\nUsage:\n"
186 "dumpsolv [-a] [<solvfile>]\n"
187 " -a read attributes.\n"
194 tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
197 dataiterator_init(&di, repo, p, keyname, match, flags);
198 while (dataiterator_step(&di))
200 switch (di.key->type)
202 case REPOKEY_TYPE_ID:
203 case REPOKEY_TYPE_IDARRAY:
204 if (di.data && di.data->localpool)
205 di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
207 di.kv.str = id2str(repo->pool, di.kv.id);
209 case REPOKEY_TYPE_STR:
210 case REPOKEY_TYPE_DIRSTRARRAY:
215 fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
217 id2str(repo->pool, di.key->name),
219 di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
224 int main(int argc, char **argv)
231 pool = pool_create();
232 pool_setdebuglevel(pool, 1);
233 pool_setloadcallback(pool, loadcallback, 0);
239 const char *s = argv[0];
244 case 'h': usage(NULL); break;
245 case 'a': with_attr = 1; break;
250 if (freopen (argv[0], "r", stdin) == 0)
255 repo = repo_create(pool, argv[0]);
256 if (repo_add_solv(repo, stdin))
257 printf("could not read repository\n");
264 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
265 if (repo_add_solv(repo, stdin))
266 printf("could not read repository\n");
268 printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
269 for (j = 0; 1 && j < pool->nrepos; j++)
271 repo = pool->repos[j];
273 printf("repo %d contains %d solvables %d non-solvables\n", j, repo->nsolvables, repo->nextra);
274 printf("repo start: %d end: %d\n", repo->start, repo->end);
275 for (i = repo->start, n = 1; i < repo->end; i++)
277 s = pool->solvables + i;
281 printf("solvable %d (%d):\n", n, i);
282 if (s->name || s->evr || s->arch)
283 printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
285 printf("vendor: %s\n", id2str(pool, s->vendor));
286 printids(repo, "provides", s->provides);
287 printids(repo, "obsoletes", s->obsoletes);
288 printids(repo, "conflicts", s->conflicts);
289 printids(repo, "requires", s->requires);
290 printids(repo, "recommends", s->recommends);
291 printids(repo, "suggests", s->suggests);
292 printids(repo, "supplements", s->supplements);
293 printids(repo, "enhances", s->enhances);
295 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
297 dump_attrs (repo, n - 1);
299 dump_repoattrs(repo, i);
301 dump_some_attrs(repo, s);
305 for (i = 0; i < repo->nextra; i++)
307 printf("\nextra %d:\n", i);
309 dataiterator_init(&di, repo, -1 - i, 0, 0, SEARCH_EXTRA | SEARCH_NO_STORAGE_SOLVABLE);
310 while (dataiterator_step(&di))
311 dump_attr(repo, di.data, di.key, &di.kv);
314 tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
316 tryme(repo, 0, 0, 0, 0);
318 tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);
322 printf ("\nSearchresults:\n");
324 dataiterator_init(&di, pool->repos[0], 0, 0, "3", SEARCH_EXTRA | SEARCH_SUBSTRING | SEARCH_ALL_REPOS | SEARCH_FILES);
326 while (dataiterator_step(&di))
328 printf("%d:", di.solvid);
329 dump_attr(repo, di.data, di.key, &di.kv);
330 /*if (di.solvid == 4 && count++ == 0)
331 dataiterator_jump_to_solvable(&di, pool->solvables + 3);*/
332 //dataiterator_skip_attribute(&di);
333 //dataiterator_skip_solvable(&di);
334 //dataiterator_skip_repo(&di);