#!/usr/bin/env python

# Copyright 2004 Daniel G. Taylor
# This code is released under the GNU GPL

"""List installed packages nicely"""

import output, sys

try: import portage
except ImportError:
    sys.exit("Portage module not found!!!")

# get all installed packages from portage
installed_packages = portage.db['/']['vartree'].getallnodes()
last_cat = ""
# for each package
for name in installed_packages:
    # split into category and package name
    category, package = name.split("/")
    if category != last_cat:
        # if the category has changed, print it green
        print output.green(category)
        last_cat = category
    # print it out
    print "\t" + package
