apt-plus/command/list

53 lines
1.2 KiB
Python

#!/usr/bin/env python
import re;
from os import system as ossystem;
from os import path as ospath;
import sys;
from parser import Manifest, Package;
# [1] get absolute path
path = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
# [2] get group option (if set)
OPTGROUP = None;
if( len(sys.argv) > 2 and ( sys.argv[1] == "-g" or sys.argv[1] == "--group" ) ):
OPTGROUP = sys.argv[2];
# [3] search for manifest file
man = Manifest.Manifest();
# [4] If group selected
if( OPTGROUP != None ):
if( not man.hasGroup(OPTGROUP) ):
print "Unknown group";
exit(1);
print "[%s]" % OPTGROUP;
for pkg_name in man._pkg[OPTGROUP]:
pkg = man._pkg[OPTGROUP][pkg_name];
if( pkg.isInstalled() ):
print "\033[38;5;78m",;
elif( pkg.isRemoved() ):
print "\033[38;5;208m",;
elif( pkg.isPurged() ):
print "\033[38;5;161m",;
print "%s\033[0m" % pkg.serialize();
# [4] List all
else:
for group in man._pkg:
print "[%s]" % group;
for pkg_name in man._pkg[group]:
pkg = man._pkg[group][pkg_name];
if( pkg.isInstalled() ):
print "\033[38;5;78m",;
elif( pkg.isRemoved() ):
print "\033[38;5;208m",;
elif( pkg.isPurged() ):
print "\033[38;5;161m",;
print "%s\033[0m" % pkg.serialize();