2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
19 #include "repo_repomdxml.h"
20 #include "common_write.h"
25 fprintf(stderr, "\nUsage:\n"
26 "repomdxml2solv [-q query]\n"
27 " reads a 'repomd.xml' file from <stdin> and writes a .solv file to <stdout>\n"
28 " -q : query a repomd data entry\n"
29 " -h : print help & exit\n"
35 doquery(Pool *pool, Repo *repo, const char *query)
42 qp = strchr(query, ':');
45 type = pool_strn2id(pool, query, qp - query, 0);
52 snprintf(qbuf, sizeof(qbuf), "repository:repomd:%s", qp);
53 id = pool_str2id(pool, qbuf, 0);
56 dataiterator_init(&di, pool, repo, SOLVID_META, id, 0, 0);
57 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
58 while (dataiterator_step(&di))
62 dataiterator_setpos_parent(&di);
63 if (pool_lookup_id(pool, SOLVID_POS, REPOSITORY_REPOMD_TYPE) != type)
69 case REPOKEY_TYPE_CONSTANTID:
70 printf("%s\n", pool_id2str(pool, di.kv.id));
72 case REPOKEY_TYPE_STR:
73 printf("%s\n", di.kv.str);
75 case REPOKEY_TYPE_NUM:
76 case REPOKEY_TYPE_CONSTANT:
77 printf("%llu\n", SOLV_KV_NUM64(&di.kv));
80 if (solv_chksum_len(di.key->type))
81 printf("%s:%s\n", solv_chksum_type2str(di.key->type), repodata_chk2str(di.data, di.key->type, (unsigned char *)di.kv.str));
85 dataiterator_free(&di);
89 main(int argc, char **argv)
92 const char *query = 0;
94 Pool *pool = pool_create();
95 Repo *repo = repo_create(pool, "<stdin>");
97 while ((c = getopt (argc, argv, "hq:")) >= 0)
112 if (repo_add_repomdxml(repo, stdin, flags))
114 fprintf(stderr, "repomdxml2solv: %s\n", pool_errstr(pool));
118 doquery(pool, repo, query);
120 tool_write(repo, 0, 0);