You are not logged in.

#1 2008-12-16 03:18:12

sabooky
Member
Registered: 2006-11-02
Posts: 89

pacstat: pacman group status

This script addresses the annoyance of pacman lack of of upgrading groups, only individual packages.

Basically this issue (http://bugs.archlinux.org/task/8242):

When doing pacman -Syu it only checks for packages that need to be upgraded, but doesn't install new ones that are part of a previously installed group.
For exmaple:
pacman -S gnome-extra
*few weeks later*
gnome-extra adds 2-3 new packages
pacman -Syu doesn't catch this and install the 2-3 new packages.

Since there's no easy way to approach this without user input. I decided to put together a small script to give me the status of each group.

The script is very straight forward

Usage:
Do a pacman -Sy in order to have the latest pkg information.

$ ./pacstat.py
base                                      98/98  %100.00
gnome-extra                               41/41  %100.00
gnome                                     20/20  %100.00
base-devel                                14/14  %100.00
compiz-fusion-git                         12/12  %100.00
xorg                                      10/10  %100.00
gstreamer0.10-plugins                      6/6   %100.00
compiz-fusion-plugins-makebelieve-git      2/2   %100.00
compiz-fusion-kde-git                     10/12  %83.33
xfce4                                      3/21  %14.29
xorg-input-drivers                         3/28  %10.71
xorg-video-drivers                         2/33  %6.06
kde                                        1/19  %5.26

Incomplete groups with over 50% installed:
compiz-fusion-kde-git

To update your system run:
pacman -S --needed compiz-fusion-kde-git

Threshold is set to 50% by default but can be overwritten by passing a number as the first argument.
For example in order to consider all groups with 12% or more packages installed:

$ ./pacstat.py 12
base                                      98/98  %100.00
..
kde                                        1/19  %5.26

Incomplete groups with over 12% installed:
xfce4 compiz-fusion-kde-git

To update your system run:
pacman -S --needed xfce4 compiz-fusion-kde-git

(cropped for space)

The script:

'''
Description: A simple script that informs the user of pacman groups that are
partially installed or upgraded.
Author: sabooky (archlinux forums)
'''
import os
import sys


#===============================================================================
# Functions
#===============================================================================
# function to compare installed groups
def group_comp(a, b):
    '''Compares pacman groups by percent, total group count'''
    a_status = a[1]
    b_status = b[1]
    return cmp((a_status['percent'], a_status['total_cnt']),
               (b_status['percent'], b_status['total_cnt']))


#===============================================================================
# Main script
#===============================================================================
# initial variables and user input
thresh = 50
if len(sys.argv) == 2:
    thresh = int(sys.argv[1])

# get a list of all installed packages
installed_pkgs = set(x.strip() for x in os.popen('pacman -Qq'))

group_status = {}
# organise pacman groups installed/not installed
for line in os.popen('pacman -Sgg'):
    group, pkg = line.split()
    group_status.setdefault(group, {'installed': set(), 'not_installed': set()})
    if pkg in installed_pkgs:
        group_status[group]['installed'].add(pkg)
    else:
        group_status[group]['not_installed'].add(pkg)

# add additional information to each groups dictionary
for group, status in group_status.iteritems():
    status['installed_cnt'] = len(status['installed'])
    status['not_installed_cnt'] = len(status['not_installed'])
    status['total_cnt'] = status['installed_cnt'] + status['not_installed_cnt']
    status['percent'] = (float(status['installed_cnt']) /
                        status['total_cnt']) * 100

# sort and output group information
for group, status in sorted(group_status.iteritems(),
                            cmp=group_comp, reverse=True):
    # skip groups that have no packages intalled
    if not status['percent']:
        continue
    layout = "{group:<40} {installed_cnt:3}/{total_cnt:<3} %{percent:.02f}"
    print layout.format(group=group, **status)


# summary line explaining how to fill in the missing groups
incomplete_groups = ' '.join(group for group, status in group_status.iteritems()
                     if thresh <= status['percent'] < 100)

if incomplete_groups:
    summary_layout = "\nIncomplete groups with over {thresh}% installed:\n" \
                     "{0}\n\nTo update your system run:\npacman -S --needed {0}"
else:
    summary_layout = "\nThere are no groups with over {thresh}% installed"


print summary_layout.format(incomplete_groups, thresh=thresh)

Python 2.6 is required (I wanted to play with the new str.format functions).
There's information that I keep in the script thats not really used.. I did this to make it easy for me to add functionality to the script if I ever decide to do so.

PS: If this has been done already, let me know.. I didn't see anything but didn't really dig for this.

Offline

#2 2008-12-16 13:20:21

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: pacstat: pacman group status

This is actually a good idea.  If it's not implemented elsewhere maybe it's a candidate for pkgtools? Daenyth?


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

Board footer

Powered by FluxBB