Display size for packages

This patch adds a -z|--showsize option to the -Q and -S commands. The
option displays the size of individual packages. This is something that
I have wanted for a while, and there is a feature request for it.

Signed-off-by: Nathan Jones <nathanj@insightbb.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Nathan Jones 2007-05-14 01:21:42 -04:00 committed by Dan McGee
parent 14c768365c
commit 5c930c318e
5 changed files with 47 additions and 11 deletions

View File

@ -54,6 +54,7 @@ typedef struct __config_t {
pmtransflag_t flags;
unsigned short noask;
unsigned int ask;
unsigned short showsize;
} config_t;
config_t *config_new(void);

View File

@ -131,6 +131,7 @@ static void usage(int op, char *myname)
printf(_(" -p, --file <package> query a package file instead of the database\n"));
printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n"));
printf(_(" -u, --upgrades list all packages that can be upgraded\n"));
printf(_(" -z, --showsize display installed size of each package\n"));
} else if(op == PM_OP_SYNC) {
printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
printf("%s:\n", str_opt);
@ -146,6 +147,7 @@ static void usage(int op, char *myname)
printf(_(" -u, --sysupgrade upgrade all packages that are out of date\n"));
printf(_(" -w, --downloadonly download packages but do not install/upgrade anything\n"));
printf(_(" -y, --refresh download fresh package databases from the server\n"));
printf(_(" -z, --showsize display download size of each package\n"));
printf(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n"));
}
printf(_(" --config <path> set an alternate configuration file\n"));
@ -291,6 +293,7 @@ static int parseargs(int argc, char *argv[])
{"verbose", no_argument, 0, 'v'},
{"downloadonly", no_argument, 0, 'w'},
{"refresh", no_argument, 0, 'y'},
{"showsize", no_argument, 0, 'z'},
{"noconfirm", no_argument, 0, 1000},
{"config", required_argument, 0, 1001},
{"ignore", required_argument, 0, 1002},
@ -304,7 +307,7 @@ static int parseargs(int argc, char *argv[])
struct stat st;
unsigned short logmask;
while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepiuwyg", opts, &option_index))) {
while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepiuwygz", opts, &option_index))) {
if(opt < 0) {
break;
}
@ -423,6 +426,7 @@ static int parseargs(int argc, char *argv[])
config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
break;
case 'y': (config->op_s_sync)++; break;
case 'z': config->showsize = 1; break;
case '?': return(1);
default: return(1);
}

View File

@ -146,7 +146,17 @@ int pacman_query(alpm_list_t *targets)
alpm_list_t *grp;
pmpkg_t *pkg = alpm_list_getdata(i);
printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
/* print the package size with the output if -z option passed */
if(config->showsize) {
/* Convert byte size to MB */
double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
printf("local/%s %s [%.2f MB]", alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg), mbsize);
} else {
printf("local/%s %s", alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
}
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
group = alpm_list_getdata(grp);

View File

@ -251,8 +251,19 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_t *grp;
pmpkg_t *pkg = alpm_list_getdata(j);
printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
/* print the package size with the output if -z option passed */
if(config->showsize) {
/* Convert byte size to MB */
double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
printf("%s/%s %s [%.2f MB]", alpm_db_get_name(db),
alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg), mbsize);
} else {
printf("%s/%s %s", alpm_db_get_name(db),
alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
}
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
group = alpm_list_getdata(grp);

View File

@ -266,8 +266,8 @@ void display_targets(alpm_list_t *syncpkgs)
alpm_list_t *i, *j;
alpm_list_t *targets = NULL, *to_remove = NULL;
/* TODO these are some messy variable names */
unsigned long size = 0, isize = 0, rsize = 0;
double mbsize = 0.0, mbisize = 0.0, mbrsize = 0.0;
unsigned long size = 0, isize = 0, rsize = 0, dispsize = 0;
double mbsize = 0.0, mbisize = 0.0, mbrsize = 0.0, mbdispsize = 0.0;
for(i = syncpkgs; i; i = alpm_list_next(i)) {
pmsyncpkg_t *sync = alpm_list_getdata(i);
@ -290,17 +290,27 @@ void display_targets(alpm_list_t *syncpkgs)
}
}
size += alpm_pkg_get_size(pkg);
dispsize = alpm_pkg_get_size(pkg);
size += dispsize;
isize += alpm_pkg_get_isize(pkg);
asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
if(config->showsize) {
/* Convert byte size to MB */
mbdispsize = dispsize / (1024.0 * 1024.0);
asprintf(&str, "%s-%s [%.1f MB]", alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg), (mbdispsize < 0.1 ? 0.1 : mbdispsize));
} else {
asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
}
targets = alpm_list_add(targets, str);
}
/* Convert byte sizes to MB */
mbsize = (double)(size) / (1024.0 * 1024.0);
mbisize = (double)(isize) / (1024.0 * 1024.0);
mbrsize = (double)(rsize) / (1024.0 * 1024.0);
mbsize = size / (1024.0 * 1024.0);
mbisize = isize / (1024.0 * 1024.0);
mbrsize = rsize / (1024.0 * 1024.0);
/* start displaying information */
printf("\n");