2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
17 #include "repo_repomdxml.h"
18 #include "common_write.h"
23 fprintf(stderr, "\nUsage:\n"
24 "repomdxml2solv [-q query]\n"
25 " reads a 'repomd.xml' file from <stdin> and writes a .solv file to <stdout>\n"
26 " -q : query a repomd data entry\n"
27 " -h : print help & exit\n"
33 doquery(Pool *pool, Repo *repo, const char *query)
40 qp = strchr(query, ':');
43 type = pool_strn2id(pool, query, qp - query, 0);
50 snprintf(qbuf, sizeof(qbuf), "repository:repomd:%s", qp);
51 id = pool_str2id(pool, qbuf, 0);
54 dataiterator_init(&di, pool, repo, SOLVID_META, id, 0, 0);
55 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
56 while (dataiterator_step(&di))
60 dataiterator_setpos_parent(&di);
61 if (pool_lookup_id(pool, SOLVID_POS, REPOSITORY_REPOMD_TYPE) != type)
67 case REPOKEY_TYPE_CONSTANTID:
68 printf("%s\n", pool_id2str(pool, di.kv.id));
70 case REPOKEY_TYPE_STR:
71 printf("%s\n", di.kv.str);
73 case REPOKEY_TYPE_NUM:
74 case REPOKEY_TYPE_CONSTANT:
75 printf("%llu\n", SOLV_KV_NUM64(&di.kv));
78 if (solv_chksum_len(di.key->type))
79 printf("%s:%s\n", solv_chksum_type2str(di.key->type), repodata_chk2str(di.data, di.key->type, (unsigned char *)di.kv.str));
83 dataiterator_free(&di);
87 main(int argc, char **argv)
90 const char *query = 0;
92 Pool *pool = pool_create();
93 Repo *repo = repo_create(pool, "<stdin>");
95 while ((c = getopt (argc, argv, "hq:")) >= 0)
110 if (repo_add_repomdxml(repo, stdin, flags))
112 fprintf(stderr, "repomdxml2solv: %s\n", pool_errstr(pool));
116 doquery(pool, repo, query);
118 tool_write(repo, stdout);