xbps: merge xbps-{install,remove} column output mode from master.

This commit is contained in:
Juan RP 2014-10-31 10:09:28 +01:00
parent 5791a82cd0
commit 2e275570ab
5 changed files with 374 additions and 4 deletions

View file

@ -0,0 +1,25 @@
From 12e18ae5796cdf0b1ec05b31a41380c6dbbe241f Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 30 Oct 2014 10:59:42 +0100
Subject: [PATCH 1/4] bin/xbps-install/util.c: use STDOUT_FILENO.
---
bin/xbps-install/util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bin/xbps-install/util.c b/bin/xbps-install/util.c
index 3be2baf..9594877 100644
--- bin/xbps-install/util.c
+++ bin/xbps-install/util.c
@@ -40,7 +40,7 @@ get_maxcols(void)
{
struct winsize ws;
- if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) == 0)
+ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
return ws.ws_col ? ws.ws_col : 80;
return 80;
--
2.1.3

View file

@ -0,0 +1,24 @@
From 3f7cd86d9d4e291a148016be9da379db52ac2d37 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 30 Oct 2014 11:00:01 +0100
Subject: [PATCH 2/4] bin/xbps-query/list.c: remove unused header.
---
bin/xbps-query/list.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/bin/xbps-query/list.c b/bin/xbps-query/list.c
index 73ba667..8532dc9 100644
--- bin/xbps-query/list.c
+++ bin/xbps-query/list.c
@@ -29,7 +29,6 @@
#include <errno.h>
#include <string.h>
#include <assert.h>
-#include <sys/ioctl.h>
#include "defs.h"
--
2.1.3

View file

@ -0,0 +1,295 @@
From b179c16fc096a8c549c860d34aa838fcc3cfb5b4 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 30 Oct 2014 11:23:10 +0100
Subject: [PATCH 3/4] xbps-{install,remove}: implemented column/wide output
mode.
See https://github.com/voidlinux/xbps/issues/63 for info.
Close #63
---
NEWS | 5 ++
bin/xbps-install/defs.h | 12 +++++
bin/xbps-install/transaction.c | 99 +++++++++++++++++--------------------
bin/xbps-install/util.c | 109 ++++++++++++++++++++++++++++++++++++++++-
4 files changed, 170 insertions(+), 55 deletions(-)
diff --git a/bin/xbps-install/defs.h b/bin/xbps-install/defs.h
index 3a9b718..a8d0c7e 100644
--- bin/xbps-install/defs.h
+++ bin/xbps-install/defs.h
@@ -34,6 +34,17 @@ struct xferstat {
struct timeval last;
};
+struct transaction {
+ struct xbps_handle *xhp;
+ xbps_dictionary_t d;
+ xbps_object_iterator_t iter;
+ uint32_t inst_pkgcnt;
+ uint32_t up_pkgcnt;
+ uint32_t cf_pkgcnt;
+ uint32_t rm_pkgcnt;
+ uint32_t dl_pkgcnt;
+};
+
/* from transaction.c */
int install_new_pkg(struct xbps_handle *, const char *, bool);
int update_pkg(struct xbps_handle *, const char *);
@@ -52,6 +63,7 @@ int state_cb(const struct xbps_state_cb_data *, void *);
/* From util.c */
void print_package_line(const char *, int, bool);
+bool print_trans_colmode(struct transaction *, int);
int get_maxcols(void);
#endif /* !_XBPS_INSTALL_DEFS_H_ */
diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c
index efd964a..7280ee4 100644
--- bin/xbps-install/transaction.c
+++ bin/xbps-install/transaction.c
@@ -36,17 +36,6 @@
#include <xbps.h>
#include "defs.h"
-struct transaction {
- struct xbps_handle *xhp;
- xbps_dictionary_t d;
- xbps_object_iterator_t iter;
- uint32_t inst_pkgcnt;
- uint32_t up_pkgcnt;
- uint32_t cf_pkgcnt;
- uint32_t rm_pkgcnt;
- uint32_t dl_pkgcnt;
-};
-
static void
print_array(xbps_array_t a)
{
@@ -128,49 +117,51 @@ show_transaction_sizes(struct transaction *trans, int cols)
uint64_t dlsize = 0, instsize = 0, rmsize = 0, disk_free_size = 0;
char size[8];
- /*
- * Show the list of packages that will be downloaded, installed, updated,
- * removed or configured.
- */
- xbps_dictionary_get_uint32(trans->d, "total-download-pkgs",
- &trans->dl_pkgcnt);
- if (trans->dl_pkgcnt) {
- printf("%u package%s will be downloaded:\n",
- trans->dl_pkgcnt, trans->dl_pkgcnt == 1 ? "" : "s");
- show_package_list(trans, NULL, cols);
- printf("\n");
- }
- xbps_dictionary_get_uint32(trans->d, "total-install-pkgs",
- &trans->inst_pkgcnt);
- if (trans->inst_pkgcnt) {
- printf("%u package%s will be installed:\n",
- trans->inst_pkgcnt, trans->inst_pkgcnt == 1 ? "" : "s");
- show_package_list(trans, "install", cols);
- printf("\n");
- }
- xbps_dictionary_get_uint32(trans->d, "total-update-pkgs",
- &trans->up_pkgcnt);
- if (trans->up_pkgcnt) {
- printf("%u package%s will be updated:\n",
- trans->up_pkgcnt, trans->up_pkgcnt == 1 ? "" : "s");
- show_package_list(trans, "update", cols);
- printf("\n");
- }
- xbps_dictionary_get_uint32(trans->d, "total-configure-pkgs",
- &trans->cf_pkgcnt);
- if (trans->cf_pkgcnt) {
- printf("%u package%s will be configured:\n",
- trans->cf_pkgcnt, trans->cf_pkgcnt == 1 ? "" : "s");
- show_package_list(trans, "configure", cols);
- printf("\n");
- }
- xbps_dictionary_get_uint32(trans->d, "total-remove-pkgs",
- &trans->rm_pkgcnt);
- if (trans->rm_pkgcnt) {
- printf("%u package%s will be removed:\n",
- trans->rm_pkgcnt, trans->rm_pkgcnt == 1 ? "" : "s");
- show_package_list(trans, "remove", cols);
- printf("\n");
+ if (!print_trans_colmode(trans, cols)) {
+ /*
+ * Show the list of packages that will be downloaded, installed, updated,
+ * removed or configured.
+ */
+ xbps_dictionary_get_uint32(trans->d, "total-download-pkgs",
+ &trans->dl_pkgcnt);
+ if (trans->dl_pkgcnt) {
+ printf("%u package%s will be downloaded:\n",
+ trans->dl_pkgcnt, trans->dl_pkgcnt == 1 ? "" : "s");
+ show_package_list(trans, NULL, cols);
+ printf("\n");
+ }
+ xbps_dictionary_get_uint32(trans->d, "total-install-pkgs",
+ &trans->inst_pkgcnt);
+ if (trans->inst_pkgcnt) {
+ printf("%u package%s will be installed:\n",
+ trans->inst_pkgcnt, trans->inst_pkgcnt == 1 ? "" : "s");
+ show_package_list(trans, "install", cols);
+ printf("\n");
+ }
+ xbps_dictionary_get_uint32(trans->d, "total-update-pkgs",
+ &trans->up_pkgcnt);
+ if (trans->up_pkgcnt) {
+ printf("%u package%s will be updated:\n",
+ trans->up_pkgcnt, trans->up_pkgcnt == 1 ? "" : "s");
+ show_package_list(trans, "update", cols);
+ printf("\n");
+ }
+ xbps_dictionary_get_uint32(trans->d, "total-configure-pkgs",
+ &trans->cf_pkgcnt);
+ if (trans->cf_pkgcnt) {
+ printf("%u package%s will be configured:\n",
+ trans->cf_pkgcnt, trans->cf_pkgcnt == 1 ? "" : "s");
+ show_package_list(trans, "configure", cols);
+ printf("\n");
+ }
+ xbps_dictionary_get_uint32(trans->d, "total-remove-pkgs",
+ &trans->rm_pkgcnt);
+ if (trans->rm_pkgcnt) {
+ printf("%u package%s will be removed:\n",
+ trans->rm_pkgcnt, trans->rm_pkgcnt == 1 ? "" : "s");
+ show_package_list(trans, "remove", cols);
+ printf("\n");
+ }
}
/*
* Show total download/installed/removed size for all required packages.
diff --git a/bin/xbps-install/util.c b/bin/xbps-install/util.c
index 9594877..3fb68a7 100644
--- bin/xbps-install/util.c
+++ bin/xbps-install/util.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2008-2013 Juan Romero Pardines.
+ * Copyright (c) 2008-2014 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,7 @@
#include <string.h>
#include <strings.h>
#include <sys/ioctl.h>
+#include <assert.h>
#include <xbps.h>
#include "defs.h"
@@ -69,3 +70,109 @@ print_package_line(const char *str, int maxcols, bool reset)
}
printf("%s ", str);
}
+
+static unsigned int
+find_longest_pkgname(struct transaction *trans)
+{
+ xbps_object_t obj;
+ const char *pkgver;
+ char *pkgname;
+ unsigned int len = 0, max = 0;
+
+ while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) {
+ xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
+ pkgname = xbps_pkg_name(pkgver);
+ assert(pkgname);
+ len = strlen(pkgname);
+ free(pkgname);
+ if (max == 0 || len > max)
+ max = len;
+ }
+ xbps_object_iterator_reset(trans->iter);
+ return max+1;
+}
+
+bool
+print_trans_colmode(struct transaction *trans, int cols)
+{
+ xbps_object_t obj;
+ uint64_t dlsize = 0;
+ char size[8];
+ unsigned int x, blen, pnamelen;
+ int hdrlen;
+
+ pnamelen = find_longest_pkgname(trans);
+ /* header length */
+ hdrlen = 4 + pnamelen + 48;
+ if (cols <= hdrlen)
+ return false;
+
+ printf("Name");
+ for (x = 4; x < pnamelen; x++)
+ printf(" ");
+ printf("Action Version New version Download size\n");
+
+ while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) {
+ xbps_dictionary_t ipkgd;
+ const char *pkgver, *ipkgver, *ver, *iver, *tract;
+ char *pkgname;
+ bool dload = false;
+
+ ver = iver = NULL;
+
+ xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
+ xbps_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
+ xbps_dictionary_get_uint64(obj, "filename-size", &dlsize);
+ xbps_dictionary_get_bool(obj, "download", &dload);
+
+ pkgname = xbps_pkg_name(pkgver);
+ assert(pkgname);
+
+ if ((strcmp(tract, "update") == 0) || strcmp(tract, "remove") == 0) {
+ ipkgd = xbps_pkgdb_get_pkg(trans->xhp, pkgname);
+ assert(ipkgd);
+ xbps_dictionary_get_cstring_nocopy(ipkgd, "pkgver", &ipkgver);
+ iver = xbps_pkg_version(ipkgver);
+ }
+ ver = xbps_pkg_version(pkgver);
+
+ /* print pkgname and some blanks */
+ blen = pnamelen - strlen(pkgname);
+ printf("%s", pkgname);
+ for (x = 0; x < blen; x++)
+ printf(" ");
+
+ /* print action */
+ printf("%s ", tract);
+ for (x = strlen(tract); x < 7; x++)
+ printf(" ");
+
+ /* print installed version */
+ if (iver == NULL)
+ iver = "-";
+
+ /* print new version */
+ printf("%s ", iver);
+ for (x = strlen(iver); x < 14; x++)
+ printf(" ");
+
+ if (strcmp(tract, "remove") == 0) {
+ ver = "-";
+ }
+ if (dload)
+ (void)xbps_humanize_number(size, (int64_t)dlsize);
+ else {
+ size[0] = '-';
+ size[1] = '\0';
+ }
+ printf("%s ", ver);
+ for (x = strlen(ver); x < 18; x++)
+ printf(" ");
+ /* print download size */
+ printf("%s ", size);
+ printf("\n");
+ free(pkgname);
+ }
+ xbps_object_iterator_reset(trans->iter);
+ return true;
+}
--
2.1.3

View file

@ -0,0 +1,25 @@
From 59781f4e91b798d63ad38e0d43ef0c0c2fe5f34c Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 30 Oct 2014 11:25:37 +0100
Subject: [PATCH 4/4] bin/xbps-install/fetch_cb.c: use STDOUT_FILENO.
---
bin/xbps-install/fetch_cb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bin/xbps-install/fetch_cb.c b/bin/xbps-install/fetch_cb.c
index fb1a069..8b715a9 100644
--- bin/xbps-install/fetch_cb.c
+++ bin/xbps-install/fetch_cb.c
@@ -162,7 +162,7 @@ fetch_file_progress_cb(const struct xbps_fetch_cb_data *xfpd, void *cbdata)
if (xfpd->cb_start) {
/* start transfer stats */
- v_tty = isatty(STDERR_FILENO);
+ v_tty = isatty(STDOUT_FILENO);
get_time(&xfer->start);
xfer->last.tv_sec = xfer->last.tv_usec = 0;
} else if (xfpd->cb_update) {
--
2.1.3

View file

@ -1,15 +1,13 @@
# Template file for 'xbps'
pkgname=xbps
version=0.41
revision=5
revision=6
bootstrap=yes
build_style=configure
short_desc="The XBPS package system utilities"
maintainer="Juan RP <xtraeme@gmail.com>"
homepage="http://www.voidlinux.eu/xbps"
license="Simplified BSD"
distfiles="https://github.com/voidlinux/xbps/archive/${version}.tar.gz"
checksum=e9d7d9a50e549be7069d328277dfae466acf53cbda59ef99eae7bbe9a096ee76
makedepends="zlib-devel libressl-devel libarchive-devel>=3.1.2"
depends="xbps-triggers>=0.75"
@ -19,7 +17,7 @@ if [ -z "$CHROOT_READY" ]; then
CFLAGS+=" -idirafter ${XBPS_MASTERDIR}/usr/include"
LDFLAGS+=" -L${XBPS_MASTERDIR}/usr/lib"
else
hostmakedepends="pkg-config"
hostmakedepends="pkg-config git"
makedepends+=" atf-devel>=0.21"
xbps-tests_package() {
@ -36,6 +34,9 @@ if [ "$XBPS_TARGET_MACHINE" = "i686-musl" ]; then
CFLAGS+=" -fno-stack-protector"
fi
do_fetch() {
git clone -b${version} git://github.com/voidlinux/xbps ${pkgname}-${version}
}
do_configure() {
if [ "$CHROOT_READY" ]; then
_args="--enable-tests"