2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
14 #include "repo_solv.h"
16 #include "attr_store.h"
17 #include "attr_store_p.h"
20 dump_attrs_1 (Attrstore *s, unsigned int entry)
23 FOR_ATTRS (s, entry, &ai)
25 fprintf (stdout, "%s:", id2str (s->pool, ai.name));
29 fprintf (stdout, "int %u\n", ai.as_int);
33 const char *str = attr_retrieve_blob (s, ai.as_chunk[0], ai.as_chunk[1]);
35 fprintf (stdout, "blob %s\n", str);
37 fprintf (stdout, "blob %u+%u\n", ai.as_chunk[0], ai.as_chunk[1]);
40 case TYPE_ATTR_STRING:
41 fprintf (stdout, "str %s\n", ai.as_string);
43 case TYPE_ATTR_INTLIST:
45 fprintf (stdout, "lint\n ");
49 get_num (ai.as_numlist, val);
50 fprintf (stdout, " %d", (val & 63) | ((val >> 1) & ~63));
54 fprintf (stdout, "\n");
57 case TYPE_ATTR_LOCALIDS:
59 fprintf (stdout, "lids");
63 get_num (ai.as_numlist, val);
66 fprintf (stdout, "\n %s(%d)", localid2str (s, val), val);
68 fprintf (stdout, "\n");
72 fprintf (stdout, "\n");
79 dump_attrs (Repo *repo, unsigned int entry)
82 for (i = 0; i < repo->nrepodata; i++)
84 Attrstore *s = repo->repodata[i].s;
85 if (s && entry < s->entries)
86 dump_attrs_1 (s, entry);
92 dump_repodata (Repo *repo)
96 if (repo->nrepodata == 0)
98 printf("repo refers to %d subfiles:\n", repo->nrepodata);
99 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
102 printf("%s has %d keys", data->location ? data->location : "**EMBED**", data->nkeys);
103 for (j = 1; j < data->nkeys; j++)
104 printf("\n %s", id2str(repo->pool, data->keys[j].name));
111 printids(Repo *repo, char *kind, Offset ido)
113 Pool *pool = repo->pool;
117 printf("%s:\n", kind);
118 ids = repo->idarraydata + ido;
119 while((id = *ids++) != 0)
120 printf(" %s\n", dep2str(pool, id));
124 printdir(Repodata *data, Id dir)
127 Id parent = dirpool_parent(&data->dirpool, dir);
130 printdir(data, parent);
133 comp = dirpool_compid(&data->dirpool, dir);
135 printf("%s", stringpool_id2str(&data->spool, comp));
137 printf("%s", id2str(data->repo->pool, comp));
141 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
145 keyname = id2str(data->repo->pool, key->name);
150 kv->str = stringpool_id2str(&data->spool, kv->id);
152 kv->str = id2str(data->repo->pool, kv->id);
153 printf("%s: %s\n", keyname, kv->str);
156 printf("%s: %s\n", keyname, kv->str);
159 printf("%s\n", keyname);
163 printf("%s: %d\n", keyname, kv->num);
165 case TYPE_DIRNUMNUMARRAY:
166 printf("%s: ", keyname);
167 printdir(data, kv->id);
168 printf(" %d %d\n", kv->num, kv->num2);
171 printf("%s: ?\n", keyname);
178 dump_repoattrs(Repo *repo, Id p)
182 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
184 if (data->state == REPODATA_STUB || data->state == REPODATA_ERROR)
186 if (p < data->start || p >= data->end)
188 repodata_search(data, p - data->start, 0, dump_repoattrs_cb, 0);
193 dump_some_attrs(Repo *repo, Solvable *s)
195 Id name = str2id (repo->pool, "summary", 0);
196 const char *summary = 0;
197 unsigned int medianr = -1, downloadsize = -1;
198 unsigned int time = -1;
200 summary = repo_lookup_str (s, name);
201 if ((name = str2id (repo->pool, "medianr", 0)))
202 medianr = repo_lookup_num (s, name);
203 if ((name = str2id (repo->pool, "downloadsize", 0)))
204 downloadsize = repo_lookup_num (s, name);
205 if ((name = str2id (repo->pool, "time", 0)))
206 time = repo_lookup_num (s, name);
208 printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
212 loadcallback (Pool *pool, Repodata *data, void *vdata)
215 fprintf (stderr, "Loading SOLV file %s\n", data->location);
216 fp = fopen ("test.attr", "r");
220 int main(int argc, char **argv)
229 if (freopen(argv[1], "r", stdin) == 0)
235 pool = pool_create();
236 pool_setdebuglevel(pool, 1);
237 pool_setloadcallback(pool, loadcallback, 0);
239 repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
240 if (repo_add_solv(repo, stdin))
241 printf("could not read repository\n");
242 dump_repodata (repo);
243 printf("repo contains %d solvables\n", repo->nsolvables);
244 for (i = repo->start, n = 1; i < repo->end; i++)
246 s = pool->solvables + i;
250 printf("solvable %d:\n", n);
251 if (s->name || s->evr || s->arch)
252 printf("name: %s(%s) %s %s\n", id2str(pool, s->name) + s->kind, id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
254 printf("vendor: %s\n", id2str(pool, s->vendor));
255 printids(repo, "provides", s->provides);
256 printids(repo, "obsoletes", s->obsoletes);
257 printids(repo, "conflicts", s->conflicts);
258 printids(repo, "requires", s->requires);
259 printids(repo, "recommends", s->recommends);
260 printids(repo, "suggests", s->suggests);
261 printids(repo, "supplements", s->supplements);
262 printids(repo, "enhances", s->enhances);
263 printids(repo, "freshens", s->freshens);
265 dump_attrs (repo, n - 1);
267 dump_repoattrs(repo, i);
269 dump_some_attrs(repo, s);