Scan The FreeBSD Ports Collection And Print One-line Summary For Each Port
Join the DZone community and get the full member experience.Join For Free
The FreeBSD ports collection is a skelton of installable software on a local FreeBSD machine. This small utility lets you scan the collection by category, to find out what software is available in that category. Call the script portinfo.py. 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') # 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 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()
Opinions expressed by DZone contributors are their own.