main.c
changeset 187 6ff03223ce4c
parent 186 7f45d0401e37
child 188 a272b6ce454b
     1.1 --- a/main.c	Sat Apr 05 01:15:04 2008 -0400
     1.2 +++ b/main.c	Sat Apr 05 23:55:00 2008 -0400
     1.3 @@ -25,15 +25,25 @@
     1.4  	struct razor_set *set;
     1.5  	struct razor_package_iterator *pi;
     1.6  	struct razor_package *package;
     1.7 -	const char *pattern = argv[0], *name, *version;
     1.8 +	const char *pattern, *name, *version;
     1.9 +	int only_names = 0, i = 0;
    1.10  
    1.11 +	if (strcmp(argv[i], "--only-names") == 0) {
    1.12 +		only_names = 1;
    1.13 +		i++;
    1.14 +	}
    1.15 +
    1.16 +	pattern = argv[i];
    1.17  	set = razor_set_open(repo_filename);
    1.18  	pi = razor_package_iterator_create(set);
    1.19  	while (razor_package_iterator_next(pi, &package, &name, &version)) {
    1.20  		if (pattern && fnmatch(pattern, name, 0) != 0)
    1.21  			continue;
    1.22  
    1.23 -		printf("%s-%s\n", name, version);
    1.24 +		if (only_names)
    1.25 +			printf("%s\n", name);
    1.26 +		else
    1.27 +			printf("%s-%s\n", name, version);
    1.28  	}
    1.29  	razor_package_iterator_destroy(pi);
    1.30  	razor_set_destroy(set);
    1.31 @@ -227,8 +237,6 @@
    1.32  	if (!dlnow < dltotal)
    1.33  		fprintf(stderr, "\rdownloading %s, %dkB/%dkB",
    1.34  			file, (int) dlnow / 1024, (int) dltotal / 1024);
    1.35 -	else
    1.36 -		fprintf(stderr, "\n");
    1.37  
    1.38  	return 0;
    1.39  }
    1.40 @@ -240,7 +248,6 @@
    1.41  	char error[256];
    1.42  	FILE *fp;
    1.43  	CURLcode res;
    1.44 -	char buffer[256];
    1.45  
    1.46  	curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
    1.47  	curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
    1.48 @@ -249,9 +256,8 @@
    1.49  
    1.50  	if (stat(file, &buf) < 0) {
    1.51  		fp = fopen(file, "w");
    1.52 -		snprintf(buffer, sizeof buffer, "%s/%s", url, file);
    1.53  		curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
    1.54 -		curl_easy_setopt(curl, CURLOPT_URL, buffer);
    1.55 +		curl_easy_setopt(curl, CURLOPT_URL, url);
    1.56  		res = curl_easy_perform(curl);
    1.57  		fclose(fp);
    1.58  		if (res != CURLE_OK) {
    1.59 @@ -261,11 +267,13 @@
    1.60  		}
    1.61  	}
    1.62  
    1.63 +	fprintf(stderr, "\n");
    1.64 +
    1.65  	return 0;
    1.66  }
    1.67  
    1.68  #define REPO_URL "http://download.fedora.redhat.com" \
    1.69 -	"/pub/fedora/linux/development/i386/os/repodata"
    1.70 +	"/pub/fedora/linux/development/i386/os"
    1.71  
    1.72  static int
    1.73  command_import_yum(int argc, const char *argv[])
    1.74 @@ -277,9 +285,13 @@
    1.75  	if (curl == NULL)
    1.76  		return 1;
    1.77  
    1.78 -	if (download_if_missing(curl, REPO_URL, "primary.xml.gz") < 0)
    1.79 +	if (download_if_missing(curl,
    1.80 +				REPO_URL "/repodata/primary.xml.gz",
    1.81 +				"primary.xml.gz") < 0)
    1.82  		return -1;
    1.83 -	if (download_if_missing(curl, REPO_URL, "filelists.xml.gz") < 0)
    1.84 +	if (download_if_missing(curl,
    1.85 +				REPO_URL "/repodata/filelists.xml.gz",
    1.86 +				"filelists.xml.gz") < 0)
    1.87  		return -1;
    1.88  	curl_easy_cleanup(curl);
    1.89  
    1.90 @@ -610,6 +622,40 @@
    1.91  	return 0;
    1.92  }
    1.93  
    1.94 +static int
    1.95 +command_download(int argc, const char *argv[])
    1.96 +{
    1.97 +	struct razor_set *set;
    1.98 +	struct razor_package_iterator *pi;
    1.99 +	struct razor_package *package;
   1.100 +	const char *pattern = argv[0], *name, *version;
   1.101 +	char url[256], file[256];
   1.102 +	CURL *curl;
   1.103 +
   1.104 +	curl = curl_easy_init();
   1.105 +	if (curl == NULL)
   1.106 +		return 1;
   1.107 +
   1.108 +	set = razor_set_open(rawhide_repo_filename);
   1.109 +	pi = razor_package_iterator_create(set);
   1.110 +	while (razor_package_iterator_next(pi, &package, &name, &version)) {
   1.111 +		if (pattern && fnmatch(pattern, name, 0) != 0)
   1.112 +			continue;
   1.113 +
   1.114 +		snprintf(url, sizeof url,
   1.115 +			 REPO_URL "/Packages/%s-%s.i386.rpm", name, version);
   1.116 +		snprintf(file, sizeof file,
   1.117 +			 "rpms/%s-%s.i386.rpm", name, version);
   1.118 +		if (download_if_missing(curl, url, file) < 0)
   1.119 +			fprintf(stderr, "failed to download %s\n", name);
   1.120 +	}
   1.121 +	razor_package_iterator_destroy(pi);
   1.122 +	razor_set_destroy(set);
   1.123 +	curl_easy_cleanup(curl);
   1.124 +
   1.125 +	return 0;
   1.126 +}
   1.127 +
   1.128  static struct {
   1.129  	const char *name;
   1.130  	const char *description;
   1.131 @@ -633,7 +679,8 @@
   1.132  	{ "remove", "remove specified packages", command_remove },
   1.133  	{ "diff", "show diff between two package sets", command_diff },
   1.134  	{ "install", "install rpm", command_install },
   1.135 -	{ "init", "init razor root", command_init }
   1.136 +	{ "init", "init razor root", command_init },
   1.137 +	{ "download", "download packages", command_download }
   1.138  };
   1.139  
   1.140  static int