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"
18 #include "attr_store.h"
19 #include "attr_store_p.h"
22 dump_attrs_1 (Attrstore *s, unsigned int entry)
25 FOR_ATTRS (s, entry, &ai)
27 fprintf (stdout, "%s:", id2str (s->pool, ai.name));
31 fprintf (stdout, "int %u\n", ai.as_int);
35 const char *str = attr_retrieve_blob (s, ai.as_chunk[0], ai.as_chunk[1]);
37 fprintf (stdout, "blob %s\n", str);
39 fprintf (stdout, "blob %u+%u\n", ai.as_chunk[0], ai.as_chunk[1]);
42 case TYPE_ATTR_STRING:
43 fprintf (stdout, "str %s\n", ai.as_string);
45 case TYPE_ATTR_INTLIST:
47 fprintf (stdout, "lint\n ");
51 get_num (ai.as_numlist, val);
52 fprintf (stdout, " %d", (val & 63) | ((val >> 1) & ~63));
56 fprintf (stdout, "\n");
59 case TYPE_ATTR_LOCALIDS:
61 fprintf (stdout, "lids");
65 get_num (ai.as_numlist, val);
68 fprintf (stdout, "\n %s(%d)", localid2str (s, val), val);
70 fprintf (stdout, "\n");
74 fprintf (stdout, "\n");
81 dump_attrs (Repo *repo, unsigned int entry)
84 for (i = 0; i < repo->nrepodata; i++)
86 Attrstore *s = repo->repodata[i].s;
87 if (s && entry < s->entries)
88 dump_attrs_1 (s, entry);
94 dump_repodata (Repo *repo)
98 if (repo->nrepodata == 0)
100 printf("repo refers to %d subfiles:\n", repo->nrepodata);
101 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
104 printf("%s has %d keys", data->location ? data->location : "**EMBED**", data->nkeys);
105 for (j = 1; j < data->nkeys; j++)
106 printf("\n %s", id2str(repo->pool, data->keys[j].name));
113 printids(Repo *repo, char *kind, Offset ido)
115 Pool *pool = repo->pool;
119 printf("%s:\n", kind);
120 ids = repo->idarraydata + ido;
121 while((id = *ids++) != 0)
122 printf(" %s\n", dep2str(pool, id));
126 printdir(Repodata *data, Id dir)
129 Id parent = dirpool_parent(&data->dirpool, dir);
132 printdir(data, parent);
135 comp = dirpool_compid(&data->dirpool, dir);
137 printf("%s", stringpool_id2str(&data->spool, comp));
139 printf("%s", id2str(data->repo->pool, comp));
143 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
147 keyname = id2str(data->repo->pool, key->name);
152 kv->str = stringpool_id2str(&data->spool, kv->id);
154 kv->str = id2str(data->repo->pool, kv->id);
155 printf("%s: %s\n", keyname, kv->str);
158 printf("%s: %s\n", keyname, kv->str);
161 printf("%s\n", keyname);
165 printf("%s: %d\n", keyname, kv->num);
167 case TYPE_DIRNUMNUMARRAY:
168 printf("%s: ", keyname);
169 printdir(data, kv->id);
170 printf(" %d %d\n", kv->num, kv->num2);
172 case TYPE_DIRSTRARRAY:
173 printf("%s: ", keyname);
174 printdir(data, kv->id);
175 printf("/%s\n", kv->str);
178 printf("%s: ?\n", keyname);
185 * dump all attributes for Id <p>
189 dump_repoattrs(Repo *repo, Id p)
191 repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
195 dump_some_attrs(Repo *repo, Solvable *s)
197 Id name = str2id (repo->pool, "summary", 0);
198 const char *summary = 0;
199 unsigned int medianr = -1, downloadsize = -1;
200 unsigned int time = -1;
202 summary = repo_lookup_str (s, name);
203 if ((name = str2id (repo->pool, "medianr", 0)))
204 medianr = repo_lookup_num (s, name);
205 if ((name = str2id (repo->pool, "downloadsize", 0)))
206 downloadsize = repo_lookup_num (s, name);
207 if ((name = str2id (repo->pool, "time", 0)))
208 time = repo_lookup_num (s, name);
210 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
215 loadcallback (Pool *pool, Repodata *data, void *vdata)
218 if (data->location && with_attr)
220 fprintf (stderr, "Loading SOLV file %s\n", data->location);
221 fp = fopen (data->location, "r");
223 perror(data->location);
230 usage( const char *err )
233 fprintf (stderr, "\n** Error:\n %s\n", err);
234 fprintf( stderr, "\nUsage:\n"
235 "dumpsolv [-a] [<solvfile>]\n"
236 " -a read attributes.\n"
242 int main(int argc, char **argv)
253 const char *s = argv[0];
258 case 'h': usage(NULL); break;
259 case 'a': with_attr = 1; break;
264 if (freopen (argv[0], "r", stdin) == 0)
274 pool = pool_create();
275 pool_setdebuglevel(pool, 1);
276 pool_setloadcallback(pool, loadcallback, 0);
278 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
279 if (repo_add_solv(repo, stdin))
280 printf("could not read repository\n");
281 dump_repodata (repo);
282 printf("repo contains %d solvables\n", repo->nsolvables);
283 for (i = repo->start, n = 1; i < repo->end; i++)
285 s = pool->solvables + i;
289 printf("solvable %d:\n", n);
290 if (s->name || s->evr || s->arch)
291 printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
293 printf("vendor: %s\n", id2str(pool, s->vendor));
294 printids(repo, "provides", s->provides);
295 printids(repo, "obsoletes", s->obsoletes);
296 printids(repo, "conflicts", s->conflicts);
297 printids(repo, "requires", s->requires);
298 printids(repo, "recommends", s->recommends);
299 printids(repo, "suggests", s->suggests);
300 printids(repo, "supplements", s->supplements);
301 printids(repo, "enhances", s->enhances);
302 printids(repo, "freshens", s->freshens);
304 printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
306 dump_attrs (repo, n - 1);
308 dump_repoattrs(repo, i);
310 dump_some_attrs(repo, s);