[pacman-dev] [PATCH 1/2] contrib: adding pacsize
Printing package size is useful for maintenance. Indeed, the first entry on the wiki is focused on this topic: https://wiki.archlinux.org/index.php/Pacman_Tips#Maintenance None of the proposed solutions will allow you to: - select packages; - work on the output of other commands yielding a list of packages; - change the sorting; - be locale independent; - print a grand total; - be fast (most solutions are wasting a lot of time -- only expac is faster); - not rely on any third-party tool. Pacsize is a POSIX shell script that is generic enough to enclose all these features (and more). Adding a 'pacsize' script eliminates the unneeded abundance of workarounds for this simple matter. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/.gitignore | 1 + contrib/Makefile.am | 3 + contrib/README | 4 ++ contrib/pacsize.sh.in | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 contrib/pacsize.sh.in diff --git a/contrib/.gitignore b/contrib/.gitignore index a181813..9cecd5e 100644 --- a/contrib/.gitignore +++ b/contrib/.gitignore @@ -7,6 +7,7 @@ paclist paclog-pkglist pacscripts pacsearch +pacsize pacsysclean rankmirrors updpkgsums diff --git a/contrib/Makefile.am b/contrib/Makefile.am index f6ca3f1..8c5c6da 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -12,6 +12,7 @@ BASHSCRIPTS = \ paclist \ paclog-pkglist \ pacscripts \ + pacsize \ pacsysclean \ rankmirrors \ updpkgsums @@ -38,6 +39,7 @@ EXTRA_DIST = \ paclist.sh.in \ pacscripts.sh.in \ pacsearch.in \ + pacsize.sh.in \ pacsysclean.sh.in \ rankmirrors.sh.in \ updpkgsums.sh.in \ @@ -102,6 +104,7 @@ paclist: $(srcdir)/paclist.sh.in paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in pacscripts: $(srcdir)/pacscripts.sh.in pacsearch: $(srcdir)/pacsearch.in +pacsize: $(srcdir)/pacsize.sh.in pacsysclean: $(srcdir)/pacsysclean.sh.in rankmirrors: $(srcdir)/rankmirrors.sh.in updpkgsums: $(srcdir)/updpkgsums.sh.in diff --git a/contrib/README b/contrib/README index ae33bb2..4f5c17f 100644 --- a/contrib/README +++ b/contrib/README @@ -31,6 +31,10 @@ pacsearch - a colorized search combining both -Ss and -Qs output. Installed packages are easily identified with a *** and local-only packages are also listed. +pacsize - display the size of packages. Duplicates are removed if any. The local +database is queried first; if the package is not found, the sync database is +then used for lookup. + pacsysclean - lists installed packages sorted by size. rankmirrors - ranks pacman mirrors by their connection and opening speed. diff --git a/contrib/pacsize.sh.in b/contrib/pacsize.sh.in new file mode 100644 index 0000000..4d84734 --- /dev/null +++ b/contrib/pacsize.sh.in @@ -0,0 +1,159 @@ +#!/bin/sh +# pacsize -- display package sizes +# +# Copyright (C) 2014 Pierre Neidhardt <ambrevar@gmail.com> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +readonly myname='pacsize' +readonly myver='@PACKAGE_VERSION@' + +calc_total () { + awk '{ + total += $1 + print +} +END { + printf ("%7s KIB TOTAL\n", total) +}' +} + +error () { + echo "$@" >&2 +} + +## Print size and name. We strip the arguably useless decimals. This makes +## output lighter. +filter () { + awk -F ": " \ + '$0 ~ "Name" { + pkg = $2 +} +$0 ~ "Installed Size" { + gsub (/[\.,].*/, "") + printf ("%7s KiB %s\n", $2, pkg) +}' +} + +remove_duplicates () { + awk '! table[$0]++' +} + +usage () { + cat <<EOF +Usage: ${1##*/} [OPTIONS] PACKAGES + ${1##*/} -a [OPTIONS] + +Display the size of PACKAGES. Duplicates are removed if any. The local database +is queried first; if the package is not found, the sync database is then used +for lookup. + +Options: + + -a: Process all installed packages. + -h: Show this help. + -n: Sort output by name. + -s: Sort output by size. + -t: Print total. + +Examples: + + $ ${1##*/} -ast + Convenient way to keep track of big packages. + + $ ${1##*/} \$(pactree -ld1 linux) + Print the size of linux and all its direct dependencies. + + $ ${1##*/} -st \$(pacman -Qdtq) + Print a grand total of orphan packages, and sort by size. +EOF +} + +version () { + echo "$myname $myver" + echo 'Copyright (C) 2014 Pierre Neidhardt <ambrevar@gmail.com>' +} + +opt_sort=false +opt_all=false +opt_total=false + +while getopts ":ahnstv" opt; do + case $opt in + a) + opt_all=true ;; + h) + usage "$0" + exit ;; + n) + opt_sort="sort -uk3" ;; + s) + opt_sort="sort -un" ;; + t) + opt_total="calc_total" ;; + v) + version "$0" + exit ;; + ?) + usage "$0" + exit 1 ;; + esac +done + +shift $(($OPTIND - 1)) + +## All-packages mode. +## We use a dedicated algorithm which is much faster than per-package mode. +## Unfortunately there is no easy way to select packages with this method. +if $opt_all; then + DBPath="$(awk -F = '/^ *DBPath/{print $2}' @sysconfdir@/pacman.conf 2>/dev/null)" + [ ! -d "$DBPath" ] && DBPath="@localstatedir@/lib/pacman" + + if [ ! -d "$DBPath/local/" ]; then + error "Could not find local database in $DBPath/local/." + exit 1 + fi + + awk '/^%NAME%/ { + getline + pkg=$0 +} +/^%SIZE%/ { + getline + size = $0 / 1024 + printf ("%6s KiB %s\n", size, pkg) +}' "$DBPath"/local/*/desc | ($opt_sort || cat) | ($opt_total || cat) + exit +fi + +## Per-package mode. +if [ $# -eq 0 ]; then + error "Missing argument." + usage "$0" + exit 1 +fi + +if ! command -v pacman >/dev/null 2>&1; then + error "'pacman' not found." + exit 1 +fi + +{ + ## If package is not found locally (-Q), we use the sync database (-S). We + ## use LC_ALL=C to make sure pacman output is not localized. + buffer=$(LC_ALL=C pacman -Qi "$@" 2>&1 1>&3 3>&- | cut -f2 -d "'") + [ -n "$buffer" ] && LC_ALL=C pacman -Si $buffer +} 3>&1 | filter | ($opt_sort || remove_duplicates) | ($opt_total || cat) + +# vim: set noet: -- 1.9.0
pacsysclean is made obsolete by pacsize: - it has no package selection ability; - it is slower; - it has no support for non-enlish locales (for which it does not work at all). pacsysclean has an '-o' option to pass argument to pacman. This is somewhat clumsy and can lead to unexpected behaviours. The suggested use $ pacsysclean -o dt can be replaced by $ pacsize $(pacman -Qqdt) which is faster, in spite of the double call to pacman. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/.gitignore | 1 - contrib/Makefile.am | 3 --- contrib/README | 2 -- contrib/pacsysclean.sh.in | 66 ----------------------------------------------- 4 files changed, 72 deletions(-) delete mode 100644 contrib/pacsysclean.sh.in diff --git a/contrib/.gitignore b/contrib/.gitignore index 9cecd5e..954c1e2 100644 --- a/contrib/.gitignore +++ b/contrib/.gitignore @@ -8,7 +8,6 @@ paclog-pkglist pacscripts pacsearch pacsize -pacsysclean rankmirrors updpkgsums zsh_completion diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 8c5c6da..d22b621 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -13,7 +13,6 @@ BASHSCRIPTS = \ paclog-pkglist \ pacscripts \ pacsize \ - pacsysclean \ rankmirrors \ updpkgsums @@ -40,7 +39,6 @@ EXTRA_DIST = \ pacscripts.sh.in \ pacsearch.in \ pacsize.sh.in \ - pacsysclean.sh.in \ rankmirrors.sh.in \ updpkgsums.sh.in \ vimprojects \ @@ -105,7 +103,6 @@ paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in pacscripts: $(srcdir)/pacscripts.sh.in pacsearch: $(srcdir)/pacsearch.in pacsize: $(srcdir)/pacsize.sh.in -pacsysclean: $(srcdir)/pacsysclean.sh.in rankmirrors: $(srcdir)/rankmirrors.sh.in updpkgsums: $(srcdir)/updpkgsums.sh.in zsh_completion: $(srcdir)/zsh_completion.in diff --git a/contrib/README b/contrib/README index 4f5c17f..f8bd952 100644 --- a/contrib/README +++ b/contrib/README @@ -35,8 +35,6 @@ pacsize - display the size of packages. Duplicates are removed if any. The local database is queried first; if the package is not found, the sync database is then used for lookup. -pacsysclean - lists installed packages sorted by size. - rankmirrors - ranks pacman mirrors by their connection and opening speed. updpkgsums - performs an in place update of the checksums in a PKGBUILD. diff --git a/contrib/pacsysclean.sh.in b/contrib/pacsysclean.sh.in deleted file mode 100644 index 8f2eea3..0000000 --- a/contrib/pacsysclean.sh.in +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -# pacsysclean - Sort installed packages by increasing installed size. Useful for system clean-up. - -declare -r myname='pacsysclean' -declare -r myver='@PACKAGE_VERSION@' - -PACMAN_OPTS= - -usage() { - echo "${myname} (pacman) v${myver}" - echo - echo "Sort installed packages by increasing installed size. Useful for" - echo "system clean-up." - echo - echo "Usage: ${myname} [options]" - echo - echo "Options:" - echo " -o <options> Specify custom pacman query options (e.g., dt)" - echo " -h, --help Show this help message and exit" -} - -version() { - printf "%s %s\n" "$myname" "$myver" - echo 'Copyright (C) 2011 Eric Bélanger <snowmaniscool@gmail.com>' -} - -if [ -n "$1" ]; then - case "$1" in - -o) PACMAN_OPTS="${2}" ;; - -h|--help) usage; exit 0 ;; - -V|--version) version; exit 0 ;; - *) usage; exit 1 ;; - esac -fi - -IFS=$'\n' -name="^Name.*: (.*)$" -size="^Installed Size.*: (.*) KiB$" - -[[ $PACMAN_OPTS && $PACMAN_OPTS != -* ]] && PACMAN_OPTS="-$PACMAN_OPTS" - -for line in $(LANG=C pacman -Qi $PACMAN_OPTS); do - if [[ $line =~ $name ]]; then - printf "%s\t" ${BASH_REMATCH[1]} - elif [[ $line =~ $size ]]; then - printf "%s\n" ${BASH_REMATCH[1]} - fi -done | sort -g -k2 | awk ' -BEGIN { - split("KiB MiB GiB TiB PiB EiB ZiB YiB", suffix) -} -function format_size(size) { - count = 1 - while (size + 0 > 1024) { - size /= 1024 - count++ - } - sizestr = sprintf("%.2f %s", size, suffix[count]) - return sizestr -} -{ - printf("%s\t%s\n", format_size($2), $1); -}' - -# vim: set noet: -- 1.9.0
On 03/05/14 at 04:00pm, Pierre Neidhardt wrote:
Printing package size is useful for maintenance. Indeed, the first entry on the wiki is focused on this topic:
https://wiki.archlinux.org/index.php/Pacman_Tips#Maintenance
None of the proposed solutions will allow you to: - select packages; - work on the output of other commands yielding a list of packages; - change the sorting; - be locale independent; - print a grand total; - be fast (most solutions are wasting a lot of time -- only expac is faster); - not rely on any third-party tool.
Pacsize is a POSIX shell script that is generic enough to enclose all these features (and more).
Adding a 'pacsize' script eliminates the unneeded abundance of workarounds for this simple matter.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/.gitignore | 1 + contrib/Makefile.am | 3 + contrib/README | 4 ++ contrib/pacsize.sh.in | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 contrib/pacsize.sh.in
Your pacman parser doesn't understand size units: $ ./pacsize linux 67 KiB linux $ pacman -Qi linux | grep Installed [0][1078] Installed Size : 67.12 MiB
On 14-03-05 10:38:36, Andrew Gregory wrote:
On 03/05/14 at 04:00pm, Pierre Neidhardt wrote:
Printing package size is useful for maintenance. Indeed, the first entry on the wiki is focused on this topic:
https://wiki.archlinux.org/index.php/Pacman_Tips#Maintenance
None of the proposed solutions will allow you to: - select packages; - work on the output of other commands yielding a list of packages; - change the sorting; - be locale independent; - print a grand total; - be fast (most solutions are wasting a lot of time -- only expac is faster); - not rely on any third-party tool.
Pacsize is a POSIX shell script that is generic enough to enclose all these features (and more).
Adding a 'pacsize' script eliminates the unneeded abundance of workarounds for this simple matter.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/.gitignore | 1 + contrib/Makefile.am | 3 + contrib/README | 4 ++ contrib/pacsize.sh.in | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 contrib/pacsize.sh.in
Your pacman parser doesn't understand size units: $ ./pacsize linux 67 KiB linux $ pacman -Qi linux | grep Installed [0][1078] Installed Size : 67.12 MiB
This is actually something I've been wondering for a while: how do you change the size unit? -- Pierre Neidhardt "Remember, extremism in the nondefense of moderation is not a virtue." -- Peter Neumann, about usenet
On 05.03.2014 17:22, Pierre Neidhardt wrote:
$ pacman -Qi linux | grep Installed [0][1078] Installed Size : 67.12 MiB
This is actually something I've been wondering for a while: how do you change the size unit?
They are hard coded for a few places, automatic in others. Automatic units work in a way that the resulting number is <=2048 or something.
On 14-03-05 17:23:27, Florian Pritz wrote:
On 05.03.2014 17:22, Pierre Neidhardt wrote:
$ pacman -Qi linux | grep Installed [0][1078] Installed Size : 67.12 MiB
This is actually something I've been wondering for a while: how do you change the size unit?
They are hard coded for a few places, automatic in others. Automatic units work in a way that the resulting number is <=2048 or something.
Ugh, I do not get it. By me: $ pacman -Qi linux | grep Installed Installed Size : 68733.00 KiB -- Pierre Neidhardt Linux: the choice of a GNU generation -- ksh@cis.ufl.edu put this on Tshirts in '93
On Wed, Mar 05, 2014 at 05:43:10PM +0100, Pierre Neidhardt wrote:
On 14-03-05 17:23:27, Florian Pritz wrote:
On 05.03.2014 17:22, Pierre Neidhardt wrote:
$ pacman -Qi linux | grep Installed [0][1078] Installed Size : 67.12 MiB
This is actually something I've been wondering for a while: how do you change the size unit?
They are hard coded for a few places, automatic in others. Automatic units work in a way that the resulting number is <=2048 or something.
Ugh, I do not get it. By me:
$ pacman -Qi linux | grep Installed Installed Size : 68733.00 KiB
Then you're not running from -git. We changed this back in October in 6405ecb2599.
On 14-03-05 11:51:29, Dave Reisner wrote:
On Wed, Mar 05, 2014 at 05:43:10PM +0100, Pierre Neidhardt wrote:
On 14-03-05 17:23:27, Florian Pritz wrote:
On 05.03.2014 17:22, Pierre Neidhardt wrote:
$ pacman -Qi linux | grep Installed [0][1078] Installed Size : 67.12 MiB
This is actually something I've been wondering for a while: how do you change the size unit?
They are hard coded for a few places, automatic in others. Automatic units work in a way that the resulting number is <=2048 or something.
Ugh, I do not get it. By me:
$ pacman -Qi linux | grep Installed Installed Size : 68733.00 KiB
Then you're not running from -git. We changed this back in October in 6405ecb2599.
Oopsy! Anyway, some scripts (pacsysclean at least) had support for various size units long before that. I wonder why. -- Pierre Neidhardt Never drink from your finger bowl -- it contains only water.
On 14-03-05 18:30:41, Pierre Neidhardt wrote:
On 14-03-05 11:51:29, Dave Reisner wrote:
On Wed, Mar 05, 2014 at 05:43:10PM +0100, Pierre Neidhardt wrote:
On 14-03-05 17:23:27, Florian Pritz wrote:
On 05.03.2014 17:22, Pierre Neidhardt wrote:
$ pacman -Qi linux | grep Installed [0][1078] Installed Size : 67.12 MiB
This is actually something I've been wondering for a while: how do you change the size unit?
They are hard coded for a few places, automatic in others. Automatic units work in a way that the resulting number is <=2048 or something.
Ugh, I do not get it. By me:
$ pacman -Qi linux | grep Installed Installed Size : 68733.00 KiB
Then you're not running from -git. We changed this back in October in 6405ecb2599.
Oopsy! Anyway, some scripts (pacsysclean at least) had support for various size units long before that. I wonder why.
My bad, pacsysclean actually implemented size unit on its side. -- Pierre Neidhardt If you drink, don't park. Accidents make people.
On Wed, Mar 05, 2014 at 04:00:16PM +0100, Pierre Neidhardt wrote:
Printing package size is useful for maintenance. Indeed, the first entry on the wiki is focused on this topic:
https://wiki.archlinux.org/index.php/Pacman_Tips#Maintenance
None of the proposed solutions will allow you to: - select packages; - work on the output of other commands yielding a list of packages; - change the sorting; - be locale independent; - print a grand total; - be fast (most solutions are wasting a lot of time -- only expac is faster); - not rely on any third-party tool.
Pacsize is a POSIX shell script that is generic enough to enclose all these features (and more).
I truly do not understand why you've chosen to write this in POSIX shell when every other shell script in the pacman repo is written in bash. A lot of the constructs in your script are made considerably uglier and more fragile than needed because of this decision.
Adding a 'pacsize' script eliminates the unneeded abundance of workarounds for this simple matter.
Ok, I'll bite. Why aren't we working on merging expac (or something like expac)? Adding yet another tool tool which relies on parsing unstable output from pacman seems like a step in the wrong direction.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/.gitignore | 1 + contrib/Makefile.am | 3 + contrib/README | 4 ++ contrib/pacsize.sh.in | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 contrib/pacsize.sh.in
diff --git a/contrib/.gitignore b/contrib/.gitignore index a181813..9cecd5e 100644 --- a/contrib/.gitignore +++ b/contrib/.gitignore @@ -7,6 +7,7 @@ paclist paclog-pkglist pacscripts pacsearch +pacsize pacsysclean rankmirrors updpkgsums diff --git a/contrib/Makefile.am b/contrib/Makefile.am index f6ca3f1..8c5c6da 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -12,6 +12,7 @@ BASHSCRIPTS = \ paclist \ paclog-pkglist \ pacscripts \ + pacsize \ pacsysclean \ rankmirrors \ updpkgsums @@ -38,6 +39,7 @@ EXTRA_DIST = \ paclist.sh.in \ pacscripts.sh.in \ pacsearch.in \ + pacsize.sh.in \ pacsysclean.sh.in \ rankmirrors.sh.in \ updpkgsums.sh.in \ @@ -102,6 +104,7 @@ paclist: $(srcdir)/paclist.sh.in paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in pacscripts: $(srcdir)/pacscripts.sh.in pacsearch: $(srcdir)/pacsearch.in +pacsize: $(srcdir)/pacsize.sh.in pacsysclean: $(srcdir)/pacsysclean.sh.in rankmirrors: $(srcdir)/rankmirrors.sh.in updpkgsums: $(srcdir)/updpkgsums.sh.in diff --git a/contrib/README b/contrib/README index ae33bb2..4f5c17f 100644 --- a/contrib/README +++ b/contrib/README @@ -31,6 +31,10 @@ pacsearch - a colorized search combining both -Ss and -Qs output. Installed packages are easily identified with a *** and local-only packages are also listed.
+pacsize - display the size of packages. Duplicates are removed if any. The local +database is queried first; if the package is not found, the sync database is +then used for lookup. + pacsysclean - lists installed packages sorted by size.
rankmirrors - ranks pacman mirrors by their connection and opening speed. diff --git a/contrib/pacsize.sh.in b/contrib/pacsize.sh.in new file mode 100644 index 0000000..4d84734 --- /dev/null +++ b/contrib/pacsize.sh.in @@ -0,0 +1,159 @@ +#!/bin/sh +# pacsize -- display package sizes +# +# Copyright (C) 2014 Pierre Neidhardt <ambrevar@gmail.com> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +readonly myname='pacsize' +readonly myver='@PACKAGE_VERSION@' + +calc_total () { + awk '{ + total += $1 + print +} +END { + printf ("%7s KIB TOTAL\n", total) +}' +} + +error () { + echo "$@" >&2 +} + +## Print size and name. We strip the arguably useless decimals. This makes +## output lighter. +filter () { + awk -F ": " \ + '$0 ~ "Name" { + pkg = $2 +} +$0 ~ "Installed Size" { + gsub (/[\.,].*/, "") + printf ("%7s KiB %s\n", $2, pkg) +}' +} + +remove_duplicates () { + awk '! table[$0]++' +} + +usage () { + cat <<EOF +Usage: ${1##*/} [OPTIONS] PACKAGES + ${1##*/} -a [OPTIONS] + +Display the size of PACKAGES. Duplicates are removed if any. The local database +is queried first; if the package is not found, the sync database is then used +for lookup. + +Options: + + -a: Process all installed packages. + -h: Show this help. + -n: Sort output by name. + -s: Sort output by size. + -t: Print total. + +Examples: + + $ ${1##*/} -ast + Convenient way to keep track of big packages. + + $ ${1##*/} \$(pactree -ld1 linux) + Print the size of linux and all its direct dependencies. + + $ ${1##*/} -st \$(pacman -Qdtq) + Print a grand total of orphan packages, and sort by size. +EOF +} + +version () { + echo "$myname $myver" + echo 'Copyright (C) 2014 Pierre Neidhardt <ambrevar@gmail.com>' +} + +opt_sort=false +opt_all=false +opt_total=false + +while getopts ":ahnstv" opt; do + case $opt in + a) + opt_all=true ;; + h) + usage "$0" + exit ;; + n) + opt_sort="sort -uk3" ;; + s) + opt_sort="sort -un" ;; + t) + opt_total="calc_total" ;; + v) + version "$0" + exit ;; + ?) + usage "$0" + exit 1 ;; + esac +done + +shift $(($OPTIND - 1)) + +## All-packages mode. +## We use a dedicated algorithm which is much faster than per-package mode. +## Unfortunately there is no easy way to select packages with this method. +if $opt_all; then + DBPath="$(awk -F = '/^ *DBPath/{print $2}' @sysconfdir@/pacman.conf 2>/dev/null)" + [ ! -d "$DBPath" ] && DBPath="@localstatedir@/lib/pacman" + + if [ ! -d "$DBPath/local/" ]; then + error "Could not find local database in $DBPath/local/." + exit 1 + fi + + awk '/^%NAME%/ { + getline + pkg=$0 +} +/^%SIZE%/ { + getline + size = $0 / 1024 + printf ("%6s KiB %s\n", size, pkg) +}' "$DBPath"/local/*/desc | ($opt_sort || cat) | ($opt_total || cat) + exit +fi + +## Per-package mode. +if [ $# -eq 0 ]; then + error "Missing argument." + usage "$0" + exit 1 +fi + +if ! command -v pacman >/dev/null 2>&1; then + error "'pacman' not found." + exit 1 +fi + +{ + ## If package is not found locally (-Q), we use the sync database (-S). We + ## use LC_ALL=C to make sure pacman output is not localized. + buffer=$(LC_ALL=C pacman -Qi "$@" 2>&1 1>&3 3>&- | cut -f2 -d "'") + [ -n "$buffer" ] && LC_ALL=C pacman -Si $buffer +} 3>&1 | filter | ($opt_sort || remove_duplicates) | ($opt_total || cat) + +# vim: set noet: -- 1.9.0
On 14-03-05 10:50:30, Dave Reisner wrote:
On Wed, Mar 05, 2014 at 04:00:16PM +0100, Pierre Neidhardt wrote:
Printing package size is useful for maintenance. Indeed, the first entry on the wiki is focused on this topic:
https://wiki.archlinux.org/index.php/Pacman_Tips#Maintenance
None of the proposed solutions will allow you to: - select packages; - work on the output of other commands yielding a list of packages; - change the sorting; - be locale independent; - print a grand total; - be fast (most solutions are wasting a lot of time -- only expac is faster); - not rely on any third-party tool.
Pacsize is a POSIX shell script that is generic enough to enclose all these features (and more).
I truly do not understand why you've chosen to write this in POSIX shell when every other shell script in the pacman repo is written in bash.
Well, since some scripts are written in perl, I guess we are free to chose the language as long as it does not add other dependencies. The true reason I chose POSIX shell over bash is that I do not endorse bash. So what I cannot do in POSIX shell (mainly when recursive file processing and structures are involved), then I call Perl. In short: * POSIX shell is more portable, obviously (even though it is not required here). * The language is simpler. * Faster. * The code is often equivalent, both in size and expressivity (not considering the structures here). So why do sth unportable if you can do it the standard way without losing anything? * Ugly is arguable, but I wouldn't say bash is beautiful either. But I do not want to start a flame war, so I will stop here. Here POSIX shell shows no limitation for the task. I do not think the code could not be shorter in bash.
A lot of the constructs in your script are made considerably uglier and more fragile than needed because of this decision.
I may have written some fragile code somewhere. Thinking about something in particular?
Adding a 'pacsize' script eliminates the unneeded abundance of workarounds for this simple matter.
Ok, I'll bite. Why aren't we working on merging expac (or something like expac)? Adding yet another tool tool which relies on parsing unstable output from pacman seems like a step in the wrong direction.
Yes! I totally agree. This will render this script obsolete (as well as pacsysclean and maybe other). -- Pierre Neidhardt Trap full -- please empty.
On 14-03-05 10:50:30, Dave Reisner wrote:
Ok, I'll bite. Why aren't we working on merging expac (or something like expac)? Adding yet another tool tool which relies on parsing unstable output from pacman seems like a step in the wrong direction.
I know it's not the place to report this, but talking about it, expac is under MIT license, while the package in the repo is marked as GPL. Anyhow, what is pacman's policy on merging third-party software with non-GPL license? -- Pierre Neidhardt The Kennedy Constant: Don't get mad -- get even.
On Wed, Mar 05, 2014 at 06:38:57PM +0100, Pierre Neidhardt wrote:
On 14-03-05 10:50:30, Dave Reisner wrote:
Ok, I'll bite. Why aren't we working on merging expac (or something like expac)? Adding yet another tool tool which relies on parsing unstable output from pacman seems like a step in the wrong direction.
I know it's not the place to report this, but talking about it, expac is under MIT license, while the package in the repo is marked as GPL. Anyhow, what is pacman's policy on merging third-party software with non-GPL license?
Poof. As the sole author, I allow it to be licensed under $insert_any_license_compatible_with_gpl. MIT is totally compatible with GPL, btw....
On 14-03-05 12:41:48, Dave Reisner wrote:
On Wed, Mar 05, 2014 at 06:38:57PM +0100, Pierre Neidhardt wrote:
On 14-03-05 10:50:30, Dave Reisner wrote:
Ok, I'll bite. Why aren't we working on merging expac (or something like expac)? Adding yet another tool tool which relies on parsing unstable output from pacman seems like a step in the wrong direction.
I know it's not the place to report this, but talking about it, expac is under MIT license, while the package in the repo is marked as GPL. Anyhow, what is pacman's policy on merging third-party software with non-GPL license?
Poof. As the sole author, I allow it to be licensed under $insert_any_license_compatible_with_gpl.
MIT is totally compatible with GPL, btw....
We still need to replace pacsysclean (which does not work at all with the size units). I've fixed pacsize, which can replace pacsysclean until expac would not be merged, or if expac does not get merged at all. I've been playing around with expac: with a few changes it could easily superseeds paclist, pacsysclean/pacsize, pacsearch, and the zillion of user scripts out there. A big +1 for expac integration. -- Pierre Neidhardt Ideas don't stay in some minds very long because they don't like solitary confinement.
On 06/03/14 01:50, Dave Reisner wrote:
On Wed, Mar 05, 2014 at 04:00:16PM +0100, Pierre Neidhardt wrote:
Printing package size is useful for maintenance. Indeed, the first entry on the wiki is focused on this topic:
https://wiki.archlinux.org/index.php/Pacman_Tips#Maintenance
None of the proposed solutions will allow you to: - select packages; - work on the output of other commands yielding a list of packages; - change the sorting; - be locale independent; - print a grand total; - be fast (most solutions are wasting a lot of time -- only expac is faster); - not rely on any third-party tool.
Pacsize is a POSIX shell script that is generic enough to enclose all these features (and more). I truly do not understand why you've chosen to write this in POSIX shell when every other shell script in the pacman repo is written in bash. A lot of the constructs in your script are made considerably uglier and more fragile than needed because of this decision.
If you can convince the author to provide a patch(set) to add expac into src/util, I'd be more than happy to accept it. Allan
On Thu, Mar 06, 2014 at 10:43:34AM +1000, Allan McRae wrote:
On 06/03/14 01:50, Dave Reisner wrote:
On Wed, Mar 05, 2014 at 04:00:16PM +0100, Pierre Neidhardt wrote:
Printing package size is useful for maintenance. Indeed, the first entry on the wiki is focused on this topic:
https://wiki.archlinux.org/index.php/Pacman_Tips#Maintenance
None of the proposed solutions will allow you to: - select packages; - work on the output of other commands yielding a list of packages; - change the sorting; - be locale independent; - print a grand total; - be fast (most solutions are wasting a lot of time -- only expac is faster); - not rely on any third-party tool.
Pacsize is a POSIX shell script that is generic enough to enclose all these features (and more). I truly do not understand why you've chosen to write this in POSIX shell when every other shell script in the pacman repo is written in bash. A lot of the constructs in your script are made considerably uglier and more fragile than needed because of this decision.
If you can convince the author to provide a patch(set) to add expac into src/util, I'd be more than happy to accept it.
Allan
I'll find out if he's willing to do this.
participants (5)
-
Allan McRae
-
Andrew Gregory
-
Dave Reisner
-
Florian Pritz
-
Pierre Neidhardt