[pacman-dev] [patch] Display size for packages

Aaron Griffin aaronmgriffin at gmail.com
Mon May 7 11:23:56 EDT 2007


On 5/6/07, Nathan Jones <nathanj at insightbb.com> wrote:
> 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 [1].
>
> The output is a bit messy, but I find it useful regardless. Some sample
> output:
>
> $ ./pacman -Quz
> Checking for package upgrades...
>
> Remove: gaim
>
> Targets: pidgin-2.0.0-1 [7.4 MB]  alsa-lib-1.0.14rc3-2 [0.4 MB]
>          alsa-utils-1.0.14rc2-2 [1.0 MB]  binutils-2.17-3 [2.8 MB]
>          cabextract-1.2-1 [0.1 MB]  cairo-1.4.6-1 [0.5 MB]
>          esd-0.2.38-1 [0.1 MB]  filesystem-0.8-3 [0.1 MB]
>          gcc-4.1.2-4 [17.9 MB]  ghostscript-8.15.4-2 [5.7 MB]
>          gimp-2.2.14-1 [10.5 MB]  glib2-2.12.12-1 [1.2 MB]
>          gmime-2.2.8-1 [0.3 MB]  gnutls-1.6.2-1 [1.0 MB]
>          gtk2-2.10.12-1 [7.0 MB]  hal-0.5.9-2 [0.4 MB]
>          hal-info-0.20070425-1 [0.1 MB]  imlib2-1.3.0-1 [0.7 MB]
>          initscripts-0.8-7 [0.1 MB]  klibc-udev-110-2 [0.1 MB]
>          libfontenc-1.0.4-1 [0.1 MB]  libldap-2.3.35-1 [0.6 MB]
>          libxfce4util-4.4.1-3 [0.1 MB]  libxml2-2.6.28-1 [1.5 MB]
>          mutt-1.5.15-2 [1.2 MB]  namcap-1.6-1 [0.1 MB]  nano-2.0.5-1 [0.4 MB]
>          net-tools-1.60-11 [0.2 MB]  openssl-0.9.8e-3 [2.0 MB]
>          p7zip-4.45-2 [1.5 MB]  pango-1.16.4-1 [0.4 MB]
>          perl-xml-simple-2.16-2 [0.1 MB]  pygtk-2.10.4-2 [1.3 MB]
>          shared-mime-info-0.21-1 [0.5 MB]  subversion-1.4.3-3 [4.7 MB]
>          unrar-3.7.5-1 [0.1 MB]  xorg-font-utils-1.0.3-2 [0.1 MB]
>          xorg-fonts-encodings-1.0.2-2 [0.6 MB]
>
> Total Package Size:   72.20 MB
>
> $ ./pacman -Ssz pacman
> current/pacman 2.9.8-4 0.47 MB
>     A .tar.gz based package manager with dependency support
> extra/namcap 1.6-1 0.03 MB
>     A Pacman package analyzer
> extra/srcpac 0.5-1 0.01 MB
>     The pacman from-source wrapper
>
>
> I'm sure that everyone does not want to add too many flags to pacman, so
> would it be preferable to have a DisplaySize option in pacman.conf
> instead?
>
> There are quite a few places where dividing by 1024 takes place to
> display the size, and this patch adds a few more. Would it be best to
> create a humanize_size() function to switch to the appropriate measure
> (KB, MB, or GB)?
>
> [1] http://bugs.archlinux.org/task/6667?pagenum=2
>
> Signed-off-by: Nathan Jones <nathanj at insightbb.com>
>
> diff -uprN pacman-lib-old/src/pacman/conf.h pacman-lib-new/src/pacman/conf.h
> --- pacman-lib-old/src/pacman/conf.h    2007-03-05 20:21:42.000000000 -0500
> +++ pacman-lib-new/src/pacman/conf.h    2007-05-05 21:39:33.000000000 -0400
> @@ -54,6 +54,7 @@ typedef struct __config_t {
>         pmtransflag_t flags;
>         unsigned short noask;
>         unsigned int ask;
> +       unsigned short showsize;
>  } config_t;
>
>  #define FREECONF(p) do { if(p) { config_free(p); p = NULL; } } while(0)
> diff -uprN pacman-lib-old/src/pacman/pacman.c pacman-lib-new/src/pacman/pacman.c
> --- pacman-lib-old/src/pacman/pacman.c  2007-03-22 14:19:49.000000000 -0400
> +++ pacman-lib-new/src/pacman/pacman.c  2007-05-06 09:35:55.000000000 -0400
> @@ -133,6 +133,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 the size of each package\n"));
>                 } else if(op == PM_OP_SYNC) {
>                         printf(_("usage:  %s {-S --sync} [options] [package]\n"), myname);
>                         printf(_("options:\n"));
> @@ -148,6 +149,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 the 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"));
> @@ -253,6 +255,7 @@ static int parseargs(int argc, char *arg
>                 {"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},
> @@ -266,7 +269,7 @@ static int parseargs(int argc, char *arg
>         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;
>                 }
> @@ -381,6 +384,7 @@ static int parseargs(int argc, char *arg
>                                 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);
>                 }
> diff -uprN pacman-lib-old/src/pacman/query.c pacman-lib-new/src/pacman/query.c
> --- pacman-lib-old/src/pacman/query.c   2007-03-22 03:32:54.000000000 -0400
> +++ pacman-lib-new/src/pacman/query.c   2007-05-05 22:03:44.000000000 -0400
> @@ -136,6 +136,7 @@ int pacman_query(alpm_list_t *targets)
>         pmpkg_t *info = NULL;
>         char *package = NULL;
>         int done = 0;
> +       double mbsize = 0.0;
>
>         if(config->op_q_search) {
>                 alpm_list_t *ret = alpm_db_search(db_local, targets);
> @@ -147,7 +148,16 @@ 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));
> +                       if(config->showsize) {
> +                               /* Convert byte size to MB */
> +                               mbsize = (double)(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);
> diff -uprN pacman-lib-old/src/pacman/sync.c pacman-lib-new/src/pacman/sync.c
> --- pacman-lib-old/src/pacman/sync.c    2007-03-26 18:47:56.000000000 -0400
> +++ pacman-lib-new/src/pacman/sync.c    2007-05-05 22:06:01.000000000 -0400
> @@ -237,6 +237,7 @@ static int sync_synctree(int level, alpm
>  static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
>  {
>         alpm_list_t *i, *j, *ret;
> +       double mbsize = 0.0;
>
>         for(i = syncs; i; i = alpm_list_next(i)) {
>                 pmdb_t *db = (pmdb_t *)alpm_list_getdata(i);
> @@ -250,8 +251,17 @@ static int sync_search(alpm_list_t *sync
>                                 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));
> +                               if(config->showsize) {
> +                                       /* Convert byte size to MB */
> +                                       mbsize = (double)(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);
> diff -uprN pacman-lib-old/src/pacman/util.c pacman-lib-new/src/pacman/util.c
> --- pacman-lib-old/src/pacman/util.c    2007-03-13 12:15:38.000000000 -0400
> +++ pacman-lib-new/src/pacman/util.c    2007-05-05 22:07:31.000000000 -0400
> @@ -270,8 +270,8 @@ void display_targets(alpm_list_t *syncpk
>         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);
> @@ -294,10 +294,20 @@ void display_targets(alpm_list_t *syncpk
>                         }
>                 }
>
> -               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 = (double)(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);
>         }

Great, thanks a lot.  This would close out http://bugs.archlinux.org/task/6667.

I will take a look tonight.  Thanks for the work!




More information about the pacman-dev mailing list