A deeper explanation of the script can be found here.
"""Scans a directory under /usr/ports/ and gives the portname and comment for each port found.""" 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()