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_DVD' in os.environ:
31 # List of packages for disc1.
33 pkgs = ['misc/freebsd-doc-bn',
34 'misc/freebsd-doc-da',
35 'misc/freebsd-doc-de',
36 'misc/freebsd-doc-el',
37 'misc/freebsd-doc-en',
38 'misc/freebsd-doc-es',
39 'misc/freebsd-doc-fr',
40 'misc/freebsd-doc-hu',
41 'misc/freebsd-doc-it',
42 'misc/freebsd-doc-ja',
43 'misc/freebsd-doc-mn',
44 'misc/freebsd-doc-nl',
45 'misc/freebsd-doc-pl',
46 'misc/freebsd-doc-pt',
47 'misc/freebsd-doc-ru',
48 'misc/freebsd-doc-sr',
49 'misc/freebsd-doc-tr',
50 'misc/freebsd-doc-zh_cn',
51 'misc/freebsd-doc-zh_tw']
54 pkgs.extend(['archivers/unzip',
55 'emulators/linux_base-f10',
59 'ports-mgmt/p5-FreeBSD-Portindex',
60 'ports-mgmt/portaudit',
61 'ports-mgmt/portmaster',
62 'ports-mgmt/portupgrade',
72 # The list of desired packages
73 def desired_packages():
74 disc1 = disc1_packages()
77 # Suck the entire INDEX file into a two different dictionaries. The first
78 # dictionary maps port names (origins) to package names. The second
79 # dictionary maps a package name to a list of its dependent packages.
84 def load_index(index):
89 fields = line.split('|')
90 name = fields[PACKAGE_COL]
92 sys.stderr.write('%d: Duplicate package %s\n' % (line_num, name))
94 origin = fields[ORIGIN_COL].replace('/usr/ports/', '', 1)
96 sys.stderr.write('%d: Duplicate port %s\n' % (line_num, origin))
98 deps[name] = fields[DEPENDS_COL].split()
100 line_num = line_num + 1
103 # Layout the packages on the various CD images. Here's how it works. We walk
104 # each disc in the list of discs. Within each disc we walk the list of ports.
105 # For each port, we add the package name to a dictionary with the value being
106 # the current disc number. We also add all of the dependent packages. If
107 # a package is already in the dictionary when we go to add it, we just leave
108 # the dictionary as it is. This means that each package ends up on the first
109 # disc that either lists it or contains it as a dependency.
110 def layout_discs(discs, pkgs, deps):
116 sys.stderr.write('Disc %d: Unable to find package for %s\n' %
120 pkg_list = [pkg] + deps[pkg]
122 if pkg not in layout:
124 print "--> Adding %s to Disc %d" % (pkg, disc_num)
125 layout[pkg] = disc_num
126 disc_num = disc_num + 1
129 # Generate a master INDEX file based on the generated layout. The way this
130 # works is that for each INDEX line, we check to see if the package is in the
131 # layout. If it is, we put that INDEX line into the master INDEX and append
132 # a new field with the disc number to the line.
133 def generate_index(index, layout, master_index):
135 pkg = line.split('|')[PACKAGE_COL]
137 new_line = '%s|%d\n' % (line.splitlines()[0], layout[pkg])
138 master_index.write(new_line)
140 # Verify the command line arguments
141 if len(sys.argv) != 3:
142 sys.stderr.write('Invalid number of arguments\n')
143 sys.stderr.write('Usage: package-split.py <source INDEX> <master INDEX>\n')
146 print "Loading %s..." % (sys.argv[1])
147 index = file(sys.argv[1])
148 (deps, pkgs) = load_index(index)
149 discs = desired_packages()
150 layout = layout_discs(discs, pkgs, deps)
152 print "Generating %s..." % (sys.argv[2])
153 master_index = file(sys.argv[2], 'w')
154 generate_index(index, layout, master_index)