freebsd-ports/Tools/portbuild/scripts/chopindex
Kris Kennaway 9100b4ee0d Rewrite this in python instead of shell. Because we can read the
INDEX once and process internally instead of invoking many external
utilities, runtime is improved from ~20 minutes to <10 seconds.
2008-05-25 18:07:49 +00:00

55 lines
1.8 KiB
Python
Executable file

#!/usr/bin/env python
import os, sys
if len(sys.argv) != 3:
print "%s: <index> <pkgdir>" % sys.argv[0]
sys.exit()
indexfile = sys.argv[1]
pkgdir = sys.argv[2]
if not pkgdir.endswith("/All"):
pkgdir = pkgdir + "/All"
packages = [pkg for (pkg, ext) in map(os.path.splitext, os.listdir(pkgdir)) if ext == ".tbz"]
index=[]
pkgs=[]
for i in file(indexfile):
out = i.rstrip().split("|")
out[7] = out[7].split(" ") # build dep
out[8] = out[8].split(" ") # run dep
index.append(out)
# Keep track of all the packages we have seen in the index. In
# principle there is no need to track the build/run deps since
# they will also be listed in field 0. We could add a sanity
# check for this.
pkgs.append(out[0])
pkgs.extend(out[7])
pkgs.extend(out[8])
used=set(pkgs)
notfound=used.difference(set(packages))
# Write out the new index, stripping out the entries for missing
# packages as well as dependencies from existing packages on the
# missing ones.
#
# This is slightly dubious since it will intentionally list packages
# that are present but missing dependencies on non-redistributable
# things like jdk that were successfully built but removed already, so
# the dependency lists will not be complete. It matches the old
# chopindex.sh behaviour though.
#
# I think it would be better to just prune those incomplete packages
# from the INDEX altogether, but I don't know if anyone is relying on
# this historical behaviour.
for data in index:
if data[0] not in notfound:
print "%s|%s|%s|%s" % ("|".join(data[:7]),
" ".join([j for j in data[7] if j not in notfound]),
" ".join([j for j in data[8] if j not in notfound]),
"|".join(data[9:]))