Display progress when importing rpms
authorJames Bowes <jbowes@redhat.com>
Mon Jun 23 14:04:47 2008 -0400 (2008-06-23)
changeset 26323c56c3f0449
parent 262 63644cc28e0b
child 264 634e54ca476c
Display progress when importing rpms
src/import-rpmdb.c
src/import-yum.c
src/main.c
     1.1 --- a/src/import-rpmdb.c	Mon Jun 23 13:54:56 2008 -0400
     1.2 +++ b/src/import-rpmdb.c	Mon Jun 23 14:04:47 2008 -0400
     1.3 @@ -90,6 +90,7 @@
     1.4  	union rpm_entry basenames, dirnames, dirindexes;
     1.5  	char filename[PATH_MAX], evr[128], buf[16];
     1.6  	rpmdb db;
     1.7 +	int imported_count = 0;
     1.8  
     1.9  	rpmReadConfigFiles(NULL, NULL);
    1.10  
    1.11 @@ -162,9 +163,13 @@
    1.12  		}
    1.13  
    1.14  		razor_importer_finish_package(importer);
    1.15 +
    1.16 +		printf("\rimporting %d", ++imported_count);
    1.17 +		fflush(stdout);
    1.18  	}
    1.19  
    1.20  	rpmdbClose(db);
    1.21  
    1.22 +	printf("\nsaving\n");
    1.23  	return razor_importer_finish(importer);
    1.24  }
     2.1 --- a/src/import-yum.c	Mon Jun 23 13:54:56 2008 -0400
     2.2 +++ b/src/import-yum.c	Mon Jun 23 14:04:47 2008 -0400
     2.3 @@ -62,6 +62,8 @@
     2.4  	char pkgid[128];
     2.5  	uint32_t property_type;
     2.6  	int state;
     2.7 +
     2.8 +	int total, current;
     2.9  };
    2.10  
    2.11  static uint32_t
    2.12 @@ -90,7 +92,12 @@
    2.13  	uint32_t pre, relation, flags;
    2.14  	int i;
    2.15  
    2.16 -	if (strcmp(name, "name") == 0) {
    2.17 +	if (strcmp(name, "metadata") == 0) {
    2.18 +		for (i = 0; atts[i]; i += 2) {
    2.19 +			if (strcmp(atts[i], "packages") == 0)
    2.20 +				ctx->total = atoi(atts[i + 1]);
    2.21 +		}
    2.22 +	} else if (strcmp(name, "name") == 0) {
    2.23  		ctx->state = YUM_STATE_PACKAGE_NAME;
    2.24  		ctx->p = ctx->name;
    2.25  	} else if (strcmp(name, "arch") == 0) {
    2.26 @@ -208,6 +215,9 @@
    2.27  
    2.28  		XML_StopParser(ctx->current_parser, XML_TRUE);
    2.29  		ctx->current_parser = ctx->filelists_parser;
    2.30 +
    2.31 +		printf("\rimporting %d/%d", ++ctx->current, ctx->total);
    2.32 +		fflush(stdout);
    2.33  	}
    2.34  }
    2.35  
    2.36 @@ -313,6 +323,8 @@
    2.37  
    2.38  	ctx.current_parser = ctx.primary_parser;
    2.39  
    2.40 +	ctx.current = 0;
    2.41 +
    2.42  	do {
    2.43  		XML_GetParsingStatus(ctx.current_parser, &status);
    2.44  		switch (status.parsing) {
    2.45 @@ -348,5 +360,6 @@
    2.46  	gzclose(primary);
    2.47  	gzclose(filelists);
    2.48  
    2.49 +	printf ("\nsaving\n");
    2.50  	return razor_importer_finish(ctx.importer);
    2.51  }
     3.1 --- a/src/main.c	Mon Jun 23 13:54:56 2008 -0400
     3.2 +++ b/src/main.c	Mon Jun 23 14:04:47 2008 -0400
     3.3 @@ -535,7 +535,7 @@
     3.4  	struct razor_importer *importer;
     3.5  	struct razor_set *set;
     3.6  	struct razor_rpm *rpm;
     3.7 -	int len;
     3.8 +	int len, imported_count = 0;
     3.9  	char filename[256];
    3.10  	const char *dirname = argv[0];
    3.11  
    3.12 @@ -569,6 +569,9 @@
    3.13  			break;
    3.14  		}
    3.15  		razor_rpm_close(rpm);
    3.16 +
    3.17 +		printf("\rimporting %d", ++imported_count);
    3.18 +		fflush(stdout);
    3.19  	}
    3.20  
    3.21  	if (de != NULL) {
    3.22 @@ -576,6 +579,7 @@
    3.23  		return -1;
    3.24  	}
    3.25  
    3.26 +	printf("\nsaving\n");
    3.27  	set = razor_importer_finish(importer);
    3.28  
    3.29  	razor_set_write(set, repo_filename, RAZOR_REPO_FILE_MAIN);