2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
18 #include "repo_repomdxml.h"
19 #include "common_write.h"
24 fprintf(stderr, "\nUsage:\n"
25 "repomdxml2solv [-q query]\n"
26 " reads a 'repomd.xml' file from <stdin> and writes a .solv file to <stdout>\n"
27 " -q : query a repomd data entry\n"
28 " -h : print help & exit\n"
34 doquery(Pool *pool, Repo *repo, const char *query)
41 qp = strchr(query, ':');
44 type = strn2id(pool, query, qp - query, 0);
51 snprintf(qbuf, sizeof(qbuf), "repository:repomd:%s", qp);
52 id = str2id(pool, qbuf, 0);
55 dataiterator_init(&di, pool, repo, SOLVID_META, id, 0, 0);
56 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
57 while (dataiterator_step(&di))
61 dataiterator_setpos_parent(&di);
62 if (pool_lookup_id(pool, SOLVID_POS, REPOSITORY_REPOMD_TYPE) != type)
68 case REPOKEY_TYPE_CONSTANTID:
69 printf("%s\n", id2str(pool, di.kv.id));
71 case REPOKEY_TYPE_STR:
72 printf("%s\n", di.kv.str);
74 case REPOKEY_TYPE_NUM:
75 printf("%d\n", di.kv.num);
77 case REPOKEY_TYPE_SHA1:
78 printf("sha1:%s\n", repodata_chk2str(di.data, di.key->type, (unsigned char *)di.kv.str));
80 case REPOKEY_TYPE_SHA256:
81 printf("sha256:%s\n", repodata_chk2str(di.data, di.key->type, (unsigned char *)di.kv.str));
87 dataiterator_free(&di);
91 main(int argc, char **argv)
94 const char *query = 0;
96 Pool *pool = pool_create();
97 Repo *repo = repo_create(pool, "<stdin>");
99 while ((c = getopt (argc, argv, "hq:")) >= 0)
114 repo_add_repomdxml(repo, stdin, flags);
116 doquery(pool, repo, query);
118 tool_write(repo, 0, 0);