Add the first bits of rpm file parser.
12 static const char *repo_filename = "system.repo";
13 static const char *rawhide_repo_filename = "rawhide.repo";
14 static const char *updated_repo_filename = "system-updated.repo";
17 command_list(int argc, const char *argv[])
19 struct razor_set *set;
21 set = razor_set_open(repo_filename);
22 razor_set_list(set, argv[0]);
23 razor_set_destroy(set);
29 command_list_requires(int argc, const char *argv[])
31 struct razor_set *set;
33 set = razor_set_open(repo_filename);
34 razor_set_list_properties(set, argv[0], RAZOR_PROPERTY_REQUIRES);
35 razor_set_destroy(set);
41 command_list_provides(int argc, const char *argv[])
43 struct razor_set *set;
45 set = razor_set_open(repo_filename);
46 razor_set_list_properties(set, argv[0], RAZOR_PROPERTY_PROVIDES);
47 razor_set_destroy(set);
53 command_list_obsoletes(int argc, const char *argv[])
55 struct razor_set *set;
57 set = razor_set_open(repo_filename);
58 razor_set_list_properties(set, argv[0], RAZOR_PROPERTY_OBSOLETES);
59 razor_set_destroy(set);
65 command_list_conflicts(int argc, const char *argv[])
67 struct razor_set *set;
69 set = razor_set_open(repo_filename);
70 razor_set_list_properties(set, argv[0], RAZOR_PROPERTY_CONFLICTS);
71 razor_set_destroy(set);
77 command_list_files(int argc, const char *argv[])
79 struct razor_set *set;
81 set = razor_set_open(repo_filename);
84 razor_set_list_files(set, argv[0]);
85 razor_set_destroy(set);
91 command_list_file_packages(int argc, const char *argv[])
93 struct razor_set *set;
95 set = razor_set_open(repo_filename);
98 razor_set_list_file_packages(set, argv[0]);
99 razor_set_destroy(set);
105 command_list_package_files(int argc, const char *argv[])
107 struct razor_set *set;
109 set = razor_set_open(repo_filename);
112 razor_set_list_package_files(set, argv[0]);
113 razor_set_destroy(set);
119 command_what_requires(int argc, const char *argv[])
121 struct razor_set *set;
123 set = razor_set_open(repo_filename);
124 razor_set_list_property_packages(set, argv[0], argv[1],
125 RAZOR_PROPERTY_REQUIRES);
126 razor_set_destroy(set);
132 command_what_provides(int argc, const char *argv[])
134 struct razor_set *set;
136 set = razor_set_open(repo_filename);
137 razor_set_list_property_packages(set, argv[0], argv[1],
138 RAZOR_PROPERTY_PROVIDES);
139 razor_set_destroy(set);
145 show_progress(void *clientp,
146 double dltotal, double dlnow, double ultotal, double ulnow)
148 const char *file = clientp;
150 if (!dlnow < dltotal)
151 fprintf(stderr, "\rdownloading %s, %dkB/%dkB",
152 file, (int) dlnow / 1024, (int) dltotal / 1024);
154 fprintf(stderr, "\n");
160 download_if_missing(CURL *curl, const char *url, const char *file)
168 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
169 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
170 curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress);
171 curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, file);
173 if (stat(file, &buf) < 0) {
174 fp = fopen(file, "w");
175 snprintf(buffer, sizeof buffer, "%s/%s", url, file);
176 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
177 curl_easy_setopt(curl, CURLOPT_URL, buffer);
178 res = curl_easy_perform(curl);
180 if (res != CURLE_OK) {
181 fprintf(stderr, "curl error: %s\n", error);
190 #define REPO_URL "http://download.fedora.redhat.com" \
191 "/pub/fedora/linux/development/i386/os/repodata"
194 command_import_yum(int argc, const char *argv[])
196 struct razor_set *set;
199 curl = curl_easy_init();
203 if (download_if_missing(curl, REPO_URL, "primary.xml.gz") < 0)
205 if (download_if_missing(curl, REPO_URL, "filelists.xml.gz") < 0)
207 curl_easy_cleanup(curl);
209 set = razor_set_create_from_yum();
212 razor_set_write(set, rawhide_repo_filename);
213 razor_set_destroy(set);
214 printf("wrote %s\n", rawhide_repo_filename);
220 command_import_rpmdb(int argc, const char *argv[])
222 struct razor_set *set;
224 set = razor_set_create_from_rpmdb();
227 razor_set_write(set, repo_filename);
228 razor_set_destroy(set);
229 printf("wrote %s\n", repo_filename);
235 command_validate(int argc, const char *argv[])
237 struct razor_set *set;
239 set = razor_set_open(repo_filename);
242 razor_set_list_unsatisfied(set);
243 razor_set_destroy(set);
249 command_update(int argc, const char *argv[])
251 struct razor_set *set, *upstream;
253 set = razor_set_open(repo_filename);
254 upstream = razor_set_open(rawhide_repo_filename);
255 if (set == NULL || upstream == NULL)
257 set = razor_set_update(set, upstream, argc, argv);
258 razor_set_write(set, updated_repo_filename);
259 razor_set_destroy(set);
260 razor_set_destroy(upstream);
261 printf("wrote system-updated.repo\n");
267 print_diff(const char *name,
268 const char *old_version, const char *new_version, void *data)
271 printf("removing %s %s\n", name, old_version);
273 printf("install %s %s\n", name, new_version);
277 command_diff(int argc, const char *argv[])
279 struct razor_set *set, *updated;
281 set = razor_set_open(repo_filename);
282 updated = razor_set_open(updated_repo_filename);
283 if (set == NULL || updated == NULL)
286 razor_set_diff(set, updated, print_diff, NULL);
288 razor_set_destroy(set);
289 razor_set_destroy(updated);
295 command_dump_rpm(int argc, const char *argv[])
297 razor_rpm_dump(argv[0]);
304 const char *description;
305 int (*func)(int argc, const char *argv[]);
306 } razor_commands[] = {
307 { "list", "list all packages", command_list },
308 { "list-requires", "list all requires for the given package", command_list_requires },
309 { "list-provides", "list all provides for the give package", command_list_provides },
310 { "list-obsoletes", "list all obsoletes for the give package", command_list_obsoletes },
311 { "list-conflicts", "list all conflicts for the give package", command_list_conflicts },
312 { "list-files", "list files for package set", command_list_files },
313 { "list-file-packages", "list packages owning file", command_list_file_packages },
314 { "list-package-files", "list files in package", command_list_package_files },
315 { "what-requires", "list the packages that have the given requires", command_what_requires },
316 { "what-provides", "list the packages that have the given provides", command_what_provides },
317 { "import-yum", "import yum filelist.xml on stdin", command_import_yum },
318 { "import-rpmdb", "import the system rpm database", command_import_rpmdb },
319 { "validate", "validate a package set", command_validate },
320 { "update", "update all or specified packages", command_update },
321 { "diff", "show diff between two package sets", command_diff },
322 { "dump", "dump rpm file contents", command_dump_rpm }
331 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
333 razor_commands[i].name, razor_commands[i].description);
339 main(int argc, const char *argv[])
344 repo = getenv("RAZOR_REPO");
346 repo_filename = repo;
351 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
352 if (strcmp(razor_commands[i].name, argv[1]) == 0)
353 return razor_commands[i].func(argc - 2, argv + 2);