1 #!/usr/local/bin/python
3 # This script generates a master INDEX file for the CD images built by the
4 # FreeBSD release engineers. Each disc is given a list of desired packages.
5 # Dependencies of these packages are placed on either the same disc or an
6 # earlier disc. The resulting master INDEX file is then written out.
8 # Usage: package-split.py <INDEX> <master INDEX>
16 arch = os.environ["PKG_ARCH"]
19 print "Using arch %s" % (arch)
21 if 'PKG_VERBOSE' in os.environ:
26 # List of packages for disc1. This just includes packages sysinstall can
27 # install as a distribution
30 pkgs = ['lang/perl5.8']
31 pkgs.extend(['x11/xorg',
35 pkgs.append('emulators/osf1_base')
37 pkgs.append('emulators/linux_base-8')
40 # List of packages for disc2. This includes packages that the X desktop
41 # menu depends on (if it still exists) and other "nice to have" packages.
42 # For architectures that use a separate livefs, this is actually disc3.
46 pkgs = ['x11/gnome2-lite',
51 pkgs.extend(['x11-wm/afterstep',
71 'net/cvsup-without-gui',
78 'print/ghostscript-gnu-nox11',
80 'print/psutils-letter',
84 'security/freebsd-update',
86 'sysutils/portupgrade',
91 'security/portaudit'])
94 # The list of desired packages
95 def desired_packages():
96 disc1 = disc1_packages()
97 disc2 = disc2_packages()
100 # Suck the entire INDEX file into a two different dictionaries. The first
101 # dictionary maps port names (origins) to package names. The second
102 # dictionary maps a package name to a list of its dependent packages.
107 def load_index(index):
112 fields = line.split('|')
113 name = fields[PACKAGE_COL]
115 sys.stderr.write('%d: Duplicate package %s\n' % (line_num, name))
117 origin = fields[ORIGIN_COL].replace('/usr/ports/', '', 1)
119 sys.stderr.write('%d: Duplicate port %s\n' % (line_num, origin))
121 deps[name] = fields[DEPENDS_COL].split()
123 line_num = line_num + 1
126 # Layout the packages on the various CD images. Here's how it works. We walk
127 # each disc in the list of discs. Within each disc we walk the list of ports.
128 # For each port, we add the package name to a dictionary with the value being
129 # the current disc number. We also add all of the dependent packages. If
130 # a package is already in the dictionary when we go to add it, we just leave
131 # the dictionary as it is. This means that each package ends up on the first
132 # disc that either lists it or contains it as a dependency.
133 def layout_discs(discs, pkgs, deps):
139 sys.stderr.write('Disc %d: Unable to find package for %s\n' %
143 pkg_list = [pkg] + deps[pkg]
145 if pkg not in layout:
147 print "--> Adding %s to Disc %d" % (pkg, disc_num)
148 layout[pkg] = disc_num
149 disc_num = disc_num + 1
152 # Generate a master INDEX file based on the generated layout. The way this
153 # works is that for each INDEX line, we check to see if the package is in the
154 # layout. If it is, we put that INDEX line into the master INDEX and append
155 # a new field with the disc number to the line.
156 def generate_index(index, layout, master_index):
158 pkg = line.split('|')[PACKAGE_COL]
160 new_line = '%s|%d\n' % (line.splitlines()[0], layout[pkg])
161 master_index.write(new_line)
163 # Verify the command line arguments
164 if len(sys.argv) != 3:
165 sys.stderr.write('Invalid number of arguments\n')
166 sys.stderr.write('Usage: package-split.py <source INDEX> <master INDEX>\n')
169 print "Loading %s..." % (sys.argv[1])
170 index = file(sys.argv[1])
171 (deps, pkgs) = load_index(index)
172 discs = desired_packages()
173 layout = layout_discs(discs, pkgs, deps)
175 print "Generating %s..." % (sys.argv[2])
176 master_index = file(sys.argv[2], 'w')
177 generate_index(index, layout, master_index)