#!/usr/bin/env python """Scans a directory under /usr/ports and gives the portname and comment for each port found. """ __RCS__ = '$Id: portinfo.py,v 1.2 2003/04/30 16:58:12 darren Exp darren $' __version__ = '$Revision: 1.2 $' __initialdate__ = 'April 2003' __author__ = 'Darren Paul Griffith, http://www.madphilosopher.ca/' import os import os.path import sys def findmakefiles(curdir): '''goes one level deep under curdir to find and act on the Makefiles.''' for name in os.listdir(curdir): pathname = os.path.join(curdir, name, 'Makefile') # COMMENTs are found in the Makefiles if os.path.isfile(pathname): processmakefile(name, pathname) def processmakefile(name, pathname): '''grabs the port's COMMENT from the Makefile.''' f = open(pathname) data = f.readlines() for line in data: if line[0:7] == 'COMMENT': try: comment = line.strip().split('\t')[1] # most COMMENTs are tab delimited except: comment = line.strip() # some are not, so just print the whole line print "%-15s %s" % (name, comment) f.close() def usage(): print 'Usage: portinfo.py /usr/ports/[category]' sys.exit(1) if __name__ == '__main__': # get directory from command line args = sys.argv[1:] if len(args) == 1: curdir = args[0] else: usage() ## curdir = '/usr/ports/security/' # scan this directory if os.path.isdir(curdir): findmakefiles(curdir) else: sys.stdout = sys.stderr print "'%s' is not a valid directory." % curdir usage()