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 if 'PKG_MEMSTICK' in os.environ:
31 if 'PKG_DVD' in os.environ:
36 # List of packages. At this point only the English documentation fits
37 # on disc1. Add in the rest of the documentation for the memstick image.
38 # And add in enough packages to make a basic graphical workstation for the
41 pkgs = ['misc/freebsd-doc-en']
43 if doing_memstick or doing_dvd:
44 pkgs.extend(['misc/freebsd-doc-bn',
45 'misc/freebsd-doc-da',
46 'misc/freebsd-doc-de',
47 'misc/freebsd-doc-el',
48 'misc/freebsd-doc-es',
49 'misc/freebsd-doc-fr',
50 'misc/freebsd-doc-hu',
51 'misc/freebsd-doc-it',
52 'misc/freebsd-doc-ja',
53 'misc/freebsd-doc-mn',
54 'misc/freebsd-doc-nl',
55 'misc/freebsd-doc-pl',
56 'misc/freebsd-doc-pt',
57 'misc/freebsd-doc-ru',
58 'misc/freebsd-doc-sr',
59 'misc/freebsd-doc-tr',
60 'misc/freebsd-doc-zh_cn',
61 'misc/freebsd-doc-zh_tw'])
64 pkgs.extend(['archivers/unzip',
65 'emulators/linux_base-f10',
67 'misc/freebsd-doc-all',
70 'ports-mgmt/portaudit',
71 'ports-mgmt/portmaster',
78 'x11-drivers/xf86-video-vmware',
84 # The list of desired packages
85 def desired_packages():
86 disc1 = disc1_packages()
89 # Suck the entire INDEX file into a two different dictionaries. The first
90 # dictionary maps port names (origins) to package names. The second
91 # dictionary maps a package name to a list of its dependent packages.
96 def load_index(index):
101 fields = line.split('|')
102 name = fields[PACKAGE_COL]
104 sys.stderr.write('%d: Duplicate package %s\n' % (line_num, name))
106 origin = fields[ORIGIN_COL].replace('/usr/ports/', '', 1)
108 sys.stderr.write('%d: Duplicate port %s\n' % (line_num, origin))
110 deps[name] = fields[DEPENDS_COL].split()
112 line_num = line_num + 1
115 # Layout the packages on the various CD images. Here's how it works. We walk
116 # each disc in the list of discs. Within each disc we walk the list of ports.
117 # For each port, we add the package name to a dictionary with the value being
118 # the current disc number. We also add all of the dependent packages. If
119 # a package is already in the dictionary when we go to add it, we just leave
120 # the dictionary as it is. This means that each package ends up on the first
121 # disc that either lists it or contains it as a dependency.
122 def layout_discs(discs, pkgs, deps):
128 sys.stderr.write('Disc %d: Unable to find package for %s\n' %
132 pkg_list = [pkg] + deps[pkg]
134 if pkg not in layout:
136 print "--> Adding %s to Disc %d" % (pkg, disc_num)
137 layout[pkg] = disc_num
138 disc_num = disc_num + 1
141 # Generate a master INDEX file based on the generated layout. The way this
142 # works is that for each INDEX line, we check to see if the package is in the
143 # layout. If it is, we put that INDEX line into the master INDEX and append
144 # a new field with the disc number to the line.
145 def generate_index(index, layout, master_index):
147 pkg = line.split('|')[PACKAGE_COL]
149 new_line = '%s|%d\n' % (line.splitlines()[0], layout[pkg])
150 master_index.write(new_line)
152 # Verify the command line arguments
153 if len(sys.argv) != 3:
154 sys.stderr.write('Invalid number of arguments\n')
155 sys.stderr.write('Usage: package-split.py <source INDEX> <master INDEX>\n')
158 print "Loading %s..." % (sys.argv[1])
159 index = file(sys.argv[1])
160 (deps, pkgs) = load_index(index)
161 discs = desired_packages()
162 layout = layout_discs(discs, pkgs, deps)
164 print "Generating %s..." % (sys.argv[2])
165 master_index = file(sys.argv[2], 'w')
166 generate_index(index, layout, master_index)